-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reuse dashboard tabs when reassigning the variable (#2243)
Fixes #1971 Tested with this code run 1 line at a time ```python import deephaven.ui as ui a = ui.dashboard(ui.text("Hello")) a = ui.dashboard(ui.text("World")) a = ui.text("Hello") a = ui.dashboard(ui.text("Hello")) del a ``` Also tested dashboards still load in embed-widget. There was a race condition since the `makeUseListenerFunction` hook was using `useEffect`. This caused the event to emit between the event hub being set and the listener being added.
- Loading branch information
1 parent
91bd8fe
commit d2c6eab
Showing
5 changed files
with
95 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,23 @@ | ||
import type { EventHub } from '@deephaven/golden-layout'; | ||
import { makeEventFunctions } from '@deephaven/golden-layout'; | ||
|
||
export const CREATE_DASHBOARD = 'CREATE_DASHBOARD'; | ||
|
||
export const CLOSE_DASHBOARD = 'CLOSE_DASHBOARD'; | ||
|
||
export interface CreateDashboardPayload<T = unknown> { | ||
pluginId: string; | ||
title: string; | ||
data: T; | ||
} | ||
|
||
export function stopListenForCreateDashboard<T = unknown>( | ||
eventHub: EventHub, | ||
handler: (p: CreateDashboardPayload<T>) => void | ||
): void { | ||
try { | ||
eventHub.off(CREATE_DASHBOARD, handler); | ||
} catch { | ||
// golden-layout throws if the handler is not found. Instead catch it and no-op | ||
} | ||
} | ||
export const { | ||
listen: listenForCreateDashboard, | ||
emit: emitCreateDashboard, | ||
useListener: useCreateDashboardListener, | ||
} = makeEventFunctions<[detail: CreateDashboardPayload]>(CREATE_DASHBOARD); | ||
|
||
export function listenForCreateDashboard<T = unknown>( | ||
eventHub: EventHub, | ||
handler: (p: CreateDashboardPayload<T>) => void | ||
): () => void { | ||
eventHub.on(CREATE_DASHBOARD, handler); | ||
return () => stopListenForCreateDashboard(eventHub, handler); | ||
} | ||
|
||
export function emitCreateDashboard<T = unknown>( | ||
eventHub: EventHub, | ||
payload: CreateDashboardPayload<T> | ||
): void { | ||
eventHub.emit(CREATE_DASHBOARD, payload); | ||
} | ||
export const { | ||
listen: listenForCloseDashboard, | ||
emit: emitCloseDashboard, | ||
useListener: useCloseDashboardListener, | ||
} = makeEventFunctions<[title: string]>(CLOSE_DASHBOARD); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters