User History Introduction - Seeding Rate Calculator

The user history feature enables users to save their calculation process, so they don’t have to reselect options each time they log in. When users log in again, the application retrieves this data from the backend, allowing them to resume their previous selections without reconfiguring their choices. This enhances user experience by providing a personalized interaction with the app.

Schema definition:

The history data saved in the backend is defined by schema, and will update constantly.

You can find the documentation about setting up schema here.

The schema number currently used is specified in .env file. Currently the schema contains most redux data and is structured as follows:

{ "type": "object", "data": { "id": 5, "version": "1.0.3", "standard": "OpenAPI 3.0.0", "json": { "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string" }, "calculator": { "type": "object", "properties": { "unit": { "type": "string" }, "options": { "type": "object" }, "seedsSelected": { "type": "array", "items": { "type": "object" } }, "mixSeedingRate": { "type": "number" }, "seedingMethods": { "type": "object" }, "bulkSeedingRate": { "type": "object" }, "sideBarSelection": { "type": "string" }, "diversitySelected": { "type": "array", "items": { "type": "string" } }, "adjustedMixSeedingRate": { "type": "number" } } }, "siteCondition": { "type": "object", "properties": { "acres": { "type": "number" }, "state": { "type": "string" }, "county": { "type": "string" }, "latlon": { "type": "array", "items": { "type": "number" } }, "council": { "type": "string" }, "stateId": { "type": "number" }, "countyId": { "type": "number" }, "plantingDate": { "type": "string" }, "soilDrainage": { "type": "string" }, "tileDrainage": { "type": "boolean" }, "soilFertility": { "type": "string" }, "checkNRCSStandards": { "type": "boolean" } } } } }, "serviceId": 2, "createdAt": "2024-03-28T18:48:24.285Z", "updatedAt": "2024-03-28T18:48:24.285Z", "deletedAt": null } }

User experience:

To utilize the user history feature, the user must sign up and log in first. At Site Condition page, click on Create New Calculation button to create a new history record with a nickname. After that, when the user make any selection and switch page, the history will be saved in the backend.

To load the history, use the dropdown on first page to select one record and click Import button to load the history. This allows the user retrieve the previous calculation and make any changes. However, there are some data on Site Condition which are unable to change (like state or location since these will affect the further result). When the user attempt to make change, a popup will prompt the user to create a new record. Also, for selections on Species Selection and Mix Ratios page, the user still have options to update their selections, but this will replace the data in the further steps of the calculation.

Except for this, the user is able to edit other information in other steps, and the changes will be saved in the history.

 

HistoryState automata:

The major user history is controlled several redux values defined in user redux. The major value that controls the state of history is historyState . There are 4 possible values defined in src\features\userSlice\state.js which are: none, new, imported, updated.

The historyState will change based on several situations:

If no history is imported, the value will be none.

If a new history is created, the value will be new and will keep it through steps.

If a history is loaded, the value will be imported until there’s any changes.

If a history is updated, the value will be updated until it’s saved through step change, and then it will be set back to imported.

 

Save history in the backend:

When a new history is created, the history api will trigger every time there’s a step change and save the changes to the backend.

When a history record is imported, the history api will not trigger upon step change unless user make ay changes at that step and historyState will change to updated. Then the api would be called and save the data and reset historyState to imported.