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

fix: Dashboard onLayoutInitialized not firing if config is empty #1914

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
21 changes: 6 additions & 15 deletions packages/dashboard/src/DashboardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ export function DashboardLayout({
const [initialClosedPanels] = useState<ReactComponentConfig[] | undefined>(
(data as DashboardData)?.closed ?? []
);
const [isDashboardInitialized, setIsDashboardInitialized] = useState(false);
const [layoutChildren, setLayoutChildren] = useState(
layout.getReactChildren()
);

// Fire only once after the layout is mounted
// This should ensure DashboardPlugins have been mounted
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => onLayoutInitialized(), []);

const hydrateMap = useMemo(() => new Map(), []);
const dehydrateMap = useMemo(() => new Map(), []);
const registerComponent = useCallback(
Expand Down Expand Up @@ -201,11 +205,6 @@ export function DashboardLayout({
// we risk the last saved state being one without that panel in the layout entirely
if (isItemDragging) return;

if (!isDashboardInitialized) {
onLayoutInitialized();
setIsDashboardInitialized(true);
}

const glConfig = layout.toConfig();
const contentConfig = glConfig.content;
const dehydratedLayoutConfig = LayoutUtils.dehydrateLayoutConfig(
Expand All @@ -232,15 +231,7 @@ export function DashboardLayout({

setLayoutChildren(layout.getReactChildren());
}
}, [
dehydrateComponent,
isDashboardInitialized,
isItemDragging,
lastConfig,
layout,
onLayoutChange,
onLayoutInitialized,
]);
}, [dehydrateComponent, isItemDragging, lastConfig, layout, onLayoutChange]);

const handleLayoutItemPickedUp = useCallback(
(component: Container) => {
Expand Down
Loading