d2coreui 23.0.31 → 23.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,11 +2,9 @@ import React, { ReactElement } from "react";
2
2
  import DataGrid, { DataGridFilterProps, DataGridProps, DataGridSearchProps, SortItem } from "./dataGrid";
3
3
  import { RowStyleRule } from "d2coreui/components/grid/cell/tableDefaultRowStyleRules";
4
4
  import { ColumnState, RowDataUpdatedEvent } from "ag-grid-community";
5
- import { Model } from "flexlayout-react/declarations/model/Model";
6
5
  import { DataChangeStateEnum } from "d2core/types/dataChangeStateEnum";
7
6
  export interface GridConfiguration {
8
7
  version?: number;
9
- layoutModel?: any;
10
8
  columnModel?: ColumnState[];
11
9
  pageSize: number;
12
10
  defaultPageSize?: number;
@@ -20,6 +18,8 @@ export interface GridConfiguration {
20
18
  defaultShowMilliseconds?: boolean;
21
19
  hideYear?: boolean;
22
20
  defaultHideYear?: boolean;
21
+ filterPanelWidth?: number;
22
+ detailPanelWidth?: number;
23
23
  }
24
24
  interface ExtendedDataGridSearchProps extends DataGridSearchProps {
25
25
  initialSearchHistory?: string[];
@@ -58,7 +58,6 @@ export interface ExtendedDataGridProps extends Omit<DataGridProps, "paging"> {
58
58
  updateDataDebounceInterval?: number;
59
59
  }
60
60
  interface ExtendedDataGridState {
61
- layoutModel: Model;
62
61
  gridConfiguration: GridConfiguration;
63
62
  searchString: string;
64
63
  searchHistory: string[];
@@ -66,6 +65,8 @@ interface ExtendedDataGridState {
66
65
  tableConfigVisible: boolean;
67
66
  filterChanged: boolean;
68
67
  tableNeedToBeReloaded: boolean;
68
+ sizes: (number | undefined)[];
69
+ width: number;
69
70
  }
70
71
  export default class ExtendedDataGrid<T extends {
71
72
  id: number | string;
@@ -77,10 +78,12 @@ export default class ExtendedDataGrid<T extends {
77
78
  private gridApi?;
78
79
  private dataLoaded;
79
80
  private dataTransaction;
80
- private flexLayout;
81
+ private containerRef;
82
+ private resizeObserver;
81
83
  private _updateDataDebounced;
82
84
  constructor(props: Readonly<ExtendedDataGridProps>);
83
- _getInitialLayoutModel(props: ExtendedDataGridProps): any;
85
+ componentDidMount(): void;
86
+ componentWillUnmount(): void;
84
87
  getConfiguration(): GridConfiguration;
85
88
  getSearchContext(): {
86
89
  searchString: string;
@@ -135,7 +138,7 @@ export default class ExtendedDataGrid<T extends {
135
138
  isFilterPanelVisible(): boolean;
136
139
  renderDataGrid(): ReactElement;
137
140
  private renderDataGridWithControlPanel;
138
- componentDidUpdate(): void;
139
141
  render(): React.JSX.Element;
142
+ private _onResize;
140
143
  }
141
144
  export {};
@@ -9,11 +9,9 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import React from "react";
13
- import * as FlexLayout from "flexlayout-react";
14
- import { Actions } from "flexlayout-react";
12
+ import React, { createRef } from "react";
15
13
  import { ExclamationOutlined, EyeInvisibleOutlined, EyeOutlined, FilterOutlined } from "@ant-design/icons";
16
- import { Badge, Button, Empty } from "antd";
14
+ import { Badge, Button, Splitter } from "antd";
17
15
  import DataGrid from "./dataGrid";
18
16
  import debounce from "lodash/debounce";
19
17
  import i18n from "d2core/i18n/i18n";
@@ -22,19 +20,18 @@ import isEqualWith from "lodash/isEqualWith";
22
20
  import cloneDeep from "lodash/cloneDeep";
23
21
  import tableDefaultRowStyleRules from "d2coreui/components/grid/cell/tableDefaultRowStyleRules";
24
22
  import { ColumnUtils } from "./columnUtils";
25
- const CONFIGURATION_VERSION = 1;
23
+ const CONFIGURATION_VERSION = 2;
26
24
  class ExtendedDataGrid extends React.Component {
27
25
  constructor(props) {
28
- var _a, _b, _c, _d, _e;
26
+ var _a;
29
27
  super(props);
30
- this.flexLayout = null;
28
+ this.containerRef = createRef();
29
+ this.resizeObserver = null;
31
30
  let gridConfiguration = {
32
31
  version: CONFIGURATION_VERSION,
33
32
  pageSize: 0
34
33
  };
35
34
  const gridConfigurationOk = props.defaultGridConfiguration && (!props.defaultGridConfiguration.version || props.defaultGridConfiguration.version === CONFIGURATION_VERSION);
36
- const layoutModelExists = gridConfigurationOk && !!props.defaultGridConfiguration.layoutModel;
37
- gridConfiguration.layoutModel = layoutModelExists ? props.defaultGridConfiguration.layoutModel : this._getInitialLayoutModel(props);
38
35
  gridConfiguration.columnModel = gridConfigurationOk && props.defaultGridConfiguration.columnModel ? props.defaultGridConfiguration.columnModel : undefined;
39
36
  gridConfiguration.pageSize = gridConfigurationOk && props.defaultGridConfiguration.pageSize ? props.defaultGridConfiguration.pageSize : 0;
40
37
  gridConfiguration.defaultPageSize = gridConfigurationOk && props.defaultGridConfiguration.defaultPageSize ? props.defaultGridConfiguration.defaultPageSize : undefined;
@@ -48,34 +45,24 @@ class ExtendedDataGrid extends React.Component {
48
45
  gridConfiguration.defaultShowMilliseconds = gridConfigurationOk && props.defaultGridConfiguration.defaultShowMilliseconds ? props.defaultGridConfiguration.defaultShowMilliseconds : false;
49
46
  gridConfiguration.hideYear = gridConfigurationOk && props.defaultGridConfiguration.hideYear ? props.defaultGridConfiguration.hideYear : false;
50
47
  gridConfiguration.defaultHideYear = gridConfigurationOk && props.defaultGridConfiguration.defaultHideYear ? props.defaultGridConfiguration.defaultHideYear : false;
51
- const layoutLength = (_d = (_c = (_b = (_a = gridConfiguration.layoutModel) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.children) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
52
- if (layoutLength > 0) {
53
- for (let i = 0; i < layoutLength; i++) {
54
- if (!gridConfiguration.layoutModel.layout.children[i].id) {
55
- gridConfiguration.layoutModel.layout.children[i].id = `#${(i + 1) * 2}`;
56
- }
57
- }
58
- }
48
+ gridConfiguration.filterPanelWidth = gridConfigurationOk && props.defaultGridConfiguration.filterPanelWidth
49
+ ? props.defaultGridConfiguration.filterPanelWidth
50
+ : (props.filterPanel ? (props.filterPanel.defaultWidth ? props.filterPanel.defaultWidth : 220) : 0);
51
+ gridConfiguration.detailPanelWidth = gridConfigurationOk && props.defaultGridConfiguration.detailPanelWidth ? props.defaultGridConfiguration.detailPanelWidth : 0;
59
52
  this.state = {
60
- layoutModel: FlexLayout.Model.fromJson(gridConfiguration.layoutModel),
61
53
  gridConfiguration: gridConfiguration,
62
54
  searchString: "",
63
55
  searchHistory: props.search && props.search.initialSearchHistory ? [...props.search.initialSearchHistory] : [],
64
56
  tableConfigVisible: false,
65
57
  defaultFilter: this.props.filterPanel && this.props.filterPanel.defaultFilter ? cloneDeep(this.props.filterPanel.defaultFilter) : undefined,
66
58
  filterChanged: false,
67
- tableNeedToBeReloaded: false
59
+ tableNeedToBeReloaded: false,
60
+ sizes: [gridConfiguration.filterPanelWidth, undefined, gridConfiguration.detailPanelWidth],
61
+ width: 0,
68
62
  };
69
- if (!layoutModelExists && props.filterPanel && props.filterPanel.hidden) {
70
- this.state.layoutModel.doAction(FlexLayout.Actions.updateNodeAttributes("#2", { width: 0 }));
71
- this.state.gridConfiguration.layoutModel.layout.children[0].width = 0;
72
- }
73
- if (props.detailPanel) {
74
- this.state.layoutModel.doAction(FlexLayout.Actions.updateNodeAttributes(props.filterPanel ? "#6" : "#4", { width: 0 }));
75
- }
76
63
  this.dataLoaded = false;
77
64
  this.dataTransaction = { add: [], remove: [], update: [] };
78
- const debounceInterval = (_e = props.updateDataDebounceInterval) !== null && _e !== void 0 ? _e : 500;
65
+ const debounceInterval = (_a = props.updateDataDebounceInterval) !== null && _a !== void 0 ? _a : 500;
79
66
  if (debounceInterval > 0) {
80
67
  this._updateDataDebounced = debounce(this._updateData.bind(this), debounceInterval, { maxWait: debounceInterval });
81
68
  }
@@ -97,64 +84,28 @@ class ExtendedDataGrid extends React.Component {
97
84
  this.selectNextPreviousRecord = this.selectNextPreviousRecord.bind(this);
98
85
  this._onSelectionChanged = this._onSelectionChanged.bind(this);
99
86
  this._onViewportChanged = this._onViewportChanged.bind(this);
100
- }
101
- _getInitialLayoutModel(props) {
102
- const renderFilter = props.filterPanel && props.filterPanel.renderer;
103
- const renderDetail = props.detailPanel;
104
- const layoutModel = {
105
- global: {
106
- tabSetEnableTabStrip: false,
107
- splitterSize: 4,
108
- },
109
- borders: [],
110
- layout: {
111
- "type": "row",
112
- "weight": 100,
113
- "children": [{
114
- "type": "tabset",
115
- "weight": 100,
116
- "selected": 0,
117
- "children": [
118
- {
119
- "type": "tab",
120
- "name": "Data",
121
- "component": "data-panel",
122
- }
123
- ]
124
- }]
87
+ this._onResize = this._onResize.bind(this);
88
+ }
89
+ componentDidMount() {
90
+ this.resizeObserver = new ResizeObserver((entries) => {
91
+ for (const entry of entries) {
92
+ if (entry.contentRect) {
93
+ const oldWidth = this.state.width;
94
+ const width = entry.contentRect.width;
95
+ const diff = width - oldWidth;
96
+ const [a, b, c] = this.state.sizes;
97
+ this.setState({ width: width, sizes: [a, b !== undefined ? (b + diff) : b, c] });
98
+ }
125
99
  }
126
- };
127
- if (renderFilter) {
128
- layoutModel.layout["children"].unshift({
129
- "id": "#2",
130
- "type": "tabset",
131
- "width": props.filterPanel && props.filterPanel.defaultWidth ? props.filterPanel.defaultWidth : 228,
132
- "selected": 0,
133
- "children": [
134
- {
135
- "type": "tab",
136
- "name": "Filter",
137
- "component": "filter-panel",
138
- }
139
- ]
140
- });
100
+ });
101
+ if (this.containerRef.current) {
102
+ this.resizeObserver.observe(this.containerRef.current);
141
103
  }
142
- if (renderDetail) {
143
- layoutModel.layout["children"].push({
144
- "id": props.filterPanel ? "#6" : "#4",
145
- "type": "tabset",
146
- "width": props.detailPanel ? (props.detailPanel.defaultWidth ? props.detailPanel.defaultWidth : 220) : 0,
147
- "selected": 0,
148
- "children": [
149
- {
150
- "type": "tab",
151
- "name": "Detail",
152
- "component": "detail-panel",
153
- }
154
- ]
155
- });
104
+ }
105
+ componentWillUnmount() {
106
+ if (this.resizeObserver) {
107
+ this.resizeObserver.disconnect();
156
108
  }
157
- return layoutModel;
158
109
  }
159
110
  getConfiguration() {
160
111
  return this.state.gridConfiguration;
@@ -429,19 +380,50 @@ class ExtendedDataGrid extends React.Component {
429
380
  }
430
381
  }
431
382
  showFilterPanel(show) {
383
+ var _a, _b;
384
+ const { gridConfiguration, sizes } = this.state;
385
+ const [filterPanelWidth, middleWidth, detailPanelWidth] = sizes;
432
386
  if (show) {
433
- this.state.layoutModel.doAction(FlexLayout.Actions.updateNodeAttributes("#2", { width: this.props.filterPanel && this.props.filterPanel.defaultWidth ? this.props.filterPanel.defaultWidth : 250 }));
387
+ if (filterPanelWidth === 0) {
388
+ const width = (_b = (_a = this.props.filterPanel) === null || _a === void 0 ? void 0 : _a.defaultWidth) !== null && _b !== void 0 ? _b : 250;
389
+ if (middleWidth !== undefined) {
390
+ this.setState({ sizes: [width, middleWidth - width, detailPanelWidth], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { filterPanelWidth: width }) });
391
+ }
392
+ else {
393
+ this.setState({ sizes: [width, undefined, detailPanelWidth], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { filterPanelWidth: width }) });
394
+ }
395
+ }
434
396
  }
435
397
  else {
436
- this.state.layoutModel.doAction(FlexLayout.Actions.updateNodeAttributes("#2", { width: 0 }));
398
+ if (middleWidth !== undefined && filterPanelWidth !== undefined) {
399
+ this.setState({ sizes: [0, middleWidth + filterPanelWidth, detailPanelWidth], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { filterPanelWidth: 0 }) });
400
+ }
401
+ else {
402
+ this.setState({ sizes: [0, undefined, detailPanelWidth], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { filterPanelWidth: 0 }) });
403
+ }
437
404
  }
438
405
  }
439
406
  showDetailPanel(show) {
407
+ const { gridConfiguration, sizes } = this.state;
408
+ const [filterPanelWidth, middleWidth, detailPanelWidth] = sizes;
440
409
  if (show) {
441
- this.state.layoutModel.doAction(FlexLayout.Actions.updateNodeAttributes(this.props.filterPanel ? "#6" : "#4", { width: this.props.detailPanel && this.props.detailPanel.defaultWidth ? this.props.detailPanel.defaultWidth : 250 }));
410
+ if (detailPanelWidth === 0) {
411
+ const width = this.props.detailPanel && this.props.detailPanel.defaultWidth ? this.props.detailPanel.defaultWidth : 250;
412
+ if (middleWidth !== undefined) {
413
+ this.setState({ sizes: [filterPanelWidth, middleWidth - width, width], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { detailPanelWidth: width }) });
414
+ }
415
+ else {
416
+ this.setState({ sizes: [filterPanelWidth, undefined, width], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { detailPanelWidth: width }) });
417
+ }
418
+ }
442
419
  }
443
420
  else {
444
- this.state.layoutModel.doAction(FlexLayout.Actions.updateNodeAttributes(this.props.filterPanel ? "#6" : "#4", { width: 0 }));
421
+ if (middleWidth !== undefined && detailPanelWidth !== undefined) {
422
+ this.setState({ sizes: [filterPanelWidth, middleWidth + detailPanelWidth, 0], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { detailPanelWidth: 0 }) });
423
+ }
424
+ else {
425
+ this.setState({ sizes: [filterPanelWidth, undefined, 0], gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { detailPanelWidth: 0 }) });
426
+ }
445
427
  }
446
428
  }
447
429
  selectNextPreviousRecord(previous) {
@@ -566,7 +548,8 @@ class ExtendedDataGrid extends React.Component {
566
548
  return undefined;
567
549
  }
568
550
  isFilterPanelVisible() {
569
- return this.state.gridConfiguration.layoutModel ? this.state.gridConfiguration.layoutModel.layout.children[0].width > 0 : true;
551
+ var _a;
552
+ return ((_a = this.state.gridConfiguration.filterPanelWidth) !== null && _a !== void 0 ? _a : 0) > 0;
570
553
  }
571
554
  renderDataGrid() {
572
555
  const _a = this.props, { defaultGridConfiguration, onGridReady, onLoadData, onSortChanged, onColumnsChanged, onSelectionChanged, onViewportChanged, onTableConfigVisible, toolbar, paging, filter, search, onChangeConfiguration, onDataChanged, onChangeRowStyleRules, filterPanel, controlPanel, detailPanel } = _a, rest = __rest(_a, ["defaultGridConfiguration", "onGridReady", "onLoadData", "onSortChanged", "onColumnsChanged", "onSelectionChanged", "onViewportChanged", "onTableConfigVisible", "toolbar", "paging", "filter", "search", "onChangeConfiguration", "onDataChanged", "onChangeRowStyleRules", "filterPanel", "controlPanel", "detailPanel"]);
@@ -642,62 +625,27 @@ class ExtendedDataGrid extends React.Component {
642
625
  height: "100%",
643
626
  width: "100%"
644
627
  } },
645
- React.createElement("div", { key: "table-with-control-panel-wrapper", style: { flex: "1 1 auto", overflow: "auto" } }, this.renderDataGrid()),
628
+ React.createElement("div", { key: "table-with-control-panel-wrapper", style: { flex: "1 1 auto", overflow: "hidden" } }, this.renderDataGrid()),
646
629
  this.props.controlPanel.renderer()));
647
630
  }
648
631
  return this.renderDataGrid();
649
632
  }
650
- componentDidUpdate() {
651
- var _a;
652
- (_a = this.flexLayout) === null || _a === void 0 ? void 0 : _a.updateRect();
653
- }
654
633
  render() {
655
634
  const { filterPanel, detailPanel } = this.props;
656
- if (filterPanel || detailPanel) {
657
- return (React.createElement(FlexLayout.Layout, { ref: (flexLayout) => {
658
- this.flexLayout = flexLayout;
659
- }, model: this.state.layoutModel, onModelChange: (model) => {
660
- this._changeConfiguration({ layoutModel: model.toJson() });
661
- }, onAction: (action) => {
662
- var _a;
663
- const node1 = action.data.node1;
664
- const node2 = action.data.node2;
665
- let tabset;
666
- if (action.type === Actions.ADJUST_SPLIT) {
667
- if (node1 === "#4" && node2 === "#6") {
668
- tabset = this.state.layoutModel.getNodeById('#6');
669
- }
670
- else if (node1 === "#2" && node2 === "#4") {
671
- tabset = this.state.layoutModel.getNodeById('#2');
672
- }
673
- if (tabset) {
674
- const width = (_a = tabset === null || tabset === void 0 ? void 0 : tabset._attributes) === null || _a === void 0 ? void 0 : _a.width;
675
- if (width === 0) {
676
- return undefined;
677
- }
678
- }
679
- }
680
- return action;
681
- }, factory: (node) => {
682
- const component = node.getComponent();
683
- if (component === "filter-panel") {
684
- return filterPanel && filterPanel.renderer && filterPanel.renderer({
685
- defaultFilter: this.state.defaultFilter,
686
- filterChanged: this.state.filterChanged
687
- });
688
- }
689
- else if (component === "data-panel") {
690
- return this.renderDataGridWithControlPanel();
691
- }
692
- else if (component === "detail-panel") {
693
- return detailPanel && detailPanel.renderer();
694
- }
695
- return React.createElement(Empty, null);
696
- } }));
697
- }
698
- else {
699
- return this.renderDataGridWithControlPanel();
700
- }
635
+ const { sizes } = this.state;
636
+ const [filterPanelWidth, middleWidth, detailPanelWidth] = sizes;
637
+ return (React.createElement("div", { ref: this.containerRef },
638
+ React.createElement(Splitter, { lazy: true, style: { overflow: "hidden", position: "absolute", inset: 0 }, onCollapse: (_, sizes) => this._onResize(sizes), onResize: this._onResize, onResizeEnd: this._onResize },
639
+ React.createElement(Splitter.Panel, { resizable: (filterPanelWidth !== null && filterPanelWidth !== void 0 ? filterPanelWidth : 0) > 0, collapsible: { end: (filterPanelWidth !== null && filterPanelWidth !== void 0 ? filterPanelWidth : 0) > 0 }, size: filterPanelWidth }, (filterPanel === null || filterPanel === void 0 ? void 0 : filterPanel.renderer) && (filterPanel === null || filterPanel === void 0 ? void 0 : filterPanel.renderer({
640
+ defaultFilter: this.state.defaultFilter,
641
+ filterChanged: this.state.filterChanged
642
+ }))),
643
+ React.createElement(Splitter.Panel, { size: middleWidth }, this.renderDataGridWithControlPanel()),
644
+ React.createElement(Splitter.Panel, { resizable: (detailPanelWidth !== null && detailPanelWidth !== void 0 ? detailPanelWidth : 0) > 0, collapsible: { start: (detailPanelWidth !== null && detailPanelWidth !== void 0 ? detailPanelWidth : 0) > 0 }, size: detailPanelWidth }, detailPanel && detailPanel.renderer()))));
645
+ }
646
+ _onResize(sizes) {
647
+ const { gridConfiguration } = this.state;
648
+ this.setState({ sizes: sizes, gridConfiguration: Object.assign(Object.assign({}, gridConfiguration), { filterPanelWidth: sizes[0], detailPanelWidth: sizes[2] }) });
701
649
  }
702
650
  }
703
651
  ExtendedDataGrid.defaultProps = {