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

Feat/group by update #494

Merged
merged 9 commits into from
Oct 12, 2023
14 changes: 11 additions & 3 deletions packages/garden/src/lib/components/ViewSettings/ViewSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Button, Icon } from '@equinor/eds-core-react';
import { useState } from 'react';

import { useState, useEffect } from 'react';
import { arrow_back_ios, arrow_forward_ios, chevron_down, chevron_up } from '@equinor/eds-icons';
import { GardenDataSource } from '../Garden';
import { GroupingSelector } from '../GroupingSelector/GroupingSelector';
import { StyledViewSettings, VerticalText } from './viewSettings.styles';

const LOCAL_STORAGE_KEY = 'FusionWorkspaceViewSettingsToggled';

interface ViewSettingsProps<TData extends Record<PropertyKey, unknown>, TContext = undefined> {
dataSource: GardenDataSource<TContext>;
context?: TContext;
Expand All @@ -29,7 +30,14 @@ export function ViewSettings<TData extends Record<PropertyKey, unknown>, TContex
onChangeDateVariant,
setGroupingKeys,
}: ViewSettingsProps<TData, TContext>): JSX.Element | null {
const [toggle, setToggle] = useState(false);
const [toggle, setToggle] = useState<boolean>(() => {
const savedState = localStorage.getItem(LOCAL_STORAGE_KEY);
return savedState !== null ? JSON.parse(savedState) : true;
});

useEffect(() => {
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(toggle));
Gustav-Eikaas marked this conversation as resolved.
Show resolved Hide resolved
}, [toggle]);

return (
<StyledViewSettings expanded={toggle}>
Expand Down
Loading