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

Enhancement - Save Filter States #209

Merged
merged 3 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/motif/src/containers/SidePanel/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
StyleOptions,
GraphList,
GraphData,
FilterOptions,
} from '../../../redux/graph';
import * as Icon from '../../../components/Icons';
import Editable from '../../../components/Editable';
Expand All @@ -28,6 +29,10 @@ const Header = () => {
const styleOptions: StyleOptions = useSelector((state) =>
GraphSelectors.getStyleOptions(state),
);

const filterOptions: FilterOptions = useSelector((state) =>
GraphSelectors.getFilterOptions(state),
);
const dispatch = useDispatch();

const onChangeName = useCallback(
Expand Down Expand Up @@ -78,6 +83,7 @@ const Header = () => {
graphList={graphList}
styleOptions={styleOptions}
graphFlatten={graphFlatten}
filterOptions={filterOptions}
/>
</>
)}
Expand All @@ -91,6 +97,7 @@ const Header = () => {
styleOptions,
graphList,
graphFlatten,
filterOptions,
],
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ const SaveChoicesMenu: FC<SaveChoicesMenuProps> = ({
graphList,
styleOptions,
graphFlatten,
filterOptions,
onExportExternal,
}) => {
const [, theme] = useStyletron();

const exportJSON = (
graphList: GraphT.GraphList,
styleOptions: GraphT.StyleOptions,
) => {
const exportJSON = () => {
const positionGraphList = setGraphListPosition(graphList, graphFlatten);
const exportData: GraphT.TLoadFormat = {
data: positionGraphList,
style: styleOptions,
filter: filterOptions,
};

const contentType = 'application/json;charset=utf-8;';
Expand All @@ -36,11 +35,12 @@ const SaveChoicesMenu: FC<SaveChoicesMenuProps> = ({
document.body.removeChild(file);
};

const saveToCloud = (graphList, styleOptions) => {
const saveToCloud = () => {
const positionGraphList = setGraphListPosition(graphList, graphFlatten);
const exportData: GraphT.TLoadFormat = {
data: positionGraphList,
style: styleOptions,
filter: filterOptions,
};

onExportExternal(exportData);
Expand All @@ -50,19 +50,19 @@ const SaveChoicesMenu: FC<SaveChoicesMenuProps> = ({
const items = [
{
label: <Label.JsonAttachment theme={theme} />,
onClick: () => exportJSON(graphList, styleOptions),
onClick: () => exportJSON(),
},
];

if (onExportExternal) {
items.push({
label: <Label.CloudUpload theme={theme} />,
onClick: () => saveToCloud(graphList, styleOptions),
onClick: () => saveToCloud(),
});
}

return items;
}, [graphList, styleOptions, exportJSON, theme, graphFlatten]);
}, [graphList, styleOptions, exportJSON, theme, graphFlatten, filterOptions]);

return (
<StatefulMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const SaveButton = ({
graphList,
styleOptions,
graphFlatten,
filterOptions,
}: SaveButtonProps) => {
return (
<StatefulPopover
Expand All @@ -25,6 +26,7 @@ const SaveButton = ({
graphList={graphList}
graphFlatten={graphFlatten}
styleOptions={styleOptions}
filterOptions={filterOptions}
onExportExternal={onExportExternal}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type SaveButtonProps = {
graphList: GraphT.GraphList;
graphFlatten: GraphT.GraphData;
styleOptions: GraphT.StyleOptions;
filterOptions: GraphT.FilterOptions;
onExportExternal?: ExplorerContextProps['onExportExternal'];
};
export type LabelProps = { theme: Theme };
4 changes: 4 additions & 0 deletions packages/motif/src/redux/graph/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ const graph = createSlice({
updateStyleOption(state, action: PayloadAction<T.StyleOptions>) {
Object.assign(state.styleOptions, action.payload);
},
updateFilterOption(state, action: PayloadAction<T.FilterOptions>) {
Object.assign(state.filterOptions, action.payload);
},
changeLayout(state, action: PayloadAction<T.LayoutParams>): void {
const { id, ...options } = action.payload.layout;
const defaultOptions = LAYOUT.OPTIONS.find((x) => x.type === id);
Expand Down Expand Up @@ -522,6 +525,7 @@ export const {
updateLastGroupEdgeIds,
overwriteEdgeSelection,
updateNodePosition,
updateFilterOption,
} = graph.actions;

export default graph.reducer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const firstEdgeListCsv =
'id,relation,source,target\ntxn1,works,jason,cylynx\ntxn3,abc,cylynx,timothy\ntxn4,says hi to,swan,cylynx';

export const secondEdgeListCsv = 'id,source,target\n123,x,y\n456,y,z\n789,z,x';

export const quotesHeaderCsv =
'"id","relation","source","target"\ntxn1,works,jason,cylynx\ntxn3,abc,cylynx,timothy\ntxn4,says hi to,swan,cylynx';
Loading