What is Unit displays?
Please see the introduction in https://lite-farm.atlassian.net/l/cp/rCoihsHd.
The frontend has a component named “Unit” which handles unit displays(/packages/webapp/src/components/Form/Unit/index.jsx
).
How does the Unit component look on the app?
simple usage
system generated(pre-populated)
system generated(pre-populated)
disabled
“hide label”
automatic conversion
Guidance for Default unit displays with examples
How does farm’s unit setting(metric/imperial) affect this on read/edit view? If record-to-record unit(user preference) is “cm” but the user’s unit setting is imperial, should we follow the default display guidance? ( - LF-2880Getting issue details... STATUS )
is there a guidance for depth and spacing?
When the value is(was) pre-populated by the system | When a value is NOT pre-populated by the system or was user created | |
---|---|---|
create | the https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Default-display-guidance should determine the value / unit combination ex. | the user set unit preference should be used Does this mean “a user can create a value with a unit he/she likes”? From what I understand, there is no “user set unit preference” until the user creates a record… |
read-only | the https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Default-display-guidance should be used ex. | the user set unit preference should be used |
editing | the https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Default-display-guidance should be used ex. If the pre-populated value/unit is edited, do we consider it as a “user created” value? | the user set unit preference should be used |
automatic conversion - we will go with easier solution.
We do not need to see automatic conversion at all? (how about total area?)
Scenarios
User’s unit system setting is “imperial”. The user created a barn and total area was 50,000 acres. After that, he switched the unit system to “metric”.
-> The total area should be displayed in ha.User’s unit system setting is “imperial”. The user created a crop plan with planting depth 3 inches.
-> The depth should be stored in XXX.
“depth” is not in the https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Default-display-guidance
How is the conversion happening?
WIP
What is the problem and why are we working on this?
There have been some bugs found on Unit displays. However, there were times that a bug fix affected another Unit component that was functioning before. The unit component is used in many different places and requirements for each unit are vary. For instance, in some views, value and unit is generated based on the guidance, and in other views, they are inputted by the user. Sometimes the values need to be converted to another unit and sometimes they are not. It is thought that the component has a good amount of code of logic to handle all of these cases, which makes it hard to be maintained and scaled. As of February 10, 2023, the component is used in 59 different instances across 29 different files in the webapp. According to Jag Dhillon, in order to fix existing bugs and not to introduce new bugs, refactor is required.
How are we going to address this issue?
Jag Dhillon says “The unit component has multiple different useEffects that are causing most of this tight interdependency”, “the problem is the code is tightly coupled and minor changes to the code easily break some of the 56 component instances throughout the app.” in his proposal.
Approaches and estimates
- Any proposed architectural refactor must be implementable by 1 engineer in 3 sprints (6 weeks) or less
- Architecture supports the ability for the user to define how unit switching works for them (see https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#A-note-on-changing-units-when-a-value-has-already-been-entered)
Jag Dhillon’s proposal is to decouple the logic from the unit component, and he suggested we move the logic to the backend. The other approach is to fix and enhance the unit component. By looking into the code, it seems to me that bug fixes have been done without understanding how the unit component was intended to work. As of February 22, 2023, I have had the chance to look at how the value is converted on the frontend, and I liked the approach. I have not looked at how the data is converted from “save as” unit in the DB to “display” unit(I could not find anything working…), but I would like to move in the direction of fixing and improving what we have now. The main reason is to avoid changing many files and the time required for testing. (I will make sure it will be bug free and easy to maintain as well)
Here is the comparison between the two approaches:
proposed approach | alternative approach | |
---|---|---|
backfill data | find wrong data and write a script | |
database | no change required | |
APIs |
| no change required |
frontend |
|
|
auto conversion | DB: need migration | |
backend: update the helper(?) to take user setting into account | frontend: update the hook(?) to take user setting into account | |
pros |
|
|
cons |
|
|
TODO
ask for answers to all questions and make the requirements crystal clear → create a document(how each Unit input works, how the data is stored in the DB, min&max value(?) etc) that can also be used as a reference for testing
save data in an apples-to-apples manner
show data correctly on the frontend
write tests
figure out which data needs to be backfilled and how → write a script. - LF-2719Getting issue details... STATUS
we need to deploy APIs & app after backfilling is complete. Do we know how?