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: Close panels when object is nulled out #170

Merged
merged 1 commit into from
Dec 15, 2023
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
12 changes: 12 additions & 0 deletions plugins/ui/src/js/src/DashboardPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export function DashboardPlugin({
[]
);

const handlePanelClose = useCallback((panelId: string) => {
setWidgetMap(prevWidgetMap => {
if (!prevWidgetMap.has(panelId)) {
return prevWidgetMap;
}
const newWidgetMap = new Map<string, WidgetWrapper>(prevWidgetMap);
newWidgetMap.delete(panelId);
return newWidgetMap;
});
}, []);
mattrunyon marked this conversation as resolved.
Show resolved Hide resolved

const handleWidgetClose = useCallback((widgetId: string) => {
log.debug('Closing widget', widgetId);
setWidgetMap(prevWidgetMap => {
Expand All @@ -83,6 +94,7 @@ export function DashboardPlugin({

// TODO: We need to change up the event system for how objects are opened, since in this case it could be opening multiple panels
useListener(layout.eventHub, PanelEvent.OPEN, handlePanelOpen);
useListener(layout.eventHub, PanelEvent.CLOSE, handlePanelClose);

const widgetHandlers = useMemo(
() =>
Expand Down