[feat]: persistence of graph toggle on variable change (#4316)

* feat: persistence of graph toggle on variable change

* fix: reverted the previous changes

* chore: full view global time selector to right
This commit is contained in:
Rajat Dabade 2024-01-18 23:22:30 +05:30 committed by GitHub
parent 0c1a500142
commit 46559014f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,6 @@
.full-view-header-container { .full-view-header-container {
display: flex; display: flex;
justify-content: center; justify-content: flex-end;
align-items: center; align-items: center;
padding: 24px 0; padding: 24px 0;

View File

@ -46,6 +46,7 @@ function WidgetGraphComponent({
data, data,
options, options,
onDragSelect, onDragSelect,
graphVisibility,
}: WidgetGraphComponentProps): JSX.Element { }: WidgetGraphComponentProps): JSX.Element {
const [deleteModal, setDeleteModal] = useState(false); const [deleteModal, setDeleteModal] = useState(false);
const [hovered, setHovered] = useState(false); const [hovered, setHovered] = useState(false);
@ -83,6 +84,10 @@ function WidgetGraphComponent({
setGraphsVisibilityStates(localStoredVisibilityStates); setGraphsVisibilityStates(localStoredVisibilityStates);
}, [localStoredVisibilityStates]); }, [localStoredVisibilityStates]);
graphVisibility?.forEach((state, index) => {
lineChartRef.current?.toggleGraph(index, state);
});
const { setLayouts, selectedDashboard, setSelectedDashboard } = useDashboard(); const { setLayouts, selectedDashboard, setSelectedDashboard } = useDashboard();
const featureResponse = useSelector<AppState, AppReducer['featureResponse']>( const featureResponse = useSelector<AppState, AppReducer['featureResponse']>(

View File

@ -163,6 +163,17 @@ function GridCardGraph({
? headerMenuList.filter((menu) => menu !== MenuItemKeys.CreateAlerts) ? headerMenuList.filter((menu) => menu !== MenuItemKeys.CreateAlerts)
: headerMenuList; : headerMenuList;
const [graphVisibility, setGraphVisibility] = useState<boolean[]>(
Array(queryResponse.data?.payload?.data.result.length || 0).fill(true),
);
useEffect(() => {
setGraphVisibility([
true,
...Array(queryResponse.data?.payload?.data.result.length).fill(true),
]);
}, [queryResponse.data?.payload?.data.result.length]);
const options = useMemo( const options = useMemo(
() => () =>
getUPlotChartOptions({ getUPlotChartOptions({
@ -178,6 +189,8 @@ function GridCardGraph({
maxTimeScale, maxTimeScale,
softMax: widget.softMax === undefined ? null : widget.softMax, softMax: widget.softMax === undefined ? null : widget.softMax,
softMin: widget.softMin === undefined ? null : widget.softMin, softMin: widget.softMin === undefined ? null : widget.softMin,
graphsVisibilityStates: graphVisibility,
setGraphsVisibilityStates: setGraphVisibility,
}), }),
[ [
widget?.id, widget?.id,
@ -192,6 +205,8 @@ function GridCardGraph({
onClickHandler, onClickHandler,
minTimeScale, minTimeScale,
maxTimeScale, maxTimeScale,
graphVisibility,
setGraphVisibility,
], ],
); );
@ -212,6 +227,7 @@ function GridCardGraph({
threshold={threshold} threshold={threshold}
headerMenuList={menuList} headerMenuList={menuList}
onClickHandler={onClickHandler} onClickHandler={onClickHandler}
graphVisibility={graphVisibility}
/> />
)} )}
</div> </div>

View File

@ -28,6 +28,7 @@ export interface WidgetGraphComponentProps extends UplotProps {
threshold?: ReactNode; threshold?: ReactNode;
headerMenuList: MenuItemKeys[]; headerMenuList: MenuItemKeys[];
isWarning: boolean; isWarning: boolean;
graphVisibility?: boolean[];
} }
export interface GridCardGraphProps { export interface GridCardGraphProps {