Skip to content

Commit 8126c69

Browse files
authored
refactor: DH-19267: columns changed filter event takes an id rather than a panel (#2417)
https://deephaven.atlassian.net/browse/DH-19267 Refactors `InputFilterEvent.COLUMNS_CHANGED` to take an id instead of a panel. This can be a panel id or a widget id. This will allow `deephaven.ui` components to send this event. Note that more work will need to be done on Linker. This will be done later when we address https://deephaven.atlassian.net/browse/DH-18840
1 parent 2827f51 commit 8126c69

7 files changed

Lines changed: 44 additions & 25 deletions

File tree

packages/dashboard-core-plugins/src/FilterPlugin.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type DashboardPluginComponentProps,
77
LayoutUtils,
88
PanelEvent,
9+
type PanelId,
910
updateDashboardData,
1011
useListener,
1112
} from '@deephaven/dashboard';
@@ -16,6 +17,7 @@ import {
1617
DropdownFilterPanel,
1718
FilterSetManagerPanel,
1819
InputFilterPanel,
20+
type WidgetId,
1921
} from './panels';
2022

2123
const log = Log.module('FilterPlugin');
@@ -25,6 +27,9 @@ type Column = {
2527
type: string;
2628
};
2729

30+
// A panel or widget can have columns for filters
31+
export type FilterColumnSourceId = PanelId | WidgetId;
32+
2833
export type FilterChangeEvent = Column & {
2934
value: string;
3035
timestamp: number;
@@ -41,7 +46,9 @@ export function FilterPlugin(props: FilterPluginProps): JSX.Element | null {
4146
assertIsDashboardPluginProps(props);
4247
const { id: localDashboardId, layout, registerComponent } = props;
4348
const dispatch = useDispatch();
44-
const [panelColumns] = useState(() => new Map<Component, Column[]>());
49+
const [panelColumns] = useState(
50+
() => new Map<FilterColumnSourceId, Column[]>()
51+
);
4552
const [panelFilters] = useState(
4653
() => new Map<Component, FilterChangeEvent[]>()
4754
);
@@ -92,13 +99,13 @@ export function FilterPlugin(props: FilterPluginProps): JSX.Element | null {
9299

93100
/**
94101
* Handler for the COLUMNS_CHANGED event.
95-
* @param panel The component that's emitting the filter change
102+
* @param sourceId The id of the component that's emitting the filter change
96103
* @param columns The columns in this panel
97104
*/
98105
const handleColumnsChanged = useCallback(
99-
(panel: Component, columns: Column | Column[]) => {
100-
log.debug2('handleColumnsChanged', panel, columns);
101-
panelColumns.set(panel, ([] as Column[]).concat(columns));
106+
(sourceId: FilterColumnSourceId, columns: Column | Column[]) => {
107+
log.debug2('handleColumnsChanged', sourceId, columns);
108+
panelColumns.set(sourceId, ([] as Column[]).concat(columns));
102109
sendUpdate();
103110
},
104111
[panelColumns, sendUpdate]
@@ -130,9 +137,12 @@ export function FilterPlugin(props: FilterPluginProps): JSX.Element | null {
130137
const handlePanelUnmount = useCallback(
131138
panel => {
132139
log.debug2('handlePanelUnmount', panel);
133-
panelColumns.delete(panel);
140+
const panelId = LayoutUtils.getIdFromPanel(panel);
141+
if (panelId != null) {
142+
panelColumns.delete(panelId);
143+
}
134144
panelFilters.delete(panel);
135-
panelTables.delete(LayoutUtils.getIdFromPanel(panel));
145+
panelTables.delete(panelId);
136146
sendUpdate();
137147
},
138148
[panelColumns, panelFilters, panelTables, sendUpdate]

packages/dashboard-core-plugins/src/linker/Linker.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import LinkerUtils, {
4646
type LinkType,
4747
isLinkableColumn,
4848
} from './LinkerUtils';
49+
import { type FilterColumnSourceId } from '../FilterPlugin';
4950

5051
const log = Log.module('Linker');
5152

@@ -252,21 +253,24 @@ export class Linker extends Component<LinkerProps, LinkerState> {
252253
this.columnSelected(panel, column, true);
253254
}
254255

255-
handleColumnsChanged(panel: PanelComponent, columns: LinkColumn[]): void {
256-
log.debug('handleColumnsChanged', panel, columns);
256+
handleColumnsChanged(
257+
sourceId: FilterColumnSourceId,
258+
columns: LinkColumn[]
259+
): void {
260+
log.debug('handleColumnsChanged', sourceId, columns);
257261
const { links } = this.props;
258-
const panelId = LayoutUtils.getIdFromPanel(panel);
259-
if (panelId == null) {
260-
log.error('Invalid panelId', panel);
262+
if (sourceId == null) {
263+
log.error('Invalid filter columns source id', sourceId);
261264
return;
262265
}
266+
// NOTE: links need to be updated to use sourceId instead of panelId. This will be done when we implement linker for dh.ui widgets DH-18840
263267
// Delete links that start or end on non-existent column in the updated panel
264268
const linksToDelete = links.filter(
265269
({ start, end }) =>
266-
(start.panelId === panelId &&
270+
(start.panelId === sourceId &&
267271
LinkerUtils.findColumn(columns, start) == null) ||
268272
(end != null &&
269-
end.panelId === panelId &&
273+
end.panelId === sourceId &&
270274
LinkerUtils.findColumn(columns, end) == null)
271275
);
272276
this.deleteLinks(linksToDelete);

packages/dashboard-core-plugins/src/panels/ChartPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ export class ChartPanel extends Component<ChartPanelProps, ChartPanelState> {
787787
const { glEventHub } = this.props;
788788
glEventHub.emit(
789789
InputFilterEvent.COLUMNS_CHANGED,
790-
this,
790+
LayoutUtils.getIdFromPanel(this),
791791
Array.from(model.getFilterColumnMap().values())
792792
);
793793
}

packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,11 @@ export class IrisGridPanel extends PureComponent<
787787
sendColumnsChange(columns: readonly dh.Column[]): void {
788788
log.debug2('sendColumnsChange', columns);
789789
const { glEventHub } = this.props;
790-
glEventHub.emit(InputFilterEvent.COLUMNS_CHANGED, this, columns);
790+
glEventHub.emit(
791+
InputFilterEvent.COLUMNS_CHANGED,
792+
LayoutUtils.getIdFromPanel(this),
793+
columns
794+
);
791795
}
792796

793797
startModelListening(model: IrisGridModel): void {

packages/dashboard-core-plugins/src/panels/WidgetPanelTypes.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type ReactNode } from 'react';
2+
import { type Brand } from '@deephaven/utils';
23

34
export type WidgetPanelDescriptor = {
45
/** Type of the widget. */
@@ -24,3 +25,5 @@ export type WidgetPanelTooltipProps = {
2425
/** Children to render within this tooltip */
2526
children?: ReactNode;
2627
};
28+
29+
export type WidgetId = Brand<'WidgetId'>;

packages/dashboard/src/layout/LayoutUtils.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,16 @@ import type {
2121
CloseOptions,
2222
GLPanelProps,
2323
} from '@deephaven/golden-layout';
24-
import { assertNotNull } from '@deephaven/utils';
24+
import { assertNotNull, type Brand } from '@deephaven/utils';
2525
import { type DashboardLayoutConfig } from '../DashboardLayout';
2626
import { type PanelConfig } from '../DashboardPlugin';
2727

2828
const log = Log.module('LayoutUtils');
2929

3030
type LayoutConfig = { id?: string; component?: string };
3131

32+
export type PanelId = Brand<'PanelId', string | string[] | undefined>;
33+
3234
export type LayoutPanel = {
3335
props: GLPanelProps;
3436
};
@@ -818,12 +820,10 @@ class LayoutUtils {
818820
* @param glContainer The container to get the panel ID for
819821
* @returns Panel ID
820822
*/
821-
static getIdFromContainer(
822-
glContainer: Container
823-
): string | string[] | null | undefined {
823+
static getIdFromContainer(glContainer: Container): PanelId | null {
824824
const config = LayoutUtils.getComponentConfigFromContainer(glContainer);
825825
if (config) {
826-
return config.id;
826+
return config.id as PanelId;
827827
}
828828
return null;
829829
}
@@ -833,9 +833,7 @@ class LayoutUtils {
833833
* @param panel The panel to get the ID for
834834
* @returns Panel ID
835835
*/
836-
static getIdFromPanel(
837-
panel: LayoutPanel
838-
): string | string[] | null | undefined {
836+
static getIdFromPanel(panel: LayoutPanel): PanelId | null {
839837
const { glContainer } = panel.props;
840838
return LayoutUtils.getIdFromContainer(glContainer);
841839
}

packages/dashboard/src/layout/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export { default as LayoutManagerContext } from './LayoutManagerContext';
2-
export { default as LayoutUtils } from './LayoutUtils';
2+
export { default as LayoutUtils, type PanelId } from './LayoutUtils';
33
export { default as GLPropTypes } from './GLPropTypes';
44
export { default as useDashboardPanel } from './useDashboardPanel';
55
export { default as useLayoutManager } from './useLayoutManager';

0 commit comments

Comments
 (0)