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

Added show all and hide all functionality to Chart manager #127

Merged
merged 3 commits into from
Nov 29, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"watch": "npx webpack --mode=development --watch",
"gobuild": "./buildandrun.sh",
"lint": "npx eslint src/js",
"lint-fix": "npx eslint --fix src/js"
"lint-fix": "npx eslint --fix src/js",
"prettier": "npx prettier --write src/js"
},
"keywords": [],
"author": "",
Expand Down
48 changes: 44 additions & 4 deletions src/js/components/Overview/Drawer/ManageChartsDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
import React from 'react';

import { Drawer, DrawerProps, Typography } from 'antd';
import { Button, Drawer, DrawerProps, Flex, Space, Typography } from 'antd';
const { Title } = Typography;

import ChartTree from './ChartTree';

import { ChartDataField } from '@/types/data';
import { useAppSelector, useTranslationCustom, useTranslationDefault } from '@/hooks';
import { useAppSelector, useAppDispatch, useTranslationCustom, useTranslationDefault } from '@/hooks';
import { hideAllSectionCharts, setAllDisplayedCharts } from '@/features/data/data.store';

const ManageChartsDrawer = ({ onManageDrawerClose, manageDrawerVisible }: ManageChartsDrawerProps) => {
const t = useTranslationCustom();
const td = useTranslationDefault();

const dispatch = useAppDispatch();

const sections = useAppSelector((state) => state.data.sections);

return (
<Drawer title={td('Manage Charts')} placement="right" onClose={onManageDrawerClose} open={manageDrawerVisible}>
<Drawer
title={td('Manage Charts')}
placement="right"
onClose={onManageDrawerClose}
open={manageDrawerVisible}
extra={
<Button
size="small"
onClick={() => {
dispatch(setAllDisplayedCharts({}));
}}
>
Show All
</Button>
}
>
{sections.map(({ sectionTitle, charts }: { sectionTitle: string; charts: ChartDataField[] }, i: number) => (
<div key={i}>
<Title level={5}>{t(sectionTitle)}</Title>
<Flex justify="space-between" align="center" style={{ padding: '10px 0' }}>
<Title level={5} style={{ margin: '0' }}>
{t(sectionTitle)}
</Title>
<Space>
<Button
size="small"
onClick={() => {
dispatch(setAllDisplayedCharts({ section: sectionTitle }));
}}
>
Show All
</Button>
<Button
size="small"
onClick={() => {
dispatch(hideAllSectionCharts({ section: sectionTitle }));
}}
>
Hide All
</Button>
</Space>
</Flex>
<ChartTree charts={charts} section={sectionTitle} />
</div>
))}
Expand Down
31 changes: 30 additions & 1 deletion src/js/features/data/data.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,28 @@ const data = createSlice({
const chartObj = state.sections.find((e) => e.sectionTitle === section)!.charts.find((c) => c.id === chart)!;
chartObj.width = width;
},
setAllDisplayedCharts: (state, { payload }: PayloadAction<{ section?: string }>) => {
if (payload.section) {
state.sections
.find((e) => e.sectionTitle === payload.section)!
.charts.forEach((_, ind, arr) => {
arr[ind].isDisplayed = true;
});
} else {
state.sections.forEach((section) => {
section.charts.forEach((val, ind, arr) => {
arr[ind].isDisplayed = true;
});
});
}
},
hideAllSectionCharts: (state, { payload }: PayloadAction<{ section: string }>) => {
state.sections
.find((e) => e.sectionTitle === payload.section)!
.charts.forEach((_, ind, arr) => {
arr[ind].isDisplayed = false;
});
},
},
extraReducers: (builder) => {
builder
Expand All @@ -64,6 +86,13 @@ const data = createSlice({
},
});

export const { rearrange, disableChart, setDisplayedCharts, setChartWidth } = data.actions;
export const {
rearrange,
disableChart,
setDisplayedCharts,
setChartWidth,
setAllDisplayedCharts,
hideAllSectionCharts,
} = data.actions;
export { makeGetDataRequestThunk };
export default data.reducer;