Skip to content

Commit

Permalink
add button for previewing and resetting selected display data
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Nov 23, 2024
1 parent a939a1e commit 402c980
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 7 deletions.
44 changes: 42 additions & 2 deletions src/containers/ModelPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ActionCreator } from "redux";
import { connect } from "react-redux";

import { State } from "../../state/types";
import { getDefaultUISettingsApplied } from "../../state/compoundSelectors";
import { ViewerStatus } from "../../state/viewer/types";
import { getStatus } from "../../state/viewer/selectors";
import { RequestNetworkFileAction } from "../../state/trajectory/types";
Expand All @@ -17,13 +18,18 @@ import {
SetVisibleAction,
SetRecentColorsAction,
HandleColorChangeAction,
ColorSetting,
SetCurrentColorSettingAction,
ResetAction,
} from "../../state/selection/types";
import {
turnAgentsOnByDisplayKey,
highlightAgentsByDisplayKey,
setAgentsVisible,
setRecentColors,
handleColorChange,
setCurrentColorSetting,
clearUserSelectedColors,
} from "../../state/selection/actions";
import {
getAgentVisibilityMap,
Expand All @@ -36,7 +42,8 @@ import NoTrajectoriesText from "../../components/NoTrajectoriesText";
import NetworkFileFailedText from "../../components/NoTrajectoriesText/NetworkFileFailedText";
import NoTypeMappingText from "../../components/NoTrajectoriesText/NoTypeMappingText";
import SideBarContents from "../../components/SideBarContents";
import { AgentMetadata } from "../../constants/interfaces";
import NavButton from "../../components/NavButton";
import { AgentMetadata, ButtonClass } from "../../constants/interfaces";
import {
getSelectAllVisibilityMap,
getSelectNoneVisibilityMap,
Expand All @@ -63,6 +70,9 @@ interface ModelPanelProps {
setRecentColors: ActionCreator<SetRecentColorsAction>;
selectedAgentMetadata: AgentMetadata;
handleColorChange: ActionCreator<HandleColorChangeAction>;
defaultUiSettingsApplied: boolean;
setCurrentColorSetting: ActionCreator<SetCurrentColorSettingAction>;
clearUserSelectedColors: ActionCreator<ResetAction>;
}

const ModelPanel: React.FC<ModelPanelProps> = ({
Expand All @@ -82,6 +92,9 @@ const ModelPanel: React.FC<ModelPanelProps> = ({
setRecentColors,
selectedAgentMetadata,
handleColorChange,
defaultUiSettingsApplied,
setCurrentColorSetting,
clearUserSelectedColors,
}): JSX.Element => {
const checkboxTree = (
<CheckBoxTree
Expand Down Expand Up @@ -112,11 +125,35 @@ const ModelPanel: React.FC<ModelPanelProps> = ({
),
};

const handlePreviewDefaultColors = (colorSetting: ColorSetting) => {
if (!defaultUiSettingsApplied) {
setCurrentColorSetting({ currentColorSetting: colorSetting });
}
};

return (
<div className={styles.container}>
<SideBarContents
mainTitle="Agents"
content={[contentMap[viewerStatus]]}
content={[
<div key="molecules">
{contentMap[viewerStatus]}
<NavButton
titleText={"Restore color defaults"}
buttonType={ButtonClass.Action}
isDisabled={defaultUiSettingsApplied}
clickHandler={clearUserSelectedColors}
onMouseEnter={() =>
handlePreviewDefaultColors(ColorSetting.Default)
}
onMouseLeave={() =>
handlePreviewDefaultColors(
ColorSetting.UserSelected
)
}
/>
</div>,
]}
selectedAgentMetadata={selectedAgentMetadata}
uiDisplayData={uiDisplayDataTree}
/>
Expand All @@ -136,6 +173,7 @@ function mapStateToProps(state: State) {
isNetworkedFile: getIsNetworkedFile(state),
recentColors: getRecentColors(state),
selectedAgentMetadata: getSelectedAgentMetadata(state),
defaultUiSettingsApplied: getDefaultUISettingsApplied(state),
};
}

Expand All @@ -147,6 +185,8 @@ const dispatchToPropsMap = {
setAgentsVisible,
setRecentColors,
handleColorChange,
setCurrentColorSetting,
clearUserSelectedColors,
};

export default connect(mapStateToProps, dispatchToPropsMap)(ModelPanel);
75 changes: 74 additions & 1 deletion src/state/compoundSelectors/compoundSelectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getCurrentUIData } from ".";
import { getCurrentUIData, getDefaultUISettingsApplied } from ".";
import { initialState } from "..";
import { ColorSetting } from "../selection/types";

Expand Down Expand Up @@ -77,3 +77,76 @@ describe("getCurrentUIData", () => {
]);
});
});

describe("getDefaultUISettingsApplied", () => {
it("returns false if selectedUIDisplayData contains selections and selectedUIDisplayData and defaultUIData are not equal", () => {
expect(
getDefaultUISettingsApplied({
...initialState,
trajectory: {
defaultUIData: [
{
name: "agent1",
displayStates: [],
color: "#bbbbbb",
},
],
},
selection: {
...initialState.selection,
selectedUIDisplayData: [
{
name: "agent1",
displayStates: [],
color: "#000",
},
],
},
})
).toBe(false);
});
it("returns true if selectedUIDisplayData contains no selections", () => {
expect(
getDefaultUISettingsApplied({
...initialState,
trajectory: {
defaultUIData: [
{
name: "agent1",
displayStates: [],
color: "#bbbbbb",
},
],
},
selection: {
selectedUIDisplayData: [],
},
})
).toBe(true);
});
it("returns true if selectedUIDisplayData and defaultUIData are equal", () => {
expect(
getDefaultUISettingsApplied({
...initialState,
trajectory: {
defaultUIData: [
{
name: "agent1",
displayStates: [],
color: "#bbbbbb",
},
],
},
selection: {
selectedUIDisplayData: [
{
name: "agent1",
displayStates: [],
color: "#bbbbbb",
},
],
},
})
).toBe(true);
});
});
15 changes: 15 additions & 0 deletions src/state/compoundSelectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSelector } from "reselect";
import { UIDisplayData } from "@aics/simularium-viewer";
import { isEqual } from "lodash";

import { getDefaultUIDisplayData } from "../trajectory/selectors";
import {
Expand All @@ -20,3 +21,17 @@ export const getCurrentUIData = createSelector(
: defaultData;
}
);

export const getDefaultUISettingsApplied = createSelector(
[getSelectedUIDisplayData, getDefaultUIDisplayData],
(selectedUIDisplayData, defaultUIData) => {
/**
* we can't just check if currentColorSettings === ColorSettings.Default
* because that state can be used to preview settings
*/
return (
selectedUIDisplayData.length === 0 ||
isEqual(selectedUIDisplayData, defaultUIData)
);
}
);
7 changes: 7 additions & 0 deletions src/state/selection/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GET_DISPLAY_DATA_FROM_BROWSER,
SET_CURRENT_COLOR_SETTINGS,
HANDLE_COLOR_CHANGE,
CLEAR_UI_DATA_FROM_STATE,
} from "./constants";
import {
ChangeAgentsRenderingStateAction,
Expand Down Expand Up @@ -136,3 +137,9 @@ export function setCurrentColorSetting(payload: {
type: SET_CURRENT_COLOR_SETTINGS,
};
}

export function clearUserSelectedColors(): ResetAction {
return {
type: CLEAR_UI_DATA_FROM_STATE,
};
}
3 changes: 3 additions & 0 deletions src/state/selection/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ export const GET_DISPLAY_DATA_FROM_BROWSER = makeSelectConstant(
export const SET_CURRENT_COLOR_SETTINGS = makeSelectConstant(
"set-current-color-settings"
);
export const CLEAR_UI_DATA_FROM_STATE = makeSelectConstant(
"clear-ui-data-from-state"
);
26 changes: 22 additions & 4 deletions src/state/selection/logics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getCurrentUIData } from "../compoundSelectors";
import {
GET_DISPLAY_DATA_FROM_BROWSER,
HANDLE_COLOR_CHANGE,
CLEAR_UI_DATA_FROM_STATE,
} from "./constants";
import { setCurrentColorSetting, setSelectedUIDisplayData } from "./actions";
import { applyColorChangeToUiDisplayData, isSameAgentTree } from "../../util";
Expand Down Expand Up @@ -57,9 +58,6 @@ const getDisplayDataFromBrowserLogic = createLogic({
);
reject(action);
}
setCurrentColorSetting({
currentColorSetting: ColorSetting.UserSelected,
});
allow(setSelectedUIDisplayData(storedUIData));
},
process() {
Expand All @@ -70,4 +68,24 @@ const getDisplayDataFromBrowserLogic = createLogic({
type: GET_DISPLAY_DATA_FROM_BROWSER,
});

export default [handleColorChangeLogic, getDisplayDataFromBrowserLogic];
export const resetSelectedUIDisplayDataLogic = createLogic({
process(deps: ReduxLogicDeps, dispatch, done) {
const { getState } = deps;
const fileKey = getSimulariumFile(getState()).name;
localStorage.removeItem(fileKey);
dispatch(
setCurrentColorSetting({
currentColorSetting: ColorSetting.Default,
})
);
dispatch(setSelectedUIDisplayData([]));
done();
},
type: CLEAR_UI_DATA_FROM_STATE,
});

export default [
handleColorChangeLogic,
getDisplayDataFromBrowserLogic,
resetSelectedUIDisplayDataLogic,
];

0 comments on commit 402c980

Please sign in to comment.