@perses-dev/table-plugin 0.13.0 → 0.14.0-beta.1
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.
- package/__mf/js/{Table.73b9cec1.js → Table.646f97de.js} +3 -3
- package/__mf/js/async/11.976870d0.js +7 -0
- package/__mf/js/async/11.976870d0.js.LICENSE.txt +102 -0
- package/__mf/js/async/121.b3a4c6cf.js +2 -0
- package/__mf/js/async/153.fa68a9e4.js +1 -0
- package/__mf/js/async/186.ab1e0cb3.js +2 -0
- package/__mf/js/async/192.942516a2.js +1 -0
- package/__mf/js/async/2.6b27d33f.js +1 -0
- package/__mf/js/async/235.c5bac291.js +1 -0
- package/__mf/js/async/274.f7dabfa6.js +2 -0
- package/__mf/js/async/321.96f362a6.js +1 -0
- package/__mf/js/async/35.ba7c1b06.js +1 -0
- package/__mf/js/async/356.d7fe5d24.js +1 -0
- package/__mf/js/async/392.e853a818.js +2 -0
- package/__mf/js/async/413.d44db4b1.js +1 -0
- package/__mf/js/async/465.8425c17a.js +1 -0
- package/__mf/js/async/470.21434f20.js +2 -0
- package/__mf/js/async/522.d6a7c203.js +22 -0
- package/__mf/js/async/534.aff242e9.js +1 -0
- package/__mf/js/async/54.e77ec040.js +1 -0
- package/__mf/js/async/587.0ff26337.js +1 -0
- package/__mf/js/async/616.4e891cf9.js +1 -0
- package/__mf/js/async/663.b3778d4c.js +1 -0
- package/__mf/js/async/700.ccacc909.js +3 -0
- package/__mf/js/async/{868.507e984c.js → 741.7feaa0ba.js} +6 -6
- package/__mf/js/async/862.4c658639.js +2 -0
- package/__mf/js/async/865.b9eb3de4.js +1 -0
- package/__mf/js/async/923.87e55609.js +1 -0
- package/__mf/js/async/941.08c16cb2.js +2 -0
- package/__mf/js/async/968.b7fe9818.js +1 -0
- package/__mf/js/async/985.6129a36c.js +37 -0
- package/__mf/js/async/__federation_expose_Table.f8d0feb7.js +1 -0
- package/__mf/js/async/lib-router.020a2a16.js +2 -0
- package/__mf/js/{main.7b15c841.js → main.276cd542.js} +2 -2
- package/lib/Table.d.ts +3 -3
- package/lib/Table.d.ts.map +1 -1
- package/lib/Table.js +4 -4
- package/lib/Table.js.map +1 -1
- package/lib/TableExportAction.d.ts +3 -3
- package/lib/TableExportAction.d.ts.map +1 -1
- package/lib/TableExportAction.js +6 -6
- package/lib/TableExportAction.js.map +1 -1
- package/lib/bootstrap.js +2 -2
- package/lib/components/CellsEditor/CellsEditor.d.ts +2 -2
- package/lib/components/CellsEditor/CellsEditor.d.ts.map +1 -1
- package/lib/components/CellsEditor/CellsEditor.js +1 -1
- package/lib/components/CellsEditor/CellsEditor.js.map +1 -1
- package/lib/components/CellsEditor/index.js +1 -1
- package/lib/components/CellsEditor/index.js.map +1 -1
- package/lib/components/ColumnsEditor/ColumnEditor.d.ts +5 -4
- package/lib/components/ColumnsEditor/ColumnEditor.d.ts.map +1 -1
- package/lib/components/ColumnsEditor/ColumnEditor.js +29 -15
- package/lib/components/ColumnsEditor/ColumnEditor.js.map +1 -1
- package/lib/components/ColumnsEditor/ColumnEditorContainer.d.ts +3 -3
- package/lib/components/ColumnsEditor/ColumnEditorContainer.d.ts.map +1 -1
- package/lib/components/ColumnsEditor/ColumnEditorContainer.js +11 -10
- package/lib/components/ColumnsEditor/ColumnEditorContainer.js.map +1 -1
- package/lib/components/ColumnsEditor/ColumnsEditor.d.ts +4 -3
- package/lib/components/ColumnsEditor/ColumnsEditor.d.ts.map +1 -1
- package/lib/components/ColumnsEditor/ColumnsEditor.js +7 -6
- package/lib/components/ColumnsEditor/ColumnsEditor.js.map +1 -1
- package/lib/components/ColumnsEditor/DataLinkEditorDialog.d.ts +2 -2
- package/lib/components/ColumnsEditor/DataLinkEditorDialog.d.ts.map +1 -1
- package/lib/components/ColumnsEditor/DataLinkEditorDialog.js +4 -4
- package/lib/components/ColumnsEditor/DataLinkEditorDialog.js.map +1 -1
- package/lib/components/ColumnsEditor/EmbeddedPanelOptionsEditor.d.ts +2 -2
- package/lib/components/ColumnsEditor/EmbeddedPanelOptionsEditor.d.ts.map +1 -1
- package/lib/components/ColumnsEditor/EmbeddedPanelOptionsEditor.js +4 -4
- package/lib/components/ColumnsEditor/EmbeddedPanelOptionsEditor.js.map +1 -1
- package/lib/components/ColumnsEditor/index.js +3 -3
- package/lib/components/ColumnsEditor/index.js.map +1 -1
- package/lib/components/ConditionalPanel.d.ts +3 -3
- package/lib/components/ConditionalPanel.d.ts.map +1 -1
- package/lib/components/ConditionalPanel.js +7 -7
- package/lib/components/ConditionalPanel.js.map +1 -1
- package/lib/components/EmbeddedPanel.d.ts +3 -3
- package/lib/components/EmbeddedPanel.d.ts.map +1 -1
- package/lib/components/EmbeddedPanel.js +4 -4
- package/lib/components/EmbeddedPanel.js.map +1 -1
- package/lib/components/TableCellsEditor.d.ts +3 -3
- package/lib/components/TableCellsEditor.d.ts.map +1 -1
- package/lib/components/TableCellsEditor.js +1 -1
- package/lib/components/TableCellsEditor.js.map +1 -1
- package/lib/components/TableColumnsEditor.d.ts +3 -3
- package/lib/components/TableColumnsEditor.d.ts.map +1 -1
- package/lib/components/TableColumnsEditor.js +3 -2
- package/lib/components/TableColumnsEditor.js.map +1 -1
- package/lib/components/TableItemSelectionActionsEditor.d.ts +2 -2
- package/lib/components/TableItemSelectionActionsEditor.d.ts.map +1 -1
- package/lib/components/TableItemSelectionActionsEditor.js +2 -2
- package/lib/components/TableItemSelectionActionsEditor.js.map +1 -1
- package/lib/components/TablePanel.d.ts +4 -4
- package/lib/components/TablePanel.d.ts.map +1 -1
- package/lib/components/TablePanel.js +196 -99
- package/lib/components/TablePanel.js.map +1 -1
- package/lib/components/TableSettingsEditor.d.ts +2 -2
- package/lib/components/TableSettingsEditor.d.ts.map +1 -1
- package/lib/components/TableSettingsEditor.js +16 -2
- package/lib/components/TableSettingsEditor.js.map +1 -1
- package/lib/components/TableTransformsEditor.d.ts +2 -2
- package/lib/components/TableTransformsEditor.d.ts.map +1 -1
- package/lib/components/TableTransformsEditor.js +2 -2
- package/lib/components/TableTransformsEditor.js.map +1 -1
- package/lib/components/index.js +9 -9
- package/lib/components/index.js.map +1 -1
- package/lib/getPluginModule.d.ts +1 -1
- package/lib/getPluginModule.d.ts.map +1 -1
- package/lib/getPluginModule.js +3 -1
- package/lib/getPluginModule.js.map +1 -1
- package/lib/index-federation.js +1 -1
- package/lib/index.js +4 -4
- package/lib/index.js.map +1 -1
- package/lib/models/index.js +2 -2
- package/lib/models/index.js.map +1 -1
- package/lib/models/model.d.ts +1 -1
- package/lib/models/model.d.ts.map +1 -1
- package/lib/models/model.js.map +1 -1
- package/lib/models/table-model.d.ts +4 -3
- package/lib/models/table-model.d.ts.map +1 -1
- package/lib/models/table-model.js +2 -2
- package/lib/models/table-model.js.map +1 -1
- package/lib/setup-tests.d.ts +1 -1
- package/lib/setup-tests.d.ts.map +1 -1
- package/lib/setup-tests.js +8 -2
- package/lib/setup-tests.js.map +1 -1
- package/lib/table-data-utils.d.ts +3 -3
- package/lib/table-data-utils.d.ts.map +1 -1
- package/lib/table-data-utils.js.map +1 -1
- package/lib/test/mock-query-results.d.ts +1 -1
- package/lib/test/mock-query-results.d.ts.map +1 -1
- package/lib/test/mock-query-results.js.map +1 -1
- package/mf-manifest.json +42 -84
- package/mf-stats.json +46 -93
- package/package.json +11 -11
- package/__mf/js/async/1432.4e515509.js +0 -1
- package/__mf/js/async/1589.124ce93d.js +0 -2
- package/__mf/js/async/1589.124ce93d.js.LICENSE.txt +0 -37
- package/__mf/js/async/1616.4828085d.js +0 -1
- package/__mf/js/async/2043.1f09864b.js +0 -2
- package/__mf/js/async/2043.1f09864b.js.LICENSE.txt +0 -24
- package/__mf/js/async/2082.231e8397.js +0 -1
- package/__mf/js/async/2842.a52597e6.js +0 -1
- package/__mf/js/async/392.b6035b41.js +0 -2
- package/__mf/js/async/3981.52e94742.js +0 -3
- package/__mf/js/async/4014.cf88a118.js +0 -7
- package/__mf/js/async/4014.cf88a118.js.LICENSE.txt +0 -39
- package/__mf/js/async/4121.e7df36d6.js +0 -2
- package/__mf/js/async/5002.3eb39a8c.js +0 -1
- package/__mf/js/async/5021.c663603d.js +0 -1
- package/__mf/js/async/5071.839a8f1a.js +0 -1
- package/__mf/js/async/5481.6496fac9.js +0 -2
- package/__mf/js/async/5587.a8a428db.js +0 -1
- package/__mf/js/async/6274.8edae86d.js +0 -2
- package/__mf/js/async/629.8cff215d.js +0 -1
- package/__mf/js/async/6811.9d4b123a.js +0 -38
- package/__mf/js/async/7177.e0e5ba2f.js +0 -1
- package/__mf/js/async/7192.692181c8.js +0 -1
- package/__mf/js/async/7413.c9310b8a.js +0 -1
- package/__mf/js/async/7968.3a9a982e.js +0 -1
- package/__mf/js/async/7978.116e4d81.js +0 -1
- package/__mf/js/async/7984.a8edc213.js +0 -22
- package/__mf/js/async/8356.152d5686.js +0 -1
- package/__mf/js/async/8470.b9762117.js +0 -2
- package/__mf/js/async/873.264fedc9.js +0 -1
- package/__mf/js/async/9051.c4deebd7.js +0 -1
- package/__mf/js/async/9235.c67cdb1d.js +0 -1
- package/__mf/js/async/941.cc458a98.js +0 -2
- package/__mf/js/async/9588.d23e2ed3.js +0 -1
- package/__mf/js/async/9701.9c4cea02.js +0 -1
- package/__mf/js/async/__federation_expose_Table.5d0cfb46.js +0 -1
- package/__mf/js/async/lib-router.3493bbf9.js +0 -2
- package/lib/cjs/Table.js +0 -62
- package/lib/cjs/TableExportAction.js +0 -180
- package/lib/cjs/bootstrap.js +0 -26
- package/lib/cjs/components/CellsEditor/CellsEditor.js +0 -30
- package/lib/cjs/components/CellsEditor/index.js +0 -30
- package/lib/cjs/components/ColumnsEditor/ColumnEditor.js +0 -289
- package/lib/cjs/components/ColumnsEditor/ColumnEditorContainer.js +0 -152
- package/lib/cjs/components/ColumnsEditor/ColumnsEditor.js +0 -108
- package/lib/cjs/components/ColumnsEditor/DataLinkEditorDialog.js +0 -139
- package/lib/cjs/components/ColumnsEditor/EmbeddedPanelOptionsEditor.js +0 -124
- package/lib/cjs/components/ColumnsEditor/index.js +0 -32
- package/lib/cjs/components/ConditionalPanel.js +0 -367
- package/lib/cjs/components/EmbeddedPanel.js +0 -52
- package/lib/cjs/components/TableCellsEditor.js +0 -36
- package/lib/cjs/components/TableColumnsEditor.js +0 -36
- package/lib/cjs/components/TableItemSelectionActionsEditor.js +0 -44
- package/lib/cjs/components/TablePanel.js +0 -845
- package/lib/cjs/components/TableSettingsEditor.js +0 -144
- package/lib/cjs/components/TableTransformsEditor.js +0 -36
- package/lib/cjs/components/index.js +0 -38
- package/lib/cjs/env.d.js +0 -14
- package/lib/cjs/getPluginModule.js +0 -39
- package/lib/cjs/index-federation.js +0 -55
- package/lib/cjs/index.js +0 -39
- package/lib/cjs/models/index.js +0 -31
- package/lib/cjs/models/model.js +0 -16
- package/lib/cjs/models/table-model.js +0 -278
- package/lib/cjs/setup-tests.js +0 -19
- package/lib/cjs/table-data-utils.js +0 -84
- package/lib/cjs/test/mock-query-results.js +0 -524
- /package/__mf/css/async/{4014.85c2cbf6.css → 11.85c2cbf6.css} +0 -0
- /package/__mf/js/async/{4121.e7df36d6.js.LICENSE.txt → 121.b3a4c6cf.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6274.8edae86d.js.LICENSE.txt → 274.f7dabfa6.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.b6035b41.js.LICENSE.txt → 392.e853a818.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{8470.b9762117.js.LICENSE.txt → 470.21434f20.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{7984.a8edc213.js.LICENSE.txt → 522.d6a7c203.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{868.507e984c.js.LICENSE.txt → 741.7feaa0ba.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5481.6496fac9.js.LICENSE.txt → 862.4c658639.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{941.cc458a98.js.LICENSE.txt → 941.08c16cb2.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{lib-router.3493bbf9.js.LICENSE.txt → lib-router.020a2a16.js.LICENSE.txt} +0 -0
|
@@ -1,845 +0,0 @@
|
|
|
1
|
-
// Copyright The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
"use strict";
|
|
14
|
-
Object.defineProperty(exports, "__esModule", {
|
|
15
|
-
value: true
|
|
16
|
-
});
|
|
17
|
-
function _export(target, all) {
|
|
18
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
_export(exports, {
|
|
24
|
-
get TablePanel () {
|
|
25
|
-
return TablePanel;
|
|
26
|
-
},
|
|
27
|
-
get getTablePanelQueryOptions () {
|
|
28
|
-
return getTablePanelQueryOptions;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
const _jsxruntime = require("react/jsx-runtime");
|
|
32
|
-
const _material = require("@mui/material");
|
|
33
|
-
const _components = require("@perses-dev/components");
|
|
34
|
-
const _dashboards = require("@perses-dev/dashboards");
|
|
35
|
-
const _pluginsystem = require("@perses-dev/plugin-system");
|
|
36
|
-
const _react = require("react");
|
|
37
|
-
const _models = require("../models");
|
|
38
|
-
const _tabledatautils = require("../table-data-utils");
|
|
39
|
-
const _EmbeddedPanel = require("./EmbeddedPanel");
|
|
40
|
-
function parseNumericCellValue(value) {
|
|
41
|
-
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
if (typeof value === 'string') {
|
|
45
|
-
const parsed = Number(value);
|
|
46
|
-
if (Number.isFinite(parsed)) {
|
|
47
|
-
return parsed;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
function isPanelData(value) {
|
|
53
|
-
if (typeof value !== 'object' || value === null) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const candidate = value;
|
|
57
|
-
return candidate.definition !== undefined && candidate.data !== undefined;
|
|
58
|
-
}
|
|
59
|
-
function createSyntheticPanelData(value, columnName) {
|
|
60
|
-
const numericValue = parseNumericCellValue(value);
|
|
61
|
-
if (numericValue === undefined) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
const now = Date.now();
|
|
65
|
-
return {
|
|
66
|
-
definition: {
|
|
67
|
-
kind: 'TimeSeriesQuery',
|
|
68
|
-
spec: {
|
|
69
|
-
plugin: {
|
|
70
|
-
kind: 'PrometheusTimeSeriesQuery',
|
|
71
|
-
spec: {
|
|
72
|
-
query: ''
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
data: {
|
|
78
|
-
timeRange: {
|
|
79
|
-
start: new Date(now),
|
|
80
|
-
end: new Date(now)
|
|
81
|
-
},
|
|
82
|
-
stepMs: 1,
|
|
83
|
-
series: [
|
|
84
|
-
{
|
|
85
|
-
name: columnName,
|
|
86
|
-
values: [
|
|
87
|
-
[
|
|
88
|
-
now,
|
|
89
|
-
numericValue
|
|
90
|
-
]
|
|
91
|
-
],
|
|
92
|
-
labels: {}
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function getGaugeNumericValue(value) {
|
|
99
|
-
if (isPanelData(value)) {
|
|
100
|
-
const series = value.data?.series;
|
|
101
|
-
const firstSeries = series?.[0];
|
|
102
|
-
if (!firstSeries?.values?.length) {
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
const calc = _pluginsystem.CalculationsMap['last-number'];
|
|
106
|
-
if (typeof calc !== 'function') {
|
|
107
|
-
return undefined;
|
|
108
|
-
}
|
|
109
|
-
const calculatedValue = calc(firstSeries.values);
|
|
110
|
-
return typeof calculatedValue === 'number' ? calculatedValue : undefined;
|
|
111
|
-
}
|
|
112
|
-
return parseNumericCellValue(value);
|
|
113
|
-
}
|
|
114
|
-
function InlineGaugeCellWithRange({ value, range, fillColor, format }) {
|
|
115
|
-
if (value === undefined) {
|
|
116
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
|
|
117
|
-
}
|
|
118
|
-
let percent = 0;
|
|
119
|
-
if (range !== undefined) {
|
|
120
|
-
if (range.max === range.min) {
|
|
121
|
-
percent = 100;
|
|
122
|
-
} else {
|
|
123
|
-
percent = (value - range.min) / (range.max - range.min) * 100;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
percent = Math.max(0, Math.min(100, percent));
|
|
127
|
-
const trackColor = 'rgba(127,127,127,0.20)';
|
|
128
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
|
|
129
|
-
sx: {
|
|
130
|
-
display: 'flex',
|
|
131
|
-
alignItems: 'center',
|
|
132
|
-
width: '100%',
|
|
133
|
-
gap: 1
|
|
134
|
-
},
|
|
135
|
-
children: [
|
|
136
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
137
|
-
sx: {
|
|
138
|
-
flexGrow: 1,
|
|
139
|
-
borderRadius: 1,
|
|
140
|
-
backgroundColor: trackColor,
|
|
141
|
-
height: 24,
|
|
142
|
-
overflow: 'hidden'
|
|
143
|
-
},
|
|
144
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
145
|
-
sx: {
|
|
146
|
-
width: `${percent}%`,
|
|
147
|
-
height: '100%',
|
|
148
|
-
backgroundColor: fillColor ?? 'success.main',
|
|
149
|
-
borderRadius: 1
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
}),
|
|
153
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
154
|
-
variant: "body2",
|
|
155
|
-
sx: {
|
|
156
|
-
minWidth: 52,
|
|
157
|
-
textAlign: 'right'
|
|
158
|
-
},
|
|
159
|
-
children: format ? (0, _components.formatValue)(value, format) : value.toFixed(2)
|
|
160
|
-
})
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
function resolveGaugeFillColor(value, globalCellSettings, columnCellSettings) {
|
|
165
|
-
let cellConfig = (0, _models.evaluateConditionalFormatting)(value, globalCellSettings);
|
|
166
|
-
if (columnCellSettings?.length) {
|
|
167
|
-
const columnCellConfig = (0, _models.evaluateConditionalFormatting)(value, columnCellSettings);
|
|
168
|
-
if (columnCellConfig) {
|
|
169
|
-
cellConfig = columnCellConfig;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return cellConfig?.backgroundColor ?? cellConfig?.textColor;
|
|
173
|
-
}
|
|
174
|
-
function generateCellContentConfig(column, gaugeRange, globalCellSettings = []) {
|
|
175
|
-
const plugin = column.plugin;
|
|
176
|
-
if (plugin !== undefined) {
|
|
177
|
-
return {
|
|
178
|
-
cell: (ctx)=>{
|
|
179
|
-
const cellValue = ctx.getValue();
|
|
180
|
-
if (plugin.kind === 'GaugeChart') {
|
|
181
|
-
const gaugeValue = getGaugeNumericValue(cellValue);
|
|
182
|
-
const gaugeFillColor = resolveGaugeFillColor(gaugeValue, globalCellSettings, column.cellSettings);
|
|
183
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(InlineGaugeCellWithRange, {
|
|
184
|
-
value: gaugeValue,
|
|
185
|
-
range: gaugeRange,
|
|
186
|
-
fillColor: gaugeFillColor,
|
|
187
|
-
format: plugin.spec?.format ?? column.format
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
const panelData = isPanelData(cellValue) ? cellValue : createSyntheticPanelData(cellValue, column.name);
|
|
191
|
-
if (!panelData) return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
|
|
192
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_EmbeddedPanel.EmbeddedPanel, {
|
|
193
|
-
kind: plugin.kind,
|
|
194
|
-
spec: plugin.spec,
|
|
195
|
-
queryResults: [
|
|
196
|
-
panelData
|
|
197
|
-
]
|
|
198
|
-
});
|
|
199
|
-
},
|
|
200
|
-
cellDescription: column.cellDescription ? ()=>`${column.cellDescription}` : ()=>''
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return {
|
|
204
|
-
cell: (ctx)=>{
|
|
205
|
-
const cellValue = ctx.getValue();
|
|
206
|
-
return typeof cellValue === 'number' && column.format ? (0, _components.formatValue)(cellValue, column.format) : cellValue;
|
|
207
|
-
},
|
|
208
|
-
cellDescription: column.cellDescription ? ()=>`${column.cellDescription}` : undefined
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function ColumnFilterDropdown({ allValues, selectedValues, onFilterChange, theme }) {
|
|
212
|
-
const [searchTerm, setSearchTerm] = (0, _react.useState)('');
|
|
213
|
-
const values = [
|
|
214
|
-
...new Set(allValues)
|
|
215
|
-
].filter((v)=>v !== null).sort();
|
|
216
|
-
const filteredValues = searchTerm ? values.filter((v)=>String(v).toLowerCase().includes(searchTerm.toLowerCase())) : values;
|
|
217
|
-
if (values.length === 0) {
|
|
218
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
219
|
-
"data-filter-dropdown": true,
|
|
220
|
-
style: {
|
|
221
|
-
width: 200,
|
|
222
|
-
padding: 10,
|
|
223
|
-
backgroundColor: theme.palette.background.paper,
|
|
224
|
-
border: `1px solid ${theme.palette.divider}`,
|
|
225
|
-
borderRadius: 4,
|
|
226
|
-
boxShadow: theme.shadows[4]
|
|
227
|
-
},
|
|
228
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
229
|
-
style: {
|
|
230
|
-
color: theme.palette.text.secondary,
|
|
231
|
-
fontSize: 14
|
|
232
|
-
},
|
|
233
|
-
children: "No values found"
|
|
234
|
-
})
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
238
|
-
"data-filter-dropdown": true,
|
|
239
|
-
style: {
|
|
240
|
-
width: 200,
|
|
241
|
-
padding: 10,
|
|
242
|
-
backgroundColor: theme.palette.background.paper,
|
|
243
|
-
border: `1px solid ${theme.palette.divider}`,
|
|
244
|
-
borderRadius: 4,
|
|
245
|
-
boxShadow: theme.shadows[4],
|
|
246
|
-
maxHeight: 250,
|
|
247
|
-
overflowY: 'auto'
|
|
248
|
-
},
|
|
249
|
-
children: [
|
|
250
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("input", {
|
|
251
|
-
type: "text",
|
|
252
|
-
placeholder: "Search...",
|
|
253
|
-
value: searchTerm,
|
|
254
|
-
onChange: (e)=>setSearchTerm(e.target.value),
|
|
255
|
-
style: {
|
|
256
|
-
width: '100%',
|
|
257
|
-
padding: '6px 8px',
|
|
258
|
-
marginBottom: 8,
|
|
259
|
-
fontSize: 13,
|
|
260
|
-
border: `1px solid ${theme.palette.divider}`,
|
|
261
|
-
borderRadius: 4,
|
|
262
|
-
backgroundColor: theme.palette.background.default,
|
|
263
|
-
color: theme.palette.text.primary,
|
|
264
|
-
boxSizing: 'border-box'
|
|
265
|
-
}
|
|
266
|
-
}),
|
|
267
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
268
|
-
style: {
|
|
269
|
-
marginBottom: 8,
|
|
270
|
-
fontSize: 14,
|
|
271
|
-
fontWeight: 'bold'
|
|
272
|
-
},
|
|
273
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("label", {
|
|
274
|
-
style: {
|
|
275
|
-
display: 'flex',
|
|
276
|
-
alignItems: 'center',
|
|
277
|
-
cursor: 'pointer'
|
|
278
|
-
},
|
|
279
|
-
children: [
|
|
280
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("input", {
|
|
281
|
-
type: "checkbox",
|
|
282
|
-
checked: selectedValues.length === values.length && values.length > 0,
|
|
283
|
-
onChange: (e)=>onFilterChange(e.target.checked ? values.map((v)=>v.original) : []),
|
|
284
|
-
style: {
|
|
285
|
-
marginRight: 8
|
|
286
|
-
}
|
|
287
|
-
}),
|
|
288
|
-
/*#__PURE__*/ (0, _jsxruntime.jsxs)("span", {
|
|
289
|
-
style: {
|
|
290
|
-
color: theme.palette.text.primary
|
|
291
|
-
},
|
|
292
|
-
children: [
|
|
293
|
-
"Select All (",
|
|
294
|
-
values.length,
|
|
295
|
-
")"
|
|
296
|
-
]
|
|
297
|
-
})
|
|
298
|
-
]
|
|
299
|
-
})
|
|
300
|
-
}),
|
|
301
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("hr", {
|
|
302
|
-
style: {
|
|
303
|
-
margin: '8px 0',
|
|
304
|
-
border: 'none',
|
|
305
|
-
borderTop: `1px solid ${theme.palette.divider}`
|
|
306
|
-
}
|
|
307
|
-
}),
|
|
308
|
-
filteredValues.map((value, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
309
|
-
style: {
|
|
310
|
-
marginBottom: 4
|
|
311
|
-
},
|
|
312
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsxs)("label", {
|
|
313
|
-
style: {
|
|
314
|
-
display: 'flex',
|
|
315
|
-
alignItems: 'center',
|
|
316
|
-
cursor: 'pointer',
|
|
317
|
-
padding: '2px 0',
|
|
318
|
-
borderRadius: 2
|
|
319
|
-
},
|
|
320
|
-
onMouseEnter: (e)=>{
|
|
321
|
-
e.currentTarget.style.backgroundColor = theme.palette.action.hover;
|
|
322
|
-
},
|
|
323
|
-
onMouseLeave: (e)=>{
|
|
324
|
-
e.currentTarget.style.backgroundColor = 'transparent';
|
|
325
|
-
},
|
|
326
|
-
children: [
|
|
327
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("input", {
|
|
328
|
-
type: "checkbox",
|
|
329
|
-
checked: selectedValues.includes(value.original),
|
|
330
|
-
onChange: (e)=>{
|
|
331
|
-
if (e.target.checked) {
|
|
332
|
-
onFilterChange([
|
|
333
|
-
...selectedValues,
|
|
334
|
-
value.original
|
|
335
|
-
]);
|
|
336
|
-
} else {
|
|
337
|
-
onFilterChange(selectedValues.filter((v)=>v !== value.original));
|
|
338
|
-
}
|
|
339
|
-
},
|
|
340
|
-
style: {
|
|
341
|
-
marginRight: 8
|
|
342
|
-
}
|
|
343
|
-
}),
|
|
344
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
345
|
-
style: {
|
|
346
|
-
fontSize: 14,
|
|
347
|
-
color: theme.palette.text.primary
|
|
348
|
-
},
|
|
349
|
-
children: value === null || value === undefined || value.formatted === '' ? '(empty)' : String(value.formatted)
|
|
350
|
-
})
|
|
351
|
-
]
|
|
352
|
-
})
|
|
353
|
-
}, `value-${index}`))
|
|
354
|
-
]
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
/*
|
|
358
|
-
* Generate column config from column definitions, if a column has multiple definitions, the first one will be used.
|
|
359
|
-
* If column is hidden, return undefined.
|
|
360
|
-
* If column do not have a definition, return a default column config.
|
|
361
|
-
*/ function generateColumnConfig(name, columnSettings, allVariables, gaugeRangeByColumn, globalCellSettings = []) {
|
|
362
|
-
for (const column of columnSettings){
|
|
363
|
-
if (column.name === name) {
|
|
364
|
-
if (column.hide) {
|
|
365
|
-
return undefined;
|
|
366
|
-
}
|
|
367
|
-
const { name, header, headerDescription, enableSorting, width, align, dataLink } = column;
|
|
368
|
-
const modifiedDataLink = dataLink ? {
|
|
369
|
-
...dataLink,
|
|
370
|
-
url: (0, _pluginsystem.replaceVariablesInString)(dataLink.url, allVariables)
|
|
371
|
-
} : undefined;
|
|
372
|
-
return {
|
|
373
|
-
accessorKey: name,
|
|
374
|
-
header: header ?? name,
|
|
375
|
-
headerDescription,
|
|
376
|
-
enableSorting,
|
|
377
|
-
width,
|
|
378
|
-
align,
|
|
379
|
-
dataLink: modifiedDataLink,
|
|
380
|
-
...generateCellContentConfig(column, gaugeRangeByColumn[name], globalCellSettings)
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
return {
|
|
385
|
-
accessorKey: name,
|
|
386
|
-
header: name
|
|
387
|
-
};
|
|
388
|
-
}
|
|
389
|
-
function getTablePanelQueryOptions(spec) {
|
|
390
|
-
// if any cell renders a panel plugin, perform a range query instead of an instant query
|
|
391
|
-
return {
|
|
392
|
-
mode: (0, _tabledatautils.getTablePanelQueryMode)(spec)
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
function TablePanel({ contentDimensions, spec, queryResults }) {
|
|
396
|
-
const theme = (0, _material.useTheme)();
|
|
397
|
-
const allVariables = (0, _pluginsystem.useAllVariableValues)();
|
|
398
|
-
const selectionEnabled = spec.selection?.enabled ?? false;
|
|
399
|
-
const { selectionMap, setSelection, clearSelection } = (0, _components.useSelection)();
|
|
400
|
-
const itemActionsConfig = spec.actions ? spec.actions : undefined;
|
|
401
|
-
const itemActionsListConfig = itemActionsConfig?.enabled && itemActionsConfig.displayWithItem ? itemActionsConfig.actionsList : [];
|
|
402
|
-
const { getItemActionButtons, confirmDialog, actionButtons } = (0, _dashboards.useSelectionItemActions)({
|
|
403
|
-
actions: itemActionsListConfig,
|
|
404
|
-
variableState: allVariables
|
|
405
|
-
});
|
|
406
|
-
const filteredDataRef = (0, _react.useRef)([]);
|
|
407
|
-
// Convert selectionMap to TanStack's RowSelectionState format
|
|
408
|
-
const rowSelection = (0, _react.useMemo)(()=>{
|
|
409
|
-
const result = {};
|
|
410
|
-
selectionMap.forEach((_, id)=>{
|
|
411
|
-
result[id] = true;
|
|
412
|
-
});
|
|
413
|
-
return result;
|
|
414
|
-
}, [
|
|
415
|
-
selectionMap
|
|
416
|
-
]);
|
|
417
|
-
const handleRowSelectionChange = (0, _react.useCallback)((newRowSelection)=>{
|
|
418
|
-
const newSelection = [];
|
|
419
|
-
for (const [id, isSelected] of Object.entries(newRowSelection)){
|
|
420
|
-
if (isSelected) {
|
|
421
|
-
const index = parseInt(id, 10);
|
|
422
|
-
if (filteredDataRef.current[index] !== undefined) {
|
|
423
|
-
newSelection.push({
|
|
424
|
-
id,
|
|
425
|
-
item: filteredDataRef.current[index]
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
if (newSelection.length === 0) {
|
|
431
|
-
clearSelection();
|
|
432
|
-
} else {
|
|
433
|
-
setSelection(newSelection);
|
|
434
|
-
}
|
|
435
|
-
}, [
|
|
436
|
-
setSelection,
|
|
437
|
-
clearSelection
|
|
438
|
-
]);
|
|
439
|
-
// TODO: handle other query types
|
|
440
|
-
const rawData = (0, _react.useMemo)(()=>{
|
|
441
|
-
// Transform query results to a tabular format using shared utility
|
|
442
|
-
return (0, _tabledatautils.buildRawTableData)(queryResults, spec);
|
|
443
|
-
}, [
|
|
444
|
-
queryResults,
|
|
445
|
-
spec
|
|
446
|
-
]);
|
|
447
|
-
// Transform will be applied by their orders on the original data
|
|
448
|
-
const data = (0, _react.useMemo)(()=>(0, _components.transformData)(rawData, spec.transforms ?? []), [
|
|
449
|
-
rawData,
|
|
450
|
-
spec.transforms
|
|
451
|
-
]);
|
|
452
|
-
const keys = (0, _react.useMemo)(()=>{
|
|
453
|
-
const result = [];
|
|
454
|
-
for (const entry of data){
|
|
455
|
-
for (const key of Object.keys(entry)){
|
|
456
|
-
if (!result.includes(key)) {
|
|
457
|
-
result.push(key);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
// Include column names from columnSettings so that columns with no data
|
|
462
|
-
// are still extended with undefined for cellSettings evaluation (e.g. N/A for null)
|
|
463
|
-
for (const col of spec.columnSettings ?? []){
|
|
464
|
-
if (!result.includes(col.name)) {
|
|
465
|
-
result.push(col.name);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return result;
|
|
469
|
-
}, [
|
|
470
|
-
data,
|
|
471
|
-
spec.columnSettings
|
|
472
|
-
]);
|
|
473
|
-
const columnsFormat = (0, _react.useMemo)(()=>{
|
|
474
|
-
const columnsFormat = {};
|
|
475
|
-
const settings = spec?.columnSettings;
|
|
476
|
-
if (settings) {
|
|
477
|
-
for(let i = 0; i < settings.length; i++){
|
|
478
|
-
const { name, format } = settings[i] || {};
|
|
479
|
-
if (name && format) {
|
|
480
|
-
columnsFormat[name] = format;
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return columnsFormat;
|
|
485
|
-
}, [
|
|
486
|
-
spec
|
|
487
|
-
]);
|
|
488
|
-
const columnUniqueValues = (0, _react.useMemo)(()=>{
|
|
489
|
-
const uniqueValues = {};
|
|
490
|
-
for (const key of keys){
|
|
491
|
-
const formatOption = columnsFormat?.[key];
|
|
492
|
-
uniqueValues[key] = [];
|
|
493
|
-
const usedValues = new Map();
|
|
494
|
-
for (const row of data){
|
|
495
|
-
const val = row[key];
|
|
496
|
-
if (val === '' || val === null || val === undefined) {
|
|
497
|
-
continue;
|
|
498
|
-
}
|
|
499
|
-
if (usedValues.get(String(val))) {
|
|
500
|
-
continue;
|
|
501
|
-
}
|
|
502
|
-
if (typeof val === 'string' || typeof val === 'number') {
|
|
503
|
-
uniqueValues[key].push({
|
|
504
|
-
original: val,
|
|
505
|
-
formatted: formatOption && typeof val === 'number' ? (0, _components.formatValue)(val, formatOption) : val
|
|
506
|
-
});
|
|
507
|
-
usedValues.set(String(val), true);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
return uniqueValues;
|
|
512
|
-
}, [
|
|
513
|
-
data,
|
|
514
|
-
keys,
|
|
515
|
-
columnsFormat
|
|
516
|
-
]);
|
|
517
|
-
const gaugeRangeByColumn = (0, _react.useMemo)(()=>{
|
|
518
|
-
const result = {};
|
|
519
|
-
for (const key of keys){
|
|
520
|
-
let min = Number.POSITIVE_INFINITY;
|
|
521
|
-
let max = Number.NEGATIVE_INFINITY;
|
|
522
|
-
for (const row of data){
|
|
523
|
-
const numericValue = getGaugeNumericValue(row[key]);
|
|
524
|
-
if (numericValue === undefined) {
|
|
525
|
-
continue;
|
|
526
|
-
}
|
|
527
|
-
min = Math.min(min, numericValue);
|
|
528
|
-
max = Math.max(max, numericValue);
|
|
529
|
-
}
|
|
530
|
-
if (min !== Number.POSITIVE_INFINITY && max !== Number.NEGATIVE_INFINITY) {
|
|
531
|
-
result[key] = {
|
|
532
|
-
min,
|
|
533
|
-
max
|
|
534
|
-
};
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
return result;
|
|
538
|
-
}, [
|
|
539
|
-
data,
|
|
540
|
-
keys
|
|
541
|
-
]);
|
|
542
|
-
// Generate columns and map each column accessor to its settings index and data key
|
|
543
|
-
const columns = (0, _react.useMemo)(()=>{
|
|
544
|
-
const columns = [];
|
|
545
|
-
const customizedColumns = new Set();
|
|
546
|
-
// Process columnSettings if they exist
|
|
547
|
-
for (const columnSetting of spec.columnSettings ?? []){
|
|
548
|
-
if (customizedColumns.has(columnSetting.name)) continue; // Skip duplicates
|
|
549
|
-
const columnConfig = generateColumnConfig(columnSetting.name, spec.columnSettings ?? [], allVariables, gaugeRangeByColumn, spec.cellSettings ?? []);
|
|
550
|
-
if (columnConfig !== undefined) {
|
|
551
|
-
columns.push(columnConfig);
|
|
552
|
-
customizedColumns.add(columnSetting.name);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
// Add remaining columns if defaultColumnHidden is false
|
|
556
|
-
if (!spec.defaultColumnHidden) {
|
|
557
|
-
for (const key of keys){
|
|
558
|
-
if (!customizedColumns.has(key)) {
|
|
559
|
-
const columnConfig = generateColumnConfig(key, spec.columnSettings ?? [], allVariables, gaugeRangeByColumn, spec.cellSettings ?? []);
|
|
560
|
-
if (columnConfig !== undefined) {
|
|
561
|
-
columns.push(columnConfig);
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
return columns;
|
|
567
|
-
}, [
|
|
568
|
-
keys,
|
|
569
|
-
spec.columnSettings,
|
|
570
|
-
spec.defaultColumnHidden,
|
|
571
|
-
allVariables,
|
|
572
|
-
gaugeRangeByColumn,
|
|
573
|
-
spec.cellSettings
|
|
574
|
-
]);
|
|
575
|
-
// Filtering state — declared before cellConfigs so filteredData is available for cell config evaluation
|
|
576
|
-
const [columnFilters, setColumnFilters] = (0, _react.useState)([]);
|
|
577
|
-
// filter data based on the current filters
|
|
578
|
-
const filteredData = (0, _react.useMemo)(()=>{
|
|
579
|
-
if (!spec.enableFiltering || columnFilters.length === 0) {
|
|
580
|
-
return data;
|
|
581
|
-
}
|
|
582
|
-
return data.filter((row)=>{
|
|
583
|
-
return columnFilters.every((filter)=>{
|
|
584
|
-
const value = row[filter.id];
|
|
585
|
-
const filterValues = filter.value;
|
|
586
|
-
if (!filterValues || filterValues.length === 0) return true;
|
|
587
|
-
return filterValues.includes(value);
|
|
588
|
-
});
|
|
589
|
-
});
|
|
590
|
-
}, [
|
|
591
|
-
data,
|
|
592
|
-
columnFilters,
|
|
593
|
-
spec.enableFiltering
|
|
594
|
-
]);
|
|
595
|
-
// Generate cell settings that will be used by the table to render cells (text color, background color, ...)
|
|
596
|
-
const cellConfigs = (0, _react.useMemo)(()=>{
|
|
597
|
-
// If there are no cell settings globally or per column, return an empty object
|
|
598
|
-
if (spec.cellSettings === undefined && !spec.columnSettings?.some((col)=>col.cellSettings !== undefined)) {
|
|
599
|
-
return {};
|
|
600
|
-
}
|
|
601
|
-
const result = {};
|
|
602
|
-
let index = 0;
|
|
603
|
-
for (const row of filteredData){
|
|
604
|
-
// Transforming key to object to extend the row with undefined values if the key is not present
|
|
605
|
-
// for checking the cell config "Misc" condition with "null"
|
|
606
|
-
const keysAsObj = keys.reduce((acc, key)=>{
|
|
607
|
-
acc[key] = undefined;
|
|
608
|
-
return acc;
|
|
609
|
-
}, {});
|
|
610
|
-
const extendRow = {
|
|
611
|
-
...keysAsObj,
|
|
612
|
-
...row
|
|
613
|
-
};
|
|
614
|
-
// Generate cellConfigs for each column (including duplicates with different headers)
|
|
615
|
-
for (const [key, value] of Object.entries(extendRow)){
|
|
616
|
-
// First, try to get cell config from global cell settings
|
|
617
|
-
let cellConfig = (0, _models.evaluateConditionalFormatting)(value, spec.cellSettings ?? []);
|
|
618
|
-
// Then, try to get cell config from column-specific cell settings
|
|
619
|
-
const columnSetting = spec.columnSettings?.find((col)=>col.name === key);
|
|
620
|
-
if (columnSetting?.cellSettings?.length) {
|
|
621
|
-
const columnCellConfig = (0, _models.evaluateConditionalFormatting)(value, columnSetting.cellSettings);
|
|
622
|
-
// Column-specific settings take precedence over global settings
|
|
623
|
-
if (columnCellConfig) {
|
|
624
|
-
cellConfig = columnCellConfig;
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
if (cellConfig) {
|
|
628
|
-
result[`${index}_${key}`] = cellConfig;
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
index++;
|
|
632
|
-
}
|
|
633
|
-
return result;
|
|
634
|
-
}, [
|
|
635
|
-
filteredData,
|
|
636
|
-
keys,
|
|
637
|
-
spec.cellSettings,
|
|
638
|
-
spec.columnSettings
|
|
639
|
-
]);
|
|
640
|
-
function generateDefaultSortingState() {
|
|
641
|
-
return spec.columnSettings?.filter((column)=>column.sort !== undefined).map((column)=>{
|
|
642
|
-
return {
|
|
643
|
-
id: column.name,
|
|
644
|
-
desc: column.sort === 'desc'
|
|
645
|
-
};
|
|
646
|
-
}) ?? [];
|
|
647
|
-
}
|
|
648
|
-
const [sorting, setSorting] = (0, _react.useState)(generateDefaultSortingState());
|
|
649
|
-
const [filterAnchorEl, setFilterAnchorEl] = (0, _react.useState)({});
|
|
650
|
-
const [openFilterColumn, setOpenFilterColumn] = (0, _react.useState)(null);
|
|
651
|
-
// get selected values for a column
|
|
652
|
-
const getSelectedFilterValues = (columnId)=>{
|
|
653
|
-
const filter = columnFilters.find((f)=>f.id === columnId);
|
|
654
|
-
return filter ? filter.value : [];
|
|
655
|
-
};
|
|
656
|
-
// update column filter
|
|
657
|
-
const updateColumnFilter = (columnId, values)=>{
|
|
658
|
-
const newFilters = columnFilters.filter((f)=>f.id !== columnId);
|
|
659
|
-
if (values.length > 0) {
|
|
660
|
-
newFilters.push({
|
|
661
|
-
id: columnId,
|
|
662
|
-
value: values
|
|
663
|
-
});
|
|
664
|
-
}
|
|
665
|
-
setColumnFilters(newFilters);
|
|
666
|
-
};
|
|
667
|
-
// Handle filter clicks
|
|
668
|
-
const handleFilterClick = (event, columnId)=>{
|
|
669
|
-
event.preventDefault();
|
|
670
|
-
event.stopPropagation();
|
|
671
|
-
setFilterAnchorEl({
|
|
672
|
-
...filterAnchorEl,
|
|
673
|
-
[columnId]: event.currentTarget
|
|
674
|
-
});
|
|
675
|
-
setOpenFilterColumn(columnId);
|
|
676
|
-
};
|
|
677
|
-
const handleFilterClose = ()=>{
|
|
678
|
-
setFilterAnchorEl({});
|
|
679
|
-
setOpenFilterColumn(null);
|
|
680
|
-
};
|
|
681
|
-
// Close filter when clicking outside
|
|
682
|
-
(0, _react.useEffect)(()=>{
|
|
683
|
-
if (!openFilterColumn) return;
|
|
684
|
-
const handleClick = (e)=>{
|
|
685
|
-
const target = e.target;
|
|
686
|
-
if (!target.closest('[data-filter-dropdown]') && !target.closest('button')) {
|
|
687
|
-
handleFilterClose();
|
|
688
|
-
}
|
|
689
|
-
};
|
|
690
|
-
const timer = setTimeout(()=>{
|
|
691
|
-
document.addEventListener('click', handleClick);
|
|
692
|
-
}, 100);
|
|
693
|
-
return ()=>{
|
|
694
|
-
clearTimeout(timer);
|
|
695
|
-
document.removeEventListener('click', handleClick);
|
|
696
|
-
};
|
|
697
|
-
}, [
|
|
698
|
-
openFilterColumn
|
|
699
|
-
]);
|
|
700
|
-
// Keep ref in sync with filtered data for use in selection handler
|
|
701
|
-
filteredDataRef.current = filteredData;
|
|
702
|
-
const [pagination, setPagination] = (0, _react.useState)(spec.pagination ? {
|
|
703
|
-
pageIndex: 0,
|
|
704
|
-
pageSize: 10
|
|
705
|
-
} : undefined);
|
|
706
|
-
(0, _react.useEffect)(()=>{
|
|
707
|
-
// If the pagination setting changes from no pagination to pagination, but the pagination state is undefined, update the pagination state
|
|
708
|
-
if (spec.pagination && !pagination) {
|
|
709
|
-
setPagination({
|
|
710
|
-
pageIndex: 0,
|
|
711
|
-
pageSize: 10
|
|
712
|
-
});
|
|
713
|
-
} else if (!spec.pagination && pagination) {
|
|
714
|
-
setPagination(undefined);
|
|
715
|
-
}
|
|
716
|
-
}, [
|
|
717
|
-
spec.pagination,
|
|
718
|
-
pagination
|
|
719
|
-
]);
|
|
720
|
-
if (contentDimensions === undefined) {
|
|
721
|
-
return null;
|
|
722
|
-
}
|
|
723
|
-
if (!data?.length) {
|
|
724
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
|
|
725
|
-
sx: {
|
|
726
|
-
display: 'flex',
|
|
727
|
-
justifyContent: 'center',
|
|
728
|
-
alignItems: 'center',
|
|
729
|
-
height: '100%'
|
|
730
|
-
},
|
|
731
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
|
|
732
|
-
children: "No data"
|
|
733
|
-
})
|
|
734
|
-
});
|
|
735
|
-
}
|
|
736
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
|
|
737
|
-
children: [
|
|
738
|
-
confirmDialog,
|
|
739
|
-
spec.enableFiltering && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
740
|
-
style: {
|
|
741
|
-
display: 'flex',
|
|
742
|
-
background: theme.palette.background.default,
|
|
743
|
-
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
744
|
-
width: contentDimensions.width,
|
|
745
|
-
boxSizing: 'border-box'
|
|
746
|
-
},
|
|
747
|
-
children: columns.map((column, idx)=>{
|
|
748
|
-
const filters = getSelectedFilterValues(column.accessorKey);
|
|
749
|
-
const columnWidth = column.width || spec.defaultColumnWidth;
|
|
750
|
-
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
751
|
-
style: {
|
|
752
|
-
padding: '8px',
|
|
753
|
-
borderRight: idx < columns.length - 1 ? `1px solid ${theme.palette.divider}` : 'none',
|
|
754
|
-
width: columnWidth,
|
|
755
|
-
minWidth: columnWidth,
|
|
756
|
-
maxWidth: columnWidth,
|
|
757
|
-
display: 'flex',
|
|
758
|
-
alignItems: 'center',
|
|
759
|
-
position: 'relative',
|
|
760
|
-
boxSizing: 'border-box',
|
|
761
|
-
flex: typeof columnWidth === 'number' ? 'none' : '1 1 auto'
|
|
762
|
-
},
|
|
763
|
-
children: [
|
|
764
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("span", {
|
|
765
|
-
style: {
|
|
766
|
-
marginRight: 8,
|
|
767
|
-
fontSize: '12px',
|
|
768
|
-
color: theme.palette.text.secondary,
|
|
769
|
-
flex: 1,
|
|
770
|
-
overflow: 'hidden',
|
|
771
|
-
textOverflow: 'ellipsis',
|
|
772
|
-
whiteSpace: 'nowrap'
|
|
773
|
-
},
|
|
774
|
-
children: filters.length ? `${filters.length} items` : 'All'
|
|
775
|
-
}),
|
|
776
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)("button", {
|
|
777
|
-
onClick: (e)=>{
|
|
778
|
-
handleFilterClick(e, column.accessorKey);
|
|
779
|
-
},
|
|
780
|
-
style: {
|
|
781
|
-
border: `1px solid ${theme.palette.divider}`,
|
|
782
|
-
background: theme.palette.background.paper,
|
|
783
|
-
cursor: 'pointer',
|
|
784
|
-
fontSize: '12px',
|
|
785
|
-
color: filters.length ? theme.palette.primary.main : theme.palette.text.secondary,
|
|
786
|
-
padding: '4px 8px',
|
|
787
|
-
borderRadius: '4px',
|
|
788
|
-
minWidth: '20px',
|
|
789
|
-
height: '24px',
|
|
790
|
-
flexShrink: 0,
|
|
791
|
-
transition: 'all 0.2s ease'
|
|
792
|
-
},
|
|
793
|
-
onMouseEnter: (e)=>{
|
|
794
|
-
e.currentTarget.style.background = theme.palette.action.hover;
|
|
795
|
-
},
|
|
796
|
-
onMouseLeave: (e)=>{
|
|
797
|
-
e.currentTarget.style.background = theme.palette.background.paper;
|
|
798
|
-
},
|
|
799
|
-
type: "button",
|
|
800
|
-
children: "▼"
|
|
801
|
-
}),
|
|
802
|
-
openFilterColumn === column.accessorKey && /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
803
|
-
style: {
|
|
804
|
-
position: 'absolute',
|
|
805
|
-
top: '100%',
|
|
806
|
-
left: 0,
|
|
807
|
-
zIndex: 1000,
|
|
808
|
-
marginTop: 4
|
|
809
|
-
},
|
|
810
|
-
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(ColumnFilterDropdown, {
|
|
811
|
-
allValues: columnUniqueValues[column.accessorKey] || [],
|
|
812
|
-
selectedValues: filters,
|
|
813
|
-
onFilterChange: (values)=>updateColumnFilter(column.accessorKey, values),
|
|
814
|
-
theme: theme
|
|
815
|
-
})
|
|
816
|
-
})
|
|
817
|
-
]
|
|
818
|
-
}, `filter-${idx}`);
|
|
819
|
-
})
|
|
820
|
-
}),
|
|
821
|
-
/*#__PURE__*/ (0, _jsxruntime.jsx)(_components.Table, {
|
|
822
|
-
data: filteredData,
|
|
823
|
-
columns: columns,
|
|
824
|
-
cellConfigs: cellConfigs,
|
|
825
|
-
height: spec.enableFiltering ? contentDimensions.height - 40 : contentDimensions.height,
|
|
826
|
-
width: contentDimensions.width,
|
|
827
|
-
density: spec.density,
|
|
828
|
-
defaultColumnWidth: spec.defaultColumnWidth,
|
|
829
|
-
defaultColumnHeight: spec.defaultColumnHeight,
|
|
830
|
-
sorting: sorting,
|
|
831
|
-
onSortingChange: setSorting,
|
|
832
|
-
pagination: pagination,
|
|
833
|
-
onPaginationChange: setPagination,
|
|
834
|
-
checkboxSelection: selectionEnabled,
|
|
835
|
-
rowSelection: rowSelection,
|
|
836
|
-
onRowSelectionChange: handleRowSelectionChange,
|
|
837
|
-
getItemActions: ({ id, data })=>getItemActionButtons({
|
|
838
|
-
id,
|
|
839
|
-
data: data
|
|
840
|
-
}),
|
|
841
|
-
hasItemActions: actionButtons && actionButtons.length > 0
|
|
842
|
-
})
|
|
843
|
-
]
|
|
844
|
-
});
|
|
845
|
-
}
|