Skip to content

Commit

Permalink
fix(dashboard): memo dashboard props to app changes resulting in dash…
Browse files Browse the repository at this point in the history
…board reverting state
  • Loading branch information
haweston committed Sep 16, 2024
1 parent 960f195 commit f7c92f4
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions packages/dashboard/src/components/dashboard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { memo } from 'react';
import React, { memo, useMemo } from 'react';
import { Provider } from 'react-redux';
import { DndProvider } from 'react-dnd';
import { TouchBackend } from 'react-dnd-touch-backend';
Expand Down Expand Up @@ -64,23 +64,34 @@ const Dashboard: React.FC<DashboardProperties> = ({
? debounce(onViewportChange, 100)
: undefined;

const readOnly = initialViewMode && initialViewMode === 'preview';
const readOnly = useMemo(() => {
return initialViewMode && initialViewMode === 'preview';
}, [initialViewMode]);

const initialStore = useMemo(() => {
return configureDashboardStore({
...toDashboardState(dashboardConfiguration),
readOnly,
isEdgeModeEnabled: isEdgeModeEnabled(edgeMode),
});
}, [dashboardConfiguration, edgeMode, readOnly]);

const clients = useMemo(
() => getClients(clientConfiguration),
[clientConfiguration]
);
const queries = useMemo(
() => getQueries(clientConfiguration, edgeMode),
[clientConfiguration, edgeMode]
);

return (
<>
{showFPSMonitor && <FpsView height={50} width={80} />}
<ClientContext.Provider value={getClients(clientConfiguration)}>
<QueryContext.Provider
value={getQueries(clientConfiguration, edgeMode)}
>
<ClientContext.Provider value={clients}>
<QueryContext.Provider value={queries}>
<QueryClientProvider client={queryClient}>
<Provider
store={configureDashboardStore({
...toDashboardState(dashboardConfiguration),
readOnly,
isEdgeModeEnabled: isEdgeModeEnabled(edgeMode),
})}
>
<Provider store={initialStore}>
<DndProvider
backend={TouchBackend}
options={{
Expand Down

0 comments on commit f7c92f4

Please sign in to comment.