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

Refactor/grouping selector #491

Merged
merged 3 commits into from
Oct 11, 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
71 changes: 46 additions & 25 deletions packages/garden/src/lib/components/Garden.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Icon } from '@equinor/eds-core-react';
import { Suspense, useRef } from 'react';
import { Suspense, useRef, useState } from 'react';
import {
CustomVirtualViews,
GardenGroup,
Expand All @@ -16,12 +16,13 @@ import { VirtualContainer } from './VirtualContainer/VirtualContainer';

import { chevron_down, chevron_up } from '@equinor/eds-icons';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { SplashScreen } from './splashScreen/SplashScreen';
import { ErrorBoundary } from 'react-error-boundary';
import { GardenError } from './error/GardenError';
import { GetIdentifier } from '../types/getIdentifier';
import { GardenConfigProvider } from '../context/gardenConfig';
import { GardenContextProvider } from '../context/gardenContext';
import { GetIdentifier } from '../types/getIdentifier';
import { ViewSettings } from './ViewSettings/ViewSettings';
import { GardenError } from './error/GardenError';
import { SplashScreen } from './splashScreen/SplashScreen';

export type GardenMetaRequest = {
groupingKeys: string[];
Expand Down Expand Up @@ -57,40 +58,60 @@ export function Garden<TData extends Record<PropertyKey, unknown>, TContext = un
getDisplayName,
context,
getIdentifier,
groupingKeys,
groupingKeys: initialGrouping,
customViews,
timeInterval,
dateVariant,
timeInterval: initialTimeInterval,
dateVariant: initialDateVariant,
visuals,
clickEvents,
selected = null,
}: GardenProps<TData, TContext>): JSX.Element | null {
const client = useRef(new QueryClient());
const [groupingKeys, setGroupingKeys] = useState<string[]>(initialGrouping);

const [timeInterval, updateTimeInterval] = useState<string | null>(initialTimeInterval ?? null);
const onChangetimeInterval = (timeInterval: string | null) => {
updateTimeInterval(timeInterval);
};
const [dateVariant, updateDateVariant] = useState<string | null>(initialDateVariant ?? null);
const onChangeDateVariant = (dateVariant: string | null) => {
updateDateVariant(dateVariant);
};

return (
<QueryClientProvider client={client.current}>
<ErrorBoundary FallbackComponent={GardenError}>
<GardenContextProvider
getIdentifier={getIdentifier}
timeInterval={timeInterval}
dateVariant={dateVariant}
initialGrouping={groupingKeys}
selected={selected}
>
<GardenConfigProvider
dataSource={dataSource}
getDisplayName={getDisplayName}
<Suspense fallback={<SplashScreen />}>
<GardenContextProvider
getIdentifier={getIdentifier}
clickEvents={clickEvents}
context={context}
customViews={customViews}
visuals={visuals}
timeInterval={timeInterval}
dateVariant={dateVariant}
initialGrouping={groupingKeys}
selected={selected}
>
<Suspense fallback={<SplashScreen />}>
<GardenConfigProvider
dataSource={dataSource}
getDisplayName={getDisplayName}
getIdentifier={getIdentifier}
clickEvents={clickEvents}
context={context}
customViews={customViews}
visuals={visuals}
>
<VirtualContainer context={context as TContext} dataSource={dataSource} />
</Suspense>
</GardenConfigProvider>
</GardenContextProvider>
</GardenConfigProvider>
<ViewSettings
dataSource={dataSource}
dateVariant={dateVariant}
groupingKeys={groupingKeys}
timeInterval={timeInterval}
context={context}
onChangeDateVariant={onChangeDateVariant}
onChangeTimeInterval={onChangetimeInterval}
setGroupingKeys={setGroupingKeys}
/>
</GardenContextProvider>
</Suspense>
</ErrorBoundary>
</QueryClientProvider>
);
Expand Down
Loading
Loading