Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

LF-4696: UI to display ensemble sensors list #3686

Merged
merged 61 commits into from
Feb 18, 2025

Conversation

SayakaOno
Copy link
Collaborator

@SayakaOno SayakaOno commented Feb 10, 2025

Description

  • Add MainContent component (usable in ExpandableItem)
    • simple variant story
    • decorated variant story
      • Implemented based on initial design. When expanded, a "remove" button appears. The removal action is intended to be handled within the component. (Note: the Styles appear off in Storybook due to the known issues)
  • Update WithStepperProgressBar
    • Add getValues() as an argument to onAfterSave
  • Add OverviewStats component (will be adjusted later if necessary)
  • Fix PageTitle prop type
  • Add EsciSensors component
  • Add SensorTable component
    • A new variant is expected to be added for the field technology tab later
  • Adjust Cell components for better reusability
  • Update TableHeader
    • Add missing className
    • Hide the invisible icon that takes up unnecessary space
      Screenshot 2025-02-07 at 11 12 08 AM
  • Add SensorList container
    • Implement URL parsing, hook call, and loading screen
  • Add useGroupedSensors hook
    • Implement API call and format data by converting depth values, adding fields, etc.
  • Update the sensor list URL to /sensors?partner_id={partnerId}

Jira link: https://lite-farm.atlassian.net/browse/LF-4696

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I the only one who gets stressed when finding the right icons? I've been renaming svgs, but I kept it this time since it would be easier if the name stays the same as in figma... (I always struggle with placing icons in the right folder too...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not the only one, the icons folder is a mess 😂 we'd probably need to take a look at what the icon library looks like in FIgma and then organize ours accordingly.

@SayakaOno SayakaOno marked this pull request as draft February 12, 2025 17:14
@SayakaOno SayakaOno marked this pull request as ready for review February 12, 2025 20:48
@SayakaOno
Copy link
Collaborator Author

NOTE: I plan to update "ESCI" to "ESci" in translations in another PR for reorganizing folders and files.

@SayakaOno SayakaOno added the new translations New translations to be sent to CrowdIn are present label Feb 12, 2025
Copy link
Collaborator

@kathyavini kathyavini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like how this code is organised and the components broken up ❤️ I particularly like the new components OverviewStats and MainContent and I hope we will push back harder on any future designs that create yet more patterns of expandable and/or KPI! It would be nice to instead see these again elsewhere in app.

(Note: the Styles appear off in Storybook due to the known issues)

That is this, right?

Screenshot 2025-02-14 at 11 13 31 AM Screenshot 2025-02-14 at 11 13 43 AM

I think I usually just over-specify the selectors in the SCSS (e.g. the yes/no buttons could be nested under their container) until it also works in Storybook -- is that a bad habit?

Edit:
One thing that is not at all blocking for this PR (it's really for Loïc, but I want to remind ourselves to check next week)...

Screenshot 2025-02-14 at 11 37 28 AM

This was the design based upon the two sensors Loïc saw on the Ensemble website. When he asked Morten if these were the only two possibilities, Morten said "no" and replied with the list of all sensor types. I don't think the designs got updated subsequently and we should circle back on this. I'm pretty sure all the possible sensor types should be allowable in KPI. The code is very extensible here (🙏 ) so the adjusts can definitely be made after merge.

@@ -1826,6 +1834,7 @@
"MONTHS_AGO": "{{time}} month(s) ago",
"NO_DATA": "(no data)",
"NO_DATA_FOUND": "No sensor readings found",
"PARTNER_SENSOR_LIST": "{{partner}} sensor list",
Copy link
Collaborator

@kathyavini kathyavini Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't know if this might be fundamentally the better solution (to interpolate 'Ensemble' and 'ESci' in English wherever they occur), but I think what we decided on Wednesday was that it should be part of the string so it can be transliterated into different scripts if desired by the translators.

At the same time I had forgotten that the loading screen also interpolates {{dataName}} so right now we're mixed. I think I would prefer to stick to either one or the other throughout 🤔 Maybe @antsgar has an opinion on that?

}

.inlineRemoveWarning,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious -- is it because I used grid in the other one that it's not possible to extract a shared visual component between this and AnimalFormHeaderItem? Or is it just more trouble than it's worth?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this a long time ago, so I don’t fully remember what I did…😅 But I think AnimalFormHeaderItem is more complex than what this reusable component can cover, so I likely treated them as separate things. Was there a specific part where you saw a difference?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no, not a difference but I just saw the chunk of code wrapped by the div with .inlineRemoveWarning was so close to duplicated I thought maybe you would have tried to extract it first and maybe that didn't work out? But it's not so much code that it matters.

Yes unfortunately AnimalFormHeaderItem is different enough again such that I don't think it could ever use MainContent 😜 So many expandables!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you were referring to inlineRemoveWarning specifically! (It's so obvious looking back 😂)
I think I just got lazy and didn’t create a new component, which makes no sense... 🙄
I'll clean that up in the next PR 🙏

Copy link
Collaborator Author

@SayakaOno SayakaOno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Joyce for reviewing and for checking unused ones as well 🙏

I think I addressed all comments and also pushed a missed commit for OverviewStats styles, along with a small improvement to MainContent (making errorCount optional).

I always want to nest CSS! It's more readable than comments... It fixed the styling in Storybook perfectly, thank you!

I spent too much time accommodating the unknowns in the KPI, so I'm hoping we'll just be adding more types without many adjustments 🤞 I'll check with Loïc next week!

}

.inlineRemoveWarning,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this a long time ago, so I don’t fully remember what I did…😅 But I think AnimalFormHeaderItem is more complex than what this reusable component can cover, so I likely treated them as separate things. Was there a specific part where you saw a difference?

kathyavini
kathyavini previously approved these changes Feb 15, 2025
Copy link
Collaborator

@kathyavini kathyavini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I love that with MainContent having its own set of stories 😍

Looks great!

antsgar
antsgar previously approved these changes Feb 18, 2025
Copy link
Collaborator

@antsgar antsgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much code here and yet really readable and easy to follow, great work @SayakaOno! Unfortunately I wasn't able to see it come to life because the Ensemble API is currently erroring out but the code looks great 👏

Comment on lines 52 to 62
const formatKpiLabel: OverviewStatsProps['format'] = (statsKey, label) => {
const Icon = statsKey === SENSOR_ARRAY ? SensorArrayIcon : SensorIcon;
return (
<div className={styles.kpiLabel}>
<span className={styles.iconWrapper}>
<Icon />
</span>
<span className={styles.text}>{label}</span>
</div>
);
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could be a component instead of a plain function, since it returns a React node?

Suggested change
const formatKpiLabel: OverviewStatsProps['format'] = (statsKey, label) => {
const Icon = statsKey === SENSOR_ARRAY ? SensorArrayIcon : SensorIcon;
return (
<div className={styles.kpiLabel}>
<span className={styles.iconWrapper}>
<Icon />
</span>
<span className={styles.text}>{label}</span>
</div>
);
};
const FormatKpiLabel: OverviewStatsProps['format'] = (statsKey, label) => {
const Icon = statsKey === SENSOR_ARRAY ? SensorArrayIcon : SensorIcon;
return (
<div className={styles.kpiLabel}>
<span className={styles.iconWrapper}>
<Icon />
</span>
<span className={styles.text}>{label}</span>
</div>
);
};

and then in the OverviewStats component

<span className={styles.category}>{FormattedLabelComponent ? <FormattedLabelComponent key={key} label={label} /> : label}</span>

format={formatKpiLabel}
isCompact={isCompact}
/>
<div className={styles.sensorGroups}>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ul instead of div since it's a list? We're probably defaulting to divs a bit too much in general and should try to use more semantic tags if possible

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, and this is definitely a list!
It wouldn't be a quick change since ExpandableItem would need the ability to render li and div conditionally, but we could create a ticket to update it!

type SensorsMapKeys = SensorArray['id'] | typeof STANDALONE;
type MappedSensors = { [key: SensorsMapKeys]: SensorInSimpleTableFormat[] };

const formatSenorArrayToGroup = (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const formatSenorArrayToGroup = (
const formatSensorArrayToGroup = (

summary: SensorSummary;
};

const EsciSensorList = ({ groupedSensors, summary }: EsciSensorListProps) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, do you think this component is specific to ESci and would not be applicable if we were to integrate another partner?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m hoping we can make this component reusable for another partner in the future with minimal changes. The title and sensor table header are currently ESci specific, making the component non-reusable, so I named it accordingly!

@SayakaOno SayakaOno dismissed stale reviews from antsgar and kathyavini via 3d143fa February 18, 2025 21:45
@SayakaOno
Copy link
Collaborator Author

Thank you @antsgar for reviewing and suggestions!

@kathyavini I think I've addressed Anto's comments, it would be appreciated if you could review the changes. Thank you!

Copy link
Collaborator

@kathyavini kathyavini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good! With integration merged did you also want to grab this TODO on this PR or separately? (It's just supplying the sensor list URL to the Partner and FarmAddon links)

Screenshot 2025-02-18 at 2 09 32 PM

@SayakaOno
Copy link
Collaborator Author

Oh, thank you for the reminder! I wouldn’t want to ask you for another re-review 😂, so I'll include it in my next PR!

@SayakaOno SayakaOno added this pull request to the merge queue Feb 18, 2025
Merged via the queue into integration with commit b43b4ae Feb 18, 2025
4 of 5 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request new translations New translations to be sent to CrowdIn are present
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants