Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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”

Guidance for Default unit displays with examples

https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Default-display-guidance

(warning) 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-2880 - Getting issue details... STATUS )

(warning) 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

(warning) 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
(the user set unit preference = record-to-record unit)

editing

the https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Default-display-guidance should be used

ex.

(warning) If the pre-populated value/unit is edited, do we consider it as a “user created” value?
I am not sure if it is because of this guidance, but currently, even if I change the unit to “ft2”, “ac” is still shown.

the user set unit preference should be used

  • automatic conversion - we will go with easier solution.
    (warning)We do not need to see automatic conversion at all? (how about total area?)

Scenarios

  1. 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.

  2. 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

 List of <Unit /> (59 instances in 29 files)

(This is not 100 percent accurate)

Path
&
file (29)
(/packages/webapp/src/components)

Number of unique <Unit /> (59)

&

Views

Type
(pre-populated / user input)

Operation
(Create/Read/Edit)

automatic conversion

Note

1

crop/:cropId(?)add_management_plan/bed_method

file:
/Crop/BedPlan/PureBedForm.jsx

4

user input

create

NO

Currently, raw data(what the user has inputted is stored in the DB. After switching unit system, data conversion does not happen.

2

/tasks/:taskId?/read_only

file:
/Crop/BedPlan/PurePlanGuidanceForm.jsx

3

-

read

-

3

/crop/:cropId?/add_management_plan/broadcast_method

file:
/Crop/BroadcastPlan/PureBroadcastForm.jsx

3

  • area used & Estimated seed required: pre-populated

  • user input

create

NO

(warning) “estimated seed required is calculated by inputting “seeding rate”, but it does not take the unit into account.

(warning) The location size does not need a unit?

4

/crop/:cropId?/management_plan/:planId?/edit

file:
/Crop/ManagementDetail/EditManagementPlanDetail.jsx

1

user input

edit

NO

5

/crop/:cropId?/management_plan/:planId?/details

file:
/Crop/ManagementDetail/ManagementPlanDetail.jsx

1

-

read

-

6

/crop/:cropId?/add_management_plan/planted_already

file:
/Crop/PlantedAlready/index.jsx

2

user input

create

NO

7

/crop/:cropId?/add_management_plan/container_method

file:
/Crop/PlantInContainer/PureContainerForm.jsx

5 (4)

These should be combined ⬇️

user input

create

NO

8

/crop/:cropId?/add_management_plan/plant_date

condition:
already_in_ground && is_wild && !needs_transplant

file:
/Crop/PlantingDate/NextHarvest.jsx

1

user input

create

NO

9

/crop/:cropId?/add_management_plan/plant_date

condition:
!(already_in_ground && is_wild && !needs_transplant)

file:
/Crop/PlantingDate/PurePlantingDate.jsx

1

user input

create

NO

10

/crop/:cropId?/add_management_plan/final_planting_method

condition:

is_planting_method_known === false && showIsPlantingMethodKnown && isFinalPlantingMethod

file:
/Crop/PlantingMethod/PureManagementPlanPlantingMethod.jsx

1

user input

create

NO

11

/crop/:cropId?/add_management_plan/row_method

the component is used for #2

file:
/Crop/RowMethod/PureRowForm.jsx

5

user input

create

NO

Estimated seed 20lb was saved in the DB

12

/finances/estimated_revenue/plan/:planId

file:
/Finances/UpdateEstimatedCropRevenue/index.jsx

2

user input

create/edit?

NO

(warning) the first unit should be $/kg or $/mt? “Estimated annual revenue” does not change by changing units.

13

/add_sale

/edit_sale

file:
/Inputs/CropVarietySale/index.jsx

2

user input

create

edit

-

(warning) the style for the quantity input is different from others

<Unit /> does not need to be used for $…

14

/create_location/ceremonial_area etc.

file:
/LocationDetailLayout/AreaDetails/AreaDetails.jsx

2

pre-populated

create

NO

15

/create_location/buffer_zone

/buffer_zone/:bufferId?/details

file:
/LocationDetailLayout/LineDetails/BufferZone/index.jsx

2

pre-populated

create

read

edit

NO

16

/create_location/fence

file:
/LocationDetailLayout/LineDetails/Fence/index.jsx

1

pre-populated

create

NO

17

/create_location/watercourse

/watercourse/84cb7da8-abe9-11ed-8b70-e66db4bef551/details

file:
/LocationDetailLayout/LineDetails/Watercourse/index.jsx

4

pre-populated / user input

create

read

edit

NO

18

/sensor/:sensorId?/details

file:
/LocationDetailLayout/PointDetails/Sensor/index.jsx

1

-

read

-

(warning) 0.87cm???

After adding sensors with “150cm” and “200cm”, they were shown as “1.5m” and “2cm”.

19

/create_location/water_valve

file:
/LocationDetailLayout/PointDetails/WaterValve/index.jsx

1

user input

create

NO

20

/map
(location - watercourse)

file:
/Map/LineMapBoxes/index.jsx

2

pre-populated

create

-

21

/add_task/task_details

file:
/Modals/WaterUsageCalculatorModal/index.jsx

6

user input

create

YES

22

/sensor/:sensorId?/edit

file:
/Sensor/EditSensor.jsx

1

pre-populated (reading the data in DB)

edit

NO

22

/add_task/task_details

file:
/Task/AddProduct/index.jsx

1

user input

create

NO

23

/add_task/task_details

file:
/Task/CleaningTask/index.jsx

1

user input

create

NO

24

/add_task/task_details

file:
/Task/HarvestingTask/index.jsx

1

user input ↔︎ disabled by checking “harvest everything”

create

NO

25

/tasks/:taskId?/read_only

file:
/Task/HarvestingTask/ReadOnly.jsx

2

-

read

-

26

/add_task/task_details

file:
/Task/PureIrrigationTask/index.jsx

1

Screen Recording 2023-02-10 at 5.14.32 PM.mov

user input

create

YES

When I input “2 gal” in the estimated water usage input, “2 gal” was saved in the DB.

27

/tasks/:taskId?/harvest_uses

file:
/Task/TaskComplete/HarvestComplete/HarvestUses.jsx

1

user input

create

NO

(warning) when changing unit, “Amount to allocate” does not change.

28

/tasks/:taskId?/complete_harvest_quantity

file:
/Task/TaskComplete/HarvestComplete/Quantity.jsx

1

user input

create

NO

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.

 What is Tight coupling?

https://lite-farm.atlassian.net/wiki/spaces/LITEFARM/pages/658309153/Unit+displays#Tight-coupling

The problem of unit displays is an example of tight coupling. This means there is a high interconnectivity between the lines of code in the unit displays component. The unit displays component tries to achieve two things at once.

1: Displaying the units

2: Handling unit conversions

To reduce the tight coupling aka solve this problem is to separate these two tasks. The handling of the unit conversions should be in the backend while displaying the units should be a client side job. Separating the tasks should allow for easier debugging, and would be much easier to add new functionality. (Simple but longer code is better than shorter and clever code)

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

  • [POST] convert received values to “stored as” units for each endpoint and store (create a helper or something)

  • [GET] convert saved values to “display” units before sending to a client (create a helper or something)

no change required

frontend

  • create a new Unit component (presentation component)

  • fetch data once

auto conversion
(optional?)

DB: need migration
API: auto conversion property in userFarm
(UI: modify user setting view)

backend: update the helper(?) to take user setting into account

frontend: update the hook(?) to take user setting into account

pros

  • some logic can be removed from the frontend

  • the logic is in one place and could avoid small errors for adding lines all over the files

  • no need to test APIs

cons

  • frontend needs to take care of some calculations anyways

  • need to update many APIs and their tests

  • QA needs to test APIs + UI

  • should be careful not to make the same mistakes (no more rework…)

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-2719 - Getting issue details... STATUS

  • we need to deploy APIs & app after backfilling is complete. Do we know how?

Questions:

  • update the style? LF-2910 - Getting issue details... STATUS

  • No labels