UBCSailbot / sailbot_workspace

UBC Sailbot's monorepo
https://ubcsailbot.github.io/sailbot_workspace/main/
Apache License 2.0
4 stars 1 forks source link

Ability to Rearrange Charts on Data Dashboard #295

Closed jahn18 closed 5 months ago

jahn18 commented 7 months ago

Purpose

Users should have the ability to move charts around.

Description

This still requires an initial design. Please work on the design here: https://docs.google.com/presentation/d/1ewzopIbE7nNtew-pzOVGlbBm-ShRoF-1CaN7ZTIj9UU/edit#slide=id.g2b95e401a1d_0_4

Redux Implementation: We want to save the arrangement of the charts within a the global store so that several components can access it.

Steps:

  1. Create a new folder under stores.

  2. Create files for Action, Types, Reducers, and Sagas (Several examples are shown here https://github.com/UBCSailbot/website/tree/main/stores). We won't be calling an API in this case, so a file for Service is not necessary.

*[<ACTION_NAME_REARRANGING_CHART>]() {
    yield takeLatest(<ACTION_NAME_REARRANGING_CHART>, (action) => {
        ... add logic here to call reducers for update succeed and update failed case 
    })
}

takeLastest will call the function you implemented whenever a <ACTION_NAME_REARRANGING_CHART> action is dispatched.

  1. Dispatch the action when a user updates the chart arrangment.

We most likely want to call this dispatch when a user completes rearranging the chart (possibly by pressing some button?). Take a look here as an example as to how this can be done: https://redux-saga.js.org/docs/introduction/GettingStarted

  1. Add the Saga and Reducer class you implemented to https://github.com/UBCSailbot/website/blob/main/lib/redux/rootReducer.ts and https://github.com/UBCSailbot/website/blob/main/lib/redux/rootSaga.ts

  2. Access the data you saved in the redux store within the DashboardContainer file.

You want to modify mapStateToProps to access the data you saved in the redux store. Take a look here: https://github.com/UBCSailbot/website/blob/main/views/DashboardContainer.tsx#L142C7-L142C22. Once you pass in the correct data, you can then access it as a prop within the class (take gps, batteries, and windSensors as an example).

Now using the data you saved, you can then use this to determine how the charts should be rearranged.

  1. How will we save the arrangement of the chart for each user? It would be pretty annoying to have to rearrange the charts everytime we refresh.