Skip to content

Commit

Permalink
idea for organizing state and files
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrm committed Oct 3, 2023
1 parent 424a624 commit 4bfd56c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 33 deletions.
9 changes: 8 additions & 1 deletion src/components/CheckBoxTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ interface CheckBoxTreeProps {
payloadForSelectAll: VisibilitySelectionMap;
payloadForSelectNone: VisibilitySelectionMap;
isSharedCheckboxIndeterminate: boolean;
colorInfoForPicker: any; //TODO: type this
}
const CHECKBOX_SPAN_NO = 2;
const LABEL_SPAN_NO = 6;
Expand Down Expand Up @@ -211,7 +212,12 @@ class CheckBoxTree extends React.Component<CheckBoxTreeProps> {
</Row>
);
render() {
const { agentsHighlighted, treeData, agentsChecked } = this.props;
const {
agentsHighlighted,
treeData,
agentsChecked,
colorInfoForPicker,
} = this.props;
return treeData.length > 0 ? (
<div className={styles.container}>
<Row className={styles.colLabels}>
Expand Down Expand Up @@ -252,6 +258,7 @@ class CheckBoxTree extends React.Component<CheckBoxTreeProps> {
color={nodeData.color}
agentName={nodeData.title}
tags={this.getAgentTags(nodeData.title)}
colorInfoForPicker={colorInfoForPicker}
/>
<Text
style={{ maxWidth: 143 }}
Expand Down
5 changes: 5 additions & 0 deletions src/components/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface ColorPickerProps {
setColorChanges: ActionCreator<SetColorChangesAction>;
setRecentColors: ActionCreator<SetRecentColorsAction>;
recentColors: string[];
infoForPicker: any; // TODO: type this
}

const ColorPicker = ({
Expand All @@ -30,6 +31,7 @@ const ColorPicker = ({
tags,
recentColors,
setRecentColors,
infoForPicker,

Check warning on line 34 in src/components/ColorPicker/index.tsx

View workflow job for this annotation

GitHub Actions / Lint

'infoForPicker' is defined but never used
}: ColorPickerProps) => {
const [color, setColor] = useState(oldColor);

Expand Down Expand Up @@ -133,6 +135,9 @@ const ColorPicker = ({
</div>
</div>
);
// TODO: move the render function from popover to here,
// encapsulate this stuff into a function called "render picker content" or something and call
// that in content of popover
};

const mapStateToProps = (state: any) => ({
Expand Down
3 changes: 3 additions & 0 deletions src/components/ColorPickerPopover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface ColorPickerPopoverProps {
closeModal: () => void;
agentName: string;
tags: string[];
colorInfoForPicker: any; // TODO: type this
}

const ColorPickerPopover = ({
Expand All @@ -18,6 +19,7 @@ const ColorPickerPopover = ({
closeModal,
agentName,
tags,
colorInfoForPicker,
}: ColorPickerPopoverProps) => {
return (
<Popover
Expand All @@ -28,6 +30,7 @@ const ColorPickerPopover = ({
agentName={agentName}
tags={tags}
oldColor={oldColor}
colorInfoForPicker={colorInfoForPicker}

Check failure on line 33 in src/components/ColorPickerPopover/index.tsx

View workflow job for this annotation

GitHub Actions / Type Check

Type '{ agentName: string; tags: string[]; oldColor: string; colorInfoForPicker: any; }' is not assignable to type 'IntrinsicAttributes & { oldColor: string; agentName: string; tags: string[]; infoForPicker: any; context?: Context<ReactReduxContextValue<any, AnyAction>> | undefined; store?: Store<...> | undefined; } & { ...; }'.
/>
}
placement="right"
Expand Down
19 changes: 10 additions & 9 deletions src/components/ColorSwatch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ interface ColorSwatchProps {
color: string;
agentName: string;
tags: string[];
colorInfoForPicker: any; // TODO: type this
}

const ColorSwatch = ({
childrenHaveDifferentColors,
color,
agentName,
tags,
colorInfoForPicker,
}: ColorSwatchProps): JSX.Element => {
const [isColorPickerVisible, setColorPickerVisible] = useState(false);
const [initialColor, setInitialColor] = useState(color);
Expand Down Expand Up @@ -44,15 +46,14 @@ const ColorSwatch = ({
openModal();
}}
/>
{isColorPickerVisible ? (
<ColorPickerPopover
agentName={agentName}
tags={tags}
oldColor={initialColor}
isOpen={isColorPickerVisible}
closeModal={closeModal}
/>
) : null}
<ColorPickerPopover
agentName={agentName}
tags={tags}
oldColor={initialColor}
isOpen={isColorPickerVisible}
closeModal={closeModal}
colorInfoForPicker={colorInfoForPicker}
/>
</>
);
};
Expand Down
5 changes: 5 additions & 0 deletions src/containers/ModelPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
getSelectAllVisibilityMap,
getSelectNoneVisibilityMap,
getIsSharedCheckboxIndeterminate,
getColorInfoForPicker,
} from "./selectors";
import {
VIEWER_EMPTY,
Expand Down Expand Up @@ -60,6 +61,7 @@ interface ModelPanelProps {
viewerStatus: ViewerStatus;
isNetworkedFile: boolean;
changeToNetworkedFile: ActionCreator<RequestNetworkFileAction>;
colorInfoForPicker: any; // TODO: type this
}

class ModelPanel extends React.Component<ModelPanelProps> {
Expand All @@ -77,6 +79,7 @@ class ModelPanel extends React.Component<ModelPanelProps> {
viewerStatus,
isNetworkedFile,
changeToNetworkedFile: loadNetworkFile,
colorInfoForPicker,
} = this.props;
const checkboxTree = (
<CheckBoxTree
Expand All @@ -89,6 +92,7 @@ class ModelPanel extends React.Component<ModelPanelProps> {
payloadForSelectAll={payloadForSelectAll}
payloadForSelectNone={payloadForSelectNone}
isSharedCheckboxIndeterminate={isSharedCheckboxIndeterminate}
colorInfoForPicker={colorInfoForPicker}
/>
);
const contentMap = {
Expand Down Expand Up @@ -128,6 +132,7 @@ function mapStateToProps(state: State) {
isSharedCheckboxIndeterminate: getIsSharedCheckboxIndeterminate(state),
viewerStatus: getStatus(state),
isNetworkedFile: getIsNetworkedFile(state),
colorInfoForPicker: getColorInfoForPicker(state),
};
}

Expand Down
15 changes: 11 additions & 4 deletions src/containers/ModelPanel/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { isEmpty } from "lodash";

import { AgentDisplayNode } from "../../components/CheckBoxTree";
import { getUiDisplayDataTree } from "../../state/trajectory/selectors";
import { getAgentVisibilityMap } from "../../state/selection/selectors";
import {
getAgentVisibilityMap,
getColorChanges,
getRecentColors,
} from "../../state/selection/selectors";
import { VisibilitySelectionMap } from "../../state/selection/types";

// Returns an agent visibility map that indicates all states should be visible
Expand Down Expand Up @@ -56,9 +60,7 @@ export const getIsSharedCheckboxIndeterminate = createSelector(
if (visibleStates === undefined) {
// This should theoretically never happen
console.warn(
`Skipping agent ${
agent.key
} in getIsSharedCheckboxIndeterminate because it doesn't exist in agentVisibilityMap`
`Skipping agent ${agent.key} in getIsSharedCheckboxIndeterminate because it doesn't exist in agentVisibilityMap`
);
continue;
}
Expand All @@ -74,3 +76,8 @@ export const getIsSharedCheckboxIndeterminate = createSelector(
return numInvisibleAgents > 0 && numInvisibleAgents < allAgents.length;
}
);

export const getColorInfoForPicker = createSelector(
[getColorChanges, getRecentColors],
(colorChanges, recentColors) => ({ colorChanges, recentColors })
);
30 changes: 12 additions & 18 deletions src/state/selection/selectors/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { createSelector } from "reselect";
import { reduce } from "lodash";
import { UIDisplayData } from "@aics/simularium-viewer/type-declarations";
import {
ColorChanges,
SelectionEntry,
} from "@aics/simularium-viewer/type-declarations/simularium/SelectionInterface";
UIDisplayData,
// ColorChanges,
// SelectionEntry,
} from "@aics/simularium-viewer/type-declarations";

import { getAgentDisplayNamesAndStates } from "../../trajectory/selectors";
import { ColorChangesMap, VisibilitySelectionMap } from "../types";
Expand All @@ -17,11 +17,8 @@ import {

export const getHighlightedAgents = createSelector(
[getAgentHighlightMap, getAgentDisplayNamesAndStates],
(
highlightedAgents: VisibilitySelectionMap,
allAgents: UIDisplayData
): SelectionEntry[] => {
const init: SelectionEntry[] = [];
(highlightedAgents: VisibilitySelectionMap, allAgents: UIDisplayData) => {
const init: any = [];
return reduce(
allAgents,
(acc, agent) => {
Expand Down Expand Up @@ -66,8 +63,8 @@ export const getAgentsToHide = createSelector(
(
agentVisibilityMap: VisibilitySelectionMap,
agentDisplayData: UIDisplayData
): SelectionEntry[] => {
const init: SelectionEntry[] = [];
) => {
const init: any = [];
return reduce(
agentDisplayData,
(acc, agent) => {
Expand Down Expand Up @@ -112,15 +109,12 @@ export const getAgentsToHide = createSelector(

export const getColorChanges = createSelector(
[getColorChangesMap, getAgentDisplayNamesAndStates],
(
colorChangesMap: ColorChangesMap,
agentDisplayData: UIDisplayData
): ColorChanges[] => {
const colorArray: ColorChanges[] = [];
(colorChangesMap: ColorChangesMap, agentDisplayData: UIDisplayData) => {
const colorArray: any = [];

const agentColorChanges: SelectionEntry[] = reduce(
const agentColorChanges = reduce(
agentDisplayData,
(acc: SelectionEntry[], agent) => {
(acc: any, agent) => {
if (!colorChangesMap.agents[agent.name]) {
return acc;
}
Expand Down
2 changes: 1 addition & 1 deletion webpack/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const PLUGINS_BY_ENV = {
[Env.DEVELOPMENT]: [
new webpack.EnvironmentPlugin({
// FIXME: make a dev server
BACKEND_SERVER_IP: `staging-node1-agentviz-backend.cellexplore.net`,
BACKEND_SERVER_IP: `production-node1-agentviz-backend.cellexplore.net`,
}),
],
};
Expand Down

0 comments on commit 4bfd56c

Please sign in to comment.