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/selector org #606

Merged
merged 6 commits into from
Nov 18, 2024
Merged

Feature/selector org #606

merged 6 commits into from
Nov 18, 2024

Conversation

interim17
Copy link
Contributor

@interim17 interim17 commented Oct 31, 2024

Time estimate or Size

small/medium
Changes related to directory organization, connected to #607, will not merge to main until both PRs are approved

Problem

Advances #511

Solution

@frasercl raised some interesting concerns about state branches in a previous PR

We have redux selectors in /state that are:

  • basic selection of piece of state
  • more complex derivation of state within a branch
  • container specific selectors (ModelPanel, ViewerPanel, etc.)

Now adding compoundSelectors to /state to account for selectors that consume state from multiple branches and are used multiple containers.

This resolution keeps the actual data for defaultUIDisplayData in the trajectory branch and selectedUIDisplayData and ColorSettings in the selection branch, and avoids circular dependencies when the branches try to import each other's selectors.

This work is essentially part of #607, but so many lines of moving/organizing code was obscuring the readability of that PR. I will not merge either PR until both are approved. It is a non-breaking change, the app should run as before.

getCurrentUIData

The selector which pulls from multiple branches to determine the current color settings for the app, and to pass to the viewer.

getUiDisplayDataTree

Previously in trajectory moved to ModelPanel as it depends on a compound selector, and is only used in once place, could also be in compoundSelectors folder...

Comment on lines +167 to +170
describe("getUiDisplayDataTree", () => {
it("returns an empty array if ui display data is empty", () => {
expect(getUiDisplayDataTree(initialState)).toStrictEqual([]);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just moved

Copy link

github-actions bot commented Oct 31, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
67.33% (+0.41% 🔼)
709/1053
🟡 Branches
67.52% (+0.42% 🔼)
106/157
🔴 Functions
35.98% (+0.49% 🔼)
95/264
🟡 Lines
65.73% (+0.43% 🔼)
631/960
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / types.ts
100% 100% 100% 100%
🟢
... / index.ts
100% 100% 100% 100%

Test suite run success

132 tests passing in 8 suites.

Report generated by 🧪jest coverage report action from 622b3b3

Comment on lines 11 to 31
export const getCurrentUIData = createSelector(
[
getCurrentColorSettings,
getSelectedUIDisplayData,
getDefaultUIDisplayData,
],
(
colorSetting: ColorSettings,
sessionData: UIDisplayData,
defaultData: UIDisplayData
) => {
const fileHasBeenParsed = defaultData.length > 0;
if (!fileHasBeenParsed) {
return [];
}
if (colorSetting === ColorSettings.UserSelected) {
return sessionData;
}
return defaultData;
}
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Important in forthcoming work but not functionally relevant until it replaces getSelectedUIDisplayData in getSelectionStateInfoForViewer

Mostly here to demonstrate the reasoning behind compoundSelectors

@interim17 interim17 marked this pull request as ready for review November 1, 2024 16:30
@interim17 interim17 requested a review from a team as a code owner November 1, 2024 16:30
@interim17 interim17 requested review from meganrm, ShrimpCryptid and frasercl and removed request for a team and ShrimpCryptid November 1, 2024 16:30
getSelectedUIDisplayData,
} from "../selection/selectors";
import { ColorSettings } from "../selection/types";
import { UIDisplayData } from "@aics/simularium-viewer";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: organize imports

@@ -87,3 +87,8 @@ export interface SetSelectedUIDisplayDataAction {
payload: UIDisplayData;
type: string;
}

export enum ColorSettings {
Copy link
Contributor

@meganrm meganrm Nov 5, 2024

Choose a reason for hiding this comment

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

nit: make this singular. So when it's used: colorSetting.Default it makes sense. it's a single setting

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a good suggestion for this name, but it could be confusing because at first glance it seems like it's going to be a list of colors. the singular will help, but something like, colorsToUse or colorsOrigin?

@@ -13,3 +13,5 @@ export const getSelectedAgentMetadata = (state: State) =>
state.selection.selectedAgentMetadata;
export const getSelectedUIDisplayData = (state: State) =>
state.selection.selectedUIDisplayData;
export const getCurrentColorSettings = (state: State) =>
state.selection.currentColorSettings;
Copy link
Contributor

Choose a reason for hiding this comment

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

should also be singular (otherwise it sounds like it's going to be a list of colors, when it's just the singular binary setting)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about currentColorSetting/getCurrentColorSetting for state and AgentColorMapping for the typing.

Examples:
if (colorSetting === AgentColorMapping.UserSelected)
or
currentColorSetting: AgentColorMapping.Default,

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't call it a Mapping because that generally means it's a lookup "table". but this is just the value you use in another lookup

@interim17 interim17 requested a review from meganrm November 6, 2024 01:03
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.

I like it!

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a short comment at the top of this file that describes what this file is for, like you did in the PR description?

I also see that the parent state directory has a README.md that (among other things) goes over the file structure for all this redux stuff - consider updating that as well

@interim17 interim17 merged commit 5c070a9 into main Nov 18, 2024
6 checks passed
@interim17 interim17 deleted the feature/selector-org branch November 18, 2024 20:52
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.

3 participants