Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Feature/user colors #584

Merged
merged 11 commits into from
Oct 22, 2024
Merged

Feature/user colors #584

merged 11 commits into from
Oct 22, 2024

Conversation

interim17
Copy link
Contributor

Time estimate or Size

small

Problem

Closes #579, advances #511

We need to differentiate between the default UI data derived by parsing trajectories and the current UI data that includes user color selections. This PR adds selectedUIDisplayData to redux, and points the getSelectionStateInfoForViewer selector at it. When default arrives it sets the initial state for selected, and then as users make color changes we only update the selected data, and the default remains unchanged.

Steps to Verify:

  1. Nothing should be functionally changed, loading trajectories and changing colors should work as before.

@interim17 interim17 requested a review from a team as a code owner October 14, 2024 18:30
@interim17 interim17 requested review from meganrm and frasercl and removed request for a team October 14, 2024 18:30
Copy link

github-actions bot commented Oct 14, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
66.34% (-0.2% 🔻)
674/1016
🟡 Branches 65.31% 96/147
🔴 Functions
35% (-0.29% 🔻)
91/260
🟡 Lines
64.72% (-0.23% 🔻)
600/927
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🔴
... / reducer.ts
20% (-1.74% 🔻)
100% 0%
20% (-1.74% 🔻)
🔴
... / actions.ts
52.17% (-0.21% 🔻)
100% 0%
52.17% (-0.21% 🔻)

Test suite run success

121 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from c52e95d

Copy link
Contributor

@frasercl frasercl left a comment

Choose a reason for hiding this comment

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

Looks okay overall, though I have a couple concerns about the use of logics.

Comment on lines +643 to +650
const setInitialSelectedUIData = createLogic({
process(deps: ReduxLogicDeps, dispatch) {
const { action } = deps;
const uiData = action.payload;
dispatch(setSelectedUIDisplayData(uiData));
},
type: SET_DEFAULT_UI_DATA,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic looks like it just re-dispatches the triggering action with a different type? If not, what am I missing; if so, why not just use that action in place of the one that triggers this logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your point is valid!

Context: this was a larger PR, and I got the feedback that I should chunk things up in more bite size pieces. You're correct that this doesn't really need this logic yet, we can just call both setDefaultUIData and setSelectedUIDisplayData in ViewerPanel, and I would happily make that change for now.

I know because I have a crystal ball, that we are likely going to need this asynchronous logic because we won't know what happens first: parsing of the trajectory to derive defaultUIData and retrieval from browser storage of selectedUIData.

This is a problem of my making! Trying to work backwards from bigger feature branches into smaller PRs can lead to issues like this.

Maybe the defining of the subtasks is the real problem, as this whole PR is somewhat contrived and serves no purpose except to lay the groundwork for forthcoming code, so I wonder what is the greater sin: using this logic to set derived state, or correctly storing state that is never accessed in the first place.

Comment on lines 34 to 36
});
dispatch(setDefaultUIData(newUiData));
dispatch(setSelectedUIDisplayData(newUiData));
done();
Copy link
Contributor

@frasercl frasercl Oct 22, 2024

Choose a reason for hiding this comment

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

Still a bit bummed to see this synchronous state derivation code in a logic. Everything this code does would (I think) work just fine in a reducer branch, and would probably be more at home there, where it wouldn't have to re-dispatch a new action and immediately call done to clear out resources held by redux-logic for what it assumes to be an async operation. That change is well out of scope for this PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like a good opportunity for a refactor. This logic was put in place during previous work on color changing, and its role has changed.

We can derive the new UiDisplayData and pass it into redux directly, redux never needs to handle the ColorChange. I am inclined to do this in ModelPanel instead of in the reducer because the pattern in this repo is for reducers to simply pass on their action payload without side effects.

Adding (synchronous) logic to a reducer feels like breaking that pattern in a way that puts code in more places which is part of the pain of redux, for me at least. But I accept that this redux-logic is not the right place for it either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrote a brief issue (#596 ) and will address in a separate PR.

@interim17 interim17 merged commit 8a87085 into main Oct 22, 2024
6 checks passed
@interim17 interim17 deleted the feature/user-colors branch October 22, 2024 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

differentiate default color settings from changed color settings
3 participants