Skip to content

Commit 588cb8f

Browse files
authored
feat: De-globalize JSAPI in IrisGrid package (#1262)
- De-globalize JSAPI in the IrisGrid package. - De-globalize JSAPI in `DateUtils` and `TableUtils` in the`jsapi-utils` package. - Update `dashboard-core-plugins`, `code-studio`, embed-grid` to match the IrisGrid package changes. BREAKING CHANGE: - `DateUtils` static methods `makeDateWrapper`, `getNextDate `, `parseDateRange` now require the JSAPI object as the first argument. - `IrisGridUtils` static methods `dehydrateIrisGridState`, `hydrateIrisGridState`, `hydrateQuickFilters`, `dehydrateAdvancedFilters`, `hydrateAdvancedFilters`, `dehydrateAdvancedFilterOptions`, `hydrateAdvancedFilterOptions`, `dehydratePendingDataMap`, `hydratePendingDataMap`, `dehydrateValue`, `hydrateValue`, `dehydrateDateTime`, `hydrateDateTime`, `hydrateLong`, `hydrateSort`, `applyTableSettings`, `getFiltersFromInputFilters`, `rangeSetFromRanges` converted to instance methods. Consumers now need to create an `IrisGridUtils` instance and pass the JSAPI object to the constructor. - `TableUtils` static methods `makeQuickFilter`, `makeQuickFilterFromComponent`, `makeQuickNumberFilter`, `makeQuickTextFilter`, `makeQuickBooleanFilter`, `makeQuickDateFilter`, `makeQuickDateFilterWithOperation`, `makeQuickCharFilter`, `makeAdvancedFilter`, `makeAdvancedValueFilter`, `makeFilterValue`, `makeFilterRawValue`, `makeValue`, `makeSelectValueFilter` converted to instance methods. Consumers now need to create a `TableUtils` instance and pass the JSAPI object to the constructor. - `IrisGridTableModel`, `IrisGridTableModelTemplate`, `IrisGridProxyModel` constructors require the JSAPI object in the first argument. - `IrisGridTestUtils.makeModel`, `IrisGridModelFactory.makeModel` now require the JSAPI object in the first argument. - `IrisGridContextMenuHandler` constructor requires the JSAPI object in the second argument. - `IrisGridPanel` requires a new `makeApi` prop, a function that resolves with the JSAPI instance. - `CrossColumnSearch.createSearchFilter` requires the JSAPI object argument. - Components `AdvancedFilterCreatorSelectValue`, `AdvancedFilterCreatorSelectValueList`, `ChartBuilder`, `GotoRow`, `IrisGrid`, `IrisGridModelUpdater`, `IrisGridPartitionSelector`, `PartitionSelectorSearch`, `TableCSVExporter`, `TableSaver`, `TreeTableViewportUpdater`, `RowFormatEditor`, `ColumnFormatEditor`, `ConditionEditor` now require the JSAPI object passed in the new prop `dh`. - Components `AdvancedFilterCreator`, `AdvancedFilterCreatorFilterItem` require the `TableUtils` instance pass in the new prop `tableUtils`. - `ConditionalFormattingUtils` static methods `getFormatColumns`, `isDateConditionValid` require the JSAPI object in the first argument. - `ConditionalFormattingAPIUtils` static method `makeRowFormatColumn` requires the JSAPI object in the first argument.
1 parent 87fa2ef commit 588cb8f

74 files changed

Lines changed: 2254 additions & 2027 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/code-studio/src/main/AppMainContainer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,8 @@ export class AppMainContainer extends Component<
755755
getDownloadWorker: DownloadServiceWorkerUtils.getServiceWorker,
756756
loadPlugin: this.handleLoadTablePlugin,
757757
localDashboardId: id,
758-
makeModel: () => createGridModel(connection, props.metadata, type),
758+
makeApi: () => Promise.resolve(dh),
759+
makeModel: () => createGridModel(dh, connection, props.metadata, type),
759760
};
760761
}
761762

@@ -767,7 +768,7 @@ export class AppMainContainer extends Component<
767768
makeApi: () => Promise.resolve(dh),
768769
makeModel: () => {
769770
const { metadata, panelState } = props;
770-
return createChartModel(connection, metadata, panelState);
771+
return createChartModel(dh, connection, metadata, panelState);
771772
},
772773
};
773774
}

packages/code-studio/src/main/WidgetUtils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ChartModel, ChartModelFactory } from '@deephaven/chart';
2-
import dh, {
2+
import {
3+
dh as DhType,
34
Table,
45
VariableTypeUnion,
56
IdeConnection,
6-
} from '@deephaven/jsapi-shim';
7+
} from '@deephaven/jsapi-types';
78
import {
89
IrisGridModel,
910
IrisGridModelFactory,
@@ -21,6 +22,7 @@ export type GridPanelMetadata = {
2122
};
2223

2324
export const createChartModel = async (
25+
dh: DhType,
2426
connection: IdeConnection,
2527
metadata: ChartPanelMetadata,
2628
panelState?: GLChartPanelState
@@ -76,8 +78,7 @@ export const createChartModel = async (
7678
type: dh.VariableType.TABLE,
7779
};
7880
const table = await connection.getObject(definition);
79-
80-
IrisGridUtils.applyTableSettings(
81+
new IrisGridUtils(dh).applyTableSettings(
8182
table,
8283
tableSettings,
8384
getTimeZone(store.getState())
@@ -88,14 +89,15 @@ export const createChartModel = async (
8889
};
8990

9091
export const createGridModel = async (
92+
dh: DhType,
9193
connection: IdeConnection,
9294
metadata: GridPanelMetadata,
9395
type: VariableTypeUnion = dh.VariableType.TABLE
9496
): Promise<IrisGridModel> => {
9597
const { table: tableName } = metadata;
9698
const definition = { title: tableName, name: tableName, type };
9799
const table = (await connection.getObject(definition)) as Table;
98-
return IrisGridModelFactory.makeModel(table);
100+
return IrisGridModelFactory.makeModel(dh, table);
99101
};
100102

101103
export default { createChartModel, createGridModel };
Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,44 @@
1-
import React, { PureComponent } from 'react';
1+
import React, { ReactElement, useState } from 'react';
22
import {
33
Grid,
4+
GridThemeType,
45
MockGridModel,
56
MockTreeGridModel,
67
ThemeContext,
7-
GridThemeType,
88
} from '@deephaven/grid';
99
import { IrisGrid } from '@deephaven/iris-grid';
10+
import { useApi } from '@deephaven/jsapi-bootstrap';
1011
import MockIrisGridTreeModel from './MockIrisGridTreeModel';
1112
import StaticExample from './grid-examples/StaticExample';
1213
import QuadrillionExample from './grid-examples/QuadrillionExample';
1314
import TreeExample from './grid-examples/TreeExample';
1415
import AsyncExample from './grid-examples/AsyncExample';
1516
import DataBarExample from './grid-examples/DataBarExample';
1617

17-
type GridsState = {
18-
irisGridModel: MockIrisGridTreeModel;
19-
model: MockGridModel;
20-
theme: Partial<GridThemeType>;
21-
contextTheme: Partial<GridThemeType>;
22-
};
23-
24-
class Grids extends PureComponent<Record<string, never>, GridsState> {
25-
constructor(props: Record<string, never>) {
26-
super(props);
27-
28-
this.state = {
29-
irisGridModel: new MockIrisGridTreeModel(new MockTreeGridModel()),
30-
model: new MockGridModel(),
31-
theme: { autoSelectRow: true },
32-
contextTheme: { rowHeight: 40 },
33-
};
34-
}
18+
function Grids(): ReactElement {
19+
const [irisGridModel] = useState(
20+
new MockIrisGridTreeModel(new MockTreeGridModel())
21+
);
22+
const [model] = useState(new MockGridModel());
23+
const [theme] = useState<Partial<GridThemeType>>({ autoSelectRow: true });
24+
const [contextTheme] = useState<Partial<GridThemeType>>({ rowHeight: 40 });
25+
const dh = useApi();
3526

36-
render(): React.ReactElement {
37-
const { contextTheme, irisGridModel, model, theme } = this.state;
38-
39-
return (
40-
<div>
41-
<ThemeContext.Provider value={contextTheme}>
42-
<h2 className="ui-title">Grid</h2>
43-
<div>
44-
<Grid model={model} theme={theme} />
45-
</div>
46-
<h2 className="ui-title">Static Data</h2>
47-
<div style={{ height: 200 }}>
48-
<StaticExample />
49-
</div>
50-
</ThemeContext.Provider>
27+
return (
28+
<div>
29+
<ThemeContext.Provider value={contextTheme}>
30+
<h2 className="ui-title">Grid</h2>
31+
<div>
32+
<Grid model={model} theme={theme} />
33+
</div>
34+
<h2 className="ui-title">Static Data</h2>
35+
<div style={{ height: 200 }}>
36+
<StaticExample />
37+
</div>
38+
<h2 className="ui-title">Data Bar</h2>
39+
<div style={{ height: 500 }}>
40+
<DataBarExample />
41+
</div>
5142
<h2 className="ui-title">Quadrillion rows and columns</h2>
5243
<div style={{ height: 500, position: 'relative' }}>
5344
<QuadrillionExample />
@@ -62,15 +53,11 @@ class Grids extends PureComponent<Record<string, never>, GridsState> {
6253
</div>
6354
<h2 className="ui-title">Iris Grid</h2>
6455
<div style={{ height: 500 }}>
65-
<IrisGrid model={irisGridModel} />
66-
</div>
67-
<h2 className="ui-title">Data Bar</h2>
68-
<div style={{ height: 500 }}>
69-
<DataBarExample />
56+
<IrisGrid dh={dh} model={irisGridModel} />
7057
</div>
71-
</div>
72-
);
73-
}
58+
</ThemeContext.Provider>
59+
</div>
60+
);
7461
}
7562

7663
export default Grids;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ export function GridPlugin(props: GridPluginProps): JSX.Element | null {
5454
}
5555

5656
const metadata = { name, table: name, type: widget.type };
57+
const makeApi = () => Promise.resolve(dh);
5758
const makeModel = () =>
58-
fetch().then((table: Table) => IrisGridModelFactory.makeModel(table));
59+
fetch().then((table: Table) =>
60+
IrisGridModelFactory.makeModel(dh, table)
61+
);
5962
const config = {
6063
type: 'react-component' as const,
6164
component: IrisGridPanel.COMPONENT,
@@ -65,6 +68,7 @@ export function GridPlugin(props: GridPluginProps): JSX.Element | null {
6568
localDashboardId: id,
6669
id: panelId,
6770
metadata,
71+
makeApi,
6872
makeModel,
6973
theme,
7074
},

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
useListener,
99
} from '@deephaven/dashboard';
1010
import { IrisGridModelFactory } from '@deephaven/iris-grid';
11-
import { Table } from '@deephaven/jsapi-shim';
11+
import type { Table } from '@deephaven/jsapi-types';
1212
import shortid from 'shortid';
1313
import { PandasPanel, PandasPanelProps } from './panels';
1414

@@ -29,7 +29,9 @@ export function PandasPlugin(props: PandasPluginProps): JSX.Element | null {
2929

3030
const metadata = { name, table: name };
3131
const makeModel = () =>
32-
fetch().then((table: Table) => IrisGridModelFactory.makeModel(table));
32+
fetch().then((table: Table) =>
33+
IrisGridModelFactory.makeModel(dh, table)
34+
);
3335
const config = {
3436
type: 'react-component' as const,
3537
component: PandasPanel.COMPONENT,

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,19 @@ function makeGlComponent() {
4444
}
4545

4646
function makeMakeModel(table = makeTable()) {
47-
return () => Promise.resolve(table).then(IrisGridModelFactory.makeModel);
47+
return () =>
48+
Promise.resolve(table).then(resolved =>
49+
IrisGridModelFactory.makeModel(dh, resolved)
50+
);
51+
}
52+
53+
function makeMakeApi() {
54+
return () => dh;
4855
}
4956

5057
function makeIrisGridPanelWrapper(
5158
makeModel = makeMakeModel(),
59+
makeApi = makeMakeApi(),
5260
metadata = { table: 'table' },
5361
glContainer = makeGlComponent(),
5462
glEventHub = makeGlComponent(),
@@ -61,6 +69,7 @@ function makeIrisGridPanelWrapper(
6169
) {
6270
return render(
6371
<IrisGridPanel
72+
makeApi={makeApi}
6473
makeModel={makeModel}
6574
metadata={metadata}
6675
glContainer={(glContainer as unknown) as Container}

0 commit comments

Comments
 (0)