-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/restore default #615
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
Changes from 16 commits
667a0a5
a0e99bf
25f4478
7ac652e
621c6d0
5a1b26c
6071d62
9dae22e
1818d54
853fb53
881e59c
b7a3bb8
7ed1d8c
a939a1e
402c980
6198f25
d3f0b27
d535a81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
|
@@ -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, | ||
|
|
@@ -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, | ||
|
|
@@ -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> = ({ | ||
|
|
@@ -82,6 +92,9 @@ const ModelPanel: React.FC<ModelPanelProps> = ({ | |
| setRecentColors, | ||
| selectedAgentMetadata, | ||
| handleColorChange, | ||
| defaultUiSettingsApplied, | ||
| setCurrentColorSetting, | ||
| clearUserSelectedColors, | ||
| }): JSX.Element => { | ||
| const checkboxTree = ( | ||
| <CheckBoxTree | ||
|
|
@@ -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} | ||
| /> | ||
|
|
@@ -136,6 +173,7 @@ function mapStateToProps(state: State) { | |
| isNetworkedFile: getIsNetworkedFile(state), | ||
| recentColors: getRecentColors(state), | ||
| selectedAgentMetadata: getSelectedAgentMetadata(state), | ||
| defaultUiSettingsApplied: getDefaultUISettingsApplied(state), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -147,6 +185,8 @@ const dispatchToPropsMap = { | |
| setAgentsVisible, | ||
| setRecentColors, | ||
| handleColorChange, | ||
| setCurrentColorSetting, | ||
| clearUserSelectedColors, | ||
| }; | ||
|
|
||
| export default connect(mapStateToProps, dispatchToPropsMap)(ModelPanel); | ||
| 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 { | ||
|
|
@@ -8,13 +9,6 @@ import { | |
| } from "../selection/selectors"; | ||
| import { ColorSetting } from "../selection/types"; | ||
|
|
||
| /** | ||
| * compoundSelectors are selectors that consume state from multiple branches | ||
| * of state, so don't belong in a particular branch's selectors file, | ||
| * and are consumed by multiple containers, and so don't belong in a particular | ||
| * container's selectors file. | ||
| */ | ||
|
|
||
| export const getCurrentUIData = createSelector( | ||
| [getCurrentColorSetting, getSelectedUIDisplayData, getDefaultUIDisplayData], | ||
| ( | ||
|
|
@@ -27,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) | ||
| ); | ||
| } | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that other elements are interacting with color changing, this needed to be a little more robust so prevent re-renders from triggering this and making preview events into permanent selection changes.