@perses-dev/table-plugin 0.6.0

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.
Files changed (198) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +41 -0
  3. package/__mf/css/async/2341.cbbd94a8.css +1 -0
  4. package/__mf/css/async/5263.cbbd94a8.css +1 -0
  5. package/__mf/css/async/6759.cbbd94a8.css +1 -0
  6. package/__mf/css/async/8433.cbbd94a8.css +1 -0
  7. package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
  8. package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
  9. package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
  10. package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
  11. package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
  12. package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
  13. package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
  14. package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
  15. package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
  16. package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
  17. package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
  18. package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
  19. package/__mf/js/6487.f255ba88.js +5 -0
  20. package/__mf/js/Table.510470af.js +5 -0
  21. package/__mf/js/async/1620.ed8d9b3d.js +2 -0
  22. package/__mf/js/async/1620.ed8d9b3d.js.LICENSE.txt +9 -0
  23. package/__mf/js/async/1640.ff18956a.js +1 -0
  24. package/__mf/js/async/1722.586085f2.js +1 -0
  25. package/__mf/js/async/1964.979a7101.js +2 -0
  26. package/__mf/js/async/1964.979a7101.js.LICENSE.txt +9 -0
  27. package/__mf/js/async/1996.e0e5fb2a.js +2 -0
  28. package/__mf/js/async/1996.e0e5fb2a.js.LICENSE.txt +24 -0
  29. package/__mf/js/async/232.ab228ab3.js +1 -0
  30. package/__mf/js/async/2399.8ceb88c6.js +23 -0
  31. package/__mf/js/async/2641.78a9e888.js +1 -0
  32. package/__mf/js/async/2651.7c8030f0.js +1 -0
  33. package/__mf/js/async/3001.51d0062c.js +1 -0
  34. package/__mf/js/async/3224.fbb884ab.js +1 -0
  35. package/__mf/js/async/3598.66df4cef.js +1 -0
  36. package/__mf/js/async/3660.4a5855e1.js +23 -0
  37. package/__mf/js/async/3893.f1c71cae.js +1 -0
  38. package/__mf/js/async/3960.c992ac30.js +2 -0
  39. package/__mf/js/async/3960.c992ac30.js.LICENSE.txt +8 -0
  40. package/__mf/js/async/4062.0dd7dc24.js +1 -0
  41. package/__mf/js/async/4075.4fb81a28.js +1 -0
  42. package/__mf/js/async/4238.e22a8e1b.js +1 -0
  43. package/__mf/js/async/4446.9a215492.js +1 -0
  44. package/__mf/js/async/468.cca77551.js +110 -0
  45. package/__mf/js/async/468.cca77551.js.LICENSE.txt +27 -0
  46. package/__mf/js/async/4741.ceabfbaa.js +38 -0
  47. package/__mf/js/async/52.77f8a241.js +2 -0
  48. package/__mf/js/async/52.77f8a241.js.LICENSE.txt +37 -0
  49. package/__mf/js/async/5214.19ee9ad8.js +1 -0
  50. package/__mf/js/async/5377.05ab91aa.js +1 -0
  51. package/__mf/js/async/5409.3c667e6d.js +1 -0
  52. package/__mf/js/async/5662.d6ae2721.js +1 -0
  53. package/__mf/js/async/5767.6be60775.js +1 -0
  54. package/__mf/js/async/5912.b68e4631.js +1 -0
  55. package/__mf/js/async/5981.95116879.js +2 -0
  56. package/__mf/js/async/5981.95116879.js.LICENSE.txt +8 -0
  57. package/__mf/js/async/5998.ac755fc8.js +73 -0
  58. package/__mf/js/async/5998.ac755fc8.js.LICENSE.txt +19 -0
  59. package/__mf/js/async/6292.20be7eae.js +1 -0
  60. package/__mf/js/async/6333.35401612.js +2 -0
  61. package/__mf/js/async/6333.35401612.js.LICENSE.txt +9 -0
  62. package/__mf/js/async/654.fd64ef4b.js +1 -0
  63. package/__mf/js/async/6757.5675a614.js +7 -0
  64. package/__mf/js/async/6757.5675a614.js.LICENSE.txt +21 -0
  65. package/__mf/js/async/6770.84690346.js +1 -0
  66. package/__mf/js/async/6884.5426473f.js +1 -0
  67. package/__mf/js/async/694.4b146780.js +1 -0
  68. package/__mf/js/async/738.e2fbbd72.js +1 -0
  69. package/__mf/js/async/7606.4ba8e3ec.js +1 -0
  70. package/__mf/js/async/7740.dcade8b6.js +1 -0
  71. package/__mf/js/async/8444.d0d247d8.js +1 -0
  72. package/__mf/js/async/8488.d5eddfc6.js +1 -0
  73. package/__mf/js/async/8807.f0e4209b.js +1 -0
  74. package/__mf/js/async/894.1c4bbdb5.js +1 -0
  75. package/__mf/js/async/9010.8332598b.js +1 -0
  76. package/__mf/js/async/9173.00408de3.js +2 -0
  77. package/__mf/js/async/9173.00408de3.js.LICENSE.txt +19 -0
  78. package/__mf/js/async/9509.e6075bf0.js +1 -0
  79. package/__mf/js/async/__federation_expose_Table.0b081d4a.js +1 -0
  80. package/__mf/js/async/lib-router.d60ae988.js +2 -0
  81. package/__mf/js/async/lib-router.d60ae988.js.LICENSE.txt +32 -0
  82. package/__mf/js/main.fa5edfce.js +1 -0
  83. package/lib/CellsEditor/CellEditor.d.ts +10 -0
  84. package/lib/CellsEditor/CellEditor.d.ts.map +1 -0
  85. package/lib/CellsEditor/CellEditor.js +372 -0
  86. package/lib/CellsEditor/CellEditor.js.map +1 -0
  87. package/lib/CellsEditor/CellsEditor.d.ts +8 -0
  88. package/lib/CellsEditor/CellsEditor.d.ts.map +1 -0
  89. package/lib/CellsEditor/CellsEditor.js +123 -0
  90. package/lib/CellsEditor/CellsEditor.js.map +1 -0
  91. package/lib/CellsEditor/index.d.ts +3 -0
  92. package/lib/CellsEditor/index.d.ts.map +1 -0
  93. package/lib/CellsEditor/index.js +16 -0
  94. package/lib/CellsEditor/index.js.map +1 -0
  95. package/lib/ColumnsEditor/ColumnEditor.d.ts +11 -0
  96. package/lib/ColumnsEditor/ColumnEditor.d.ts.map +1 -0
  97. package/lib/ColumnsEditor/ColumnEditor.js +213 -0
  98. package/lib/ColumnsEditor/ColumnEditor.js.map +1 -0
  99. package/lib/ColumnsEditor/ColumnEditorContainer.d.ts +11 -0
  100. package/lib/ColumnsEditor/ColumnEditorContainer.d.ts.map +1 -0
  101. package/lib/ColumnsEditor/ColumnEditorContainer.js +139 -0
  102. package/lib/ColumnsEditor/ColumnEditorContainer.js.map +1 -0
  103. package/lib/ColumnsEditor/ColumnsEditor.d.ts +8 -0
  104. package/lib/ColumnsEditor/ColumnsEditor.d.ts.map +1 -0
  105. package/lib/ColumnsEditor/ColumnsEditor.js +95 -0
  106. package/lib/ColumnsEditor/ColumnsEditor.js.map +1 -0
  107. package/lib/ColumnsEditor/index.d.ts +4 -0
  108. package/lib/ColumnsEditor/index.d.ts.map +1 -0
  109. package/lib/ColumnsEditor/index.js +17 -0
  110. package/lib/ColumnsEditor/index.js.map +1 -0
  111. package/lib/EmbeddedPanel.d.ts +10 -0
  112. package/lib/EmbeddedPanel.d.ts.map +1 -0
  113. package/lib/EmbeddedPanel.js +39 -0
  114. package/lib/EmbeddedPanel.js.map +1 -0
  115. package/lib/Table.d.ts +8 -0
  116. package/lib/Table.d.ts.map +1 -0
  117. package/lib/Table.js +48 -0
  118. package/lib/Table.js.map +1 -0
  119. package/lib/TableCellsEditor.d.ts +6 -0
  120. package/lib/TableCellsEditor.d.ts.map +1 -0
  121. package/lib/TableCellsEditor.js +28 -0
  122. package/lib/TableCellsEditor.js.map +1 -0
  123. package/lib/TableColumnsEditor.d.ts +6 -0
  124. package/lib/TableColumnsEditor.d.ts.map +1 -0
  125. package/lib/TableColumnsEditor.js +28 -0
  126. package/lib/TableColumnsEditor.js.map +1 -0
  127. package/lib/TablePanel.d.ts +10 -0
  128. package/lib/TablePanel.d.ts.map +1 -0
  129. package/lib/TablePanel.js +325 -0
  130. package/lib/TablePanel.js.map +1 -0
  131. package/lib/TableSettingsEditor.d.ts +4 -0
  132. package/lib/TableSettingsEditor.d.ts.map +1 -0
  133. package/lib/TableSettingsEditor.js +108 -0
  134. package/lib/TableSettingsEditor.js.map +1 -0
  135. package/lib/TableTransformsEditor.d.ts +4 -0
  136. package/lib/TableTransformsEditor.d.ts.map +1 -0
  137. package/lib/TableTransformsEditor.js +28 -0
  138. package/lib/TableTransformsEditor.js.map +1 -0
  139. package/lib/bootstrap.d.ts +2 -0
  140. package/lib/bootstrap.d.ts.map +1 -0
  141. package/lib/bootstrap.js +19 -0
  142. package/lib/bootstrap.js.map +1 -0
  143. package/lib/cjs/CellsEditor/CellEditor.js +385 -0
  144. package/lib/cjs/CellsEditor/CellsEditor.js +136 -0
  145. package/lib/cjs/CellsEditor/index.js +31 -0
  146. package/lib/cjs/ColumnsEditor/ColumnEditor.js +221 -0
  147. package/lib/cjs/ColumnsEditor/ColumnEditorContainer.js +152 -0
  148. package/lib/cjs/ColumnsEditor/ColumnsEditor.js +108 -0
  149. package/lib/cjs/ColumnsEditor/index.js +32 -0
  150. package/lib/cjs/EmbeddedPanel.js +52 -0
  151. package/lib/cjs/Table.js +54 -0
  152. package/lib/cjs/TableCellsEditor.js +36 -0
  153. package/lib/cjs/TableColumnsEditor.js +36 -0
  154. package/lib/cjs/TablePanel.js +341 -0
  155. package/lib/cjs/TableSettingsEditor.js +116 -0
  156. package/lib/cjs/TableTransformsEditor.js +36 -0
  157. package/lib/cjs/bootstrap.js +26 -0
  158. package/lib/cjs/env.d.js +14 -0
  159. package/lib/cjs/getPluginModule.js +27 -0
  160. package/lib/cjs/index-federation.js +55 -0
  161. package/lib/cjs/index.js +34 -0
  162. package/lib/cjs/model.js +4 -0
  163. package/lib/cjs/setup-tests.js +19 -0
  164. package/lib/cjs/table-model.js +27 -0
  165. package/lib/cjs/test/mock-query-results.js +417 -0
  166. package/lib/env.d.js +15 -0
  167. package/lib/env.d.js.map +1 -0
  168. package/lib/getPluginModule.d.ts +6 -0
  169. package/lib/getPluginModule.d.ts.map +1 -0
  170. package/lib/getPluginModule.js +16 -0
  171. package/lib/getPluginModule.js.map +1 -0
  172. package/lib/index-federation.d.ts +1 -0
  173. package/lib/index-federation.d.ts.map +1 -0
  174. package/lib/index-federation.js +15 -0
  175. package/lib/index-federation.js.map +1 -0
  176. package/lib/index.d.ts +12 -0
  177. package/lib/index.d.ts.map +1 -0
  178. package/lib/index.js +13 -0
  179. package/lib/index.js.map +1 -0
  180. package/lib/model.d.ts +6 -0
  181. package/lib/model.d.ts.map +1 -0
  182. package/lib/model.js +3 -0
  183. package/lib/model.js.map +1 -0
  184. package/lib/setup-tests.d.ts +2 -0
  185. package/lib/setup-tests.d.ts.map +1 -0
  186. package/lib/setup-tests.js +17 -0
  187. package/lib/setup-tests.js.map +1 -0
  188. package/lib/table-model.d.ts +92 -0
  189. package/lib/table-model.d.ts.map +1 -0
  190. package/lib/table-model.js +21 -0
  191. package/lib/table-model.js.map +1 -0
  192. package/lib/test/mock-query-results.d.ts +136 -0
  193. package/lib/test/mock-query-results.d.ts.map +1 -0
  194. package/lib/test/mock-query-results.js +389 -0
  195. package/lib/test/mock-query-results.js.map +1 -0
  196. package/mf-manifest.json +491 -0
  197. package/mf-stats.json +554 -0
  198. package/package.json +60 -0
@@ -0,0 +1,32 @@
1
+ // Copyright 2024 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
+ _export_star(require("./ColumnEditor"), exports);
18
+ _export_star(require("./ColumnEditorContainer"), exports);
19
+ _export_star(require("./ColumnsEditor"), exports);
20
+ function _export_star(from, to) {
21
+ Object.keys(from).forEach(function(k) {
22
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
23
+ Object.defineProperty(to, k, {
24
+ enumerable: true,
25
+ get: function() {
26
+ return from[k];
27
+ }
28
+ });
29
+ }
30
+ });
31
+ return from;
32
+ }
@@ -0,0 +1,52 @@
1
+ // Copyright 2025 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
+ Object.defineProperty(exports, "EmbeddedPanel", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return EmbeddedPanel;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _dashboards = require("@perses-dev/dashboards");
25
+ const _useresizeobserver = /*#__PURE__*/ _interop_require_default(require("use-resize-observer"));
26
+ const _components = require("@perses-dev/components");
27
+ function _interop_require_default(obj) {
28
+ return obj && obj.__esModule ? obj : {
29
+ default: obj
30
+ };
31
+ }
32
+ function EmbeddedPanel({ kind, spec, queryResults }) {
33
+ const { ref, width = 1, height = 1 } = (0, _useresizeobserver.default)();
34
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
35
+ ref: ref,
36
+ style: {
37
+ height: '100%'
38
+ },
39
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
40
+ FallbackComponent: _components.ErrorAlert,
41
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_dashboards.PanelPluginLoader, {
42
+ kind: kind,
43
+ contentDimensions: {
44
+ width,
45
+ height
46
+ },
47
+ spec: spec,
48
+ queryResults: queryResults
49
+ })
50
+ })
51
+ });
52
+ }
@@ -0,0 +1,54 @@
1
+ // Copyright 2024 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
+ Object.defineProperty(exports, "Table", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return Table;
21
+ }
22
+ });
23
+ const _tablemodel = require("./table-model");
24
+ const _TablePanel = require("./TablePanel");
25
+ const _TableColumnsEditor = require("./TableColumnsEditor");
26
+ const _TableSettingsEditor = require("./TableSettingsEditor");
27
+ const _TableCellsEditor = require("./TableCellsEditor");
28
+ const _TableTransformsEditor = require("./TableTransformsEditor");
29
+ const Table = {
30
+ PanelComponent: _TablePanel.TablePanel,
31
+ supportedQueryTypes: [
32
+ 'TimeSeriesQuery'
33
+ ],
34
+ queryOptions: _TablePanel.getTablePanelQueryOptions,
35
+ panelOptionsEditorComponents: [
36
+ {
37
+ label: 'General Settings',
38
+ content: _TableSettingsEditor.TableSettingsEditor
39
+ },
40
+ {
41
+ label: 'Column Settings',
42
+ content: _TableColumnsEditor.TableColumnsEditor
43
+ },
44
+ {
45
+ label: 'Cell Settings',
46
+ content: _TableCellsEditor.TableCellsEditor
47
+ },
48
+ {
49
+ label: 'Transforms',
50
+ content: _TableTransformsEditor.TableTransformsEditor
51
+ }
52
+ ],
53
+ createInitialOptions: _tablemodel.createInitialTableOptions
54
+ };
@@ -0,0 +1,36 @@
1
+ // Copyright 2024 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
+ Object.defineProperty(exports, "TableCellsEditor", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return TableCellsEditor;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _CellsEditor = require("./CellsEditor");
25
+ function TableCellsEditor({ onChange, value }) {
26
+ function handleCellsChange(cells) {
27
+ onChange({
28
+ ...value,
29
+ cellSettings: cells
30
+ });
31
+ }
32
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_CellsEditor.CellsEditor, {
33
+ cellSettings: value.cellSettings ?? [],
34
+ onChange: handleCellsChange
35
+ });
36
+ }
@@ -0,0 +1,36 @@
1
+ // Copyright 2024 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
+ Object.defineProperty(exports, "TableColumnsEditor", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return TableColumnsEditor;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _ColumnsEditor = require("./ColumnsEditor");
25
+ function TableColumnsEditor({ onChange, value }) {
26
+ function handleColumnsChange(columns) {
27
+ onChange({
28
+ ...value,
29
+ columnSettings: columns
30
+ });
31
+ }
32
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_ColumnsEditor.ColumnsEditor, {
33
+ columnSettings: value.columnSettings ?? [],
34
+ onChange: handleColumnsChange
35
+ });
36
+ }
@@ -0,0 +1,341 @@
1
+ // Copyright 2024 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: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ TablePanel: function() {
25
+ return TablePanel;
26
+ },
27
+ getTablePanelQueryOptions: function() {
28
+ return getTablePanelQueryOptions;
29
+ }
30
+ });
31
+ const _jsxruntime = require("react/jsx-runtime");
32
+ const _components = require("@perses-dev/components");
33
+ const _react = require("react");
34
+ const _core = require("@perses-dev/core");
35
+ const _EmbeddedPanel = require("./EmbeddedPanel");
36
+ function generateCellContentConfig(column) {
37
+ const plugin = column.plugin;
38
+ if (plugin !== undefined) {
39
+ return {
40
+ cell: (ctx)=>{
41
+ const panelData = ctx.getValue();
42
+ if (!panelData) return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
43
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_EmbeddedPanel.EmbeddedPanel, {
44
+ kind: plugin.kind,
45
+ spec: plugin.spec,
46
+ queryResults: [
47
+ panelData
48
+ ]
49
+ });
50
+ },
51
+ cellDescription: column.cellDescription ? ()=>`${column.cellDescription}` : ()=>''
52
+ };
53
+ }
54
+ return {
55
+ cell: (ctx)=>{
56
+ const cellValue = ctx.getValue();
57
+ return typeof cellValue === 'number' && column.format ? (0, _core.formatValue)(cellValue, column.format) : cellValue;
58
+ },
59
+ cellDescription: column.cellDescription ? ()=>`${column.cellDescription}` : undefined
60
+ };
61
+ }
62
+ /*
63
+ * Generate column config from column definitions, if a column has multiple definitions, the first one will be used.
64
+ * If column is hidden, return undefined.
65
+ * If column do not have a definition, return a default column config.
66
+ */ function generateColumnConfig(name, columnSettings) {
67
+ for (const column of columnSettings){
68
+ if (column.name === name) {
69
+ if (column.hide) {
70
+ return undefined;
71
+ }
72
+ return {
73
+ accessorKey: name,
74
+ header: column.header ?? name,
75
+ headerDescription: column.headerDescription,
76
+ enableSorting: column.enableSorting,
77
+ width: column.width,
78
+ align: column.align,
79
+ ...generateCellContentConfig(column)
80
+ };
81
+ }
82
+ }
83
+ return {
84
+ accessorKey: name,
85
+ header: name
86
+ };
87
+ }
88
+ function generateCellConfig(value, settings) {
89
+ for (const setting of settings){
90
+ if (setting.condition.kind === 'Value' && setting.condition.spec?.value === String(value)) {
91
+ return {
92
+ text: setting.text,
93
+ textColor: setting.textColor,
94
+ backgroundColor: setting.backgroundColor
95
+ };
96
+ }
97
+ if (setting.condition.kind === 'Range' && !Number.isNaN(Number(value))) {
98
+ const numericValue = Number(value);
99
+ if (setting.condition.spec?.min !== undefined && setting.condition.spec?.max !== undefined && numericValue >= +setting.condition.spec?.min && numericValue <= +setting.condition.spec?.max) {
100
+ return {
101
+ text: setting.text,
102
+ textColor: setting.textColor,
103
+ backgroundColor: setting.backgroundColor
104
+ };
105
+ }
106
+ if (setting.condition.spec?.min !== undefined && numericValue >= +setting.condition.spec?.min) {
107
+ return {
108
+ text: setting.text,
109
+ textColor: setting.textColor,
110
+ backgroundColor: setting.backgroundColor
111
+ };
112
+ }
113
+ if (setting.condition.spec?.max !== undefined && numericValue <= +setting.condition.spec?.max) {
114
+ return {
115
+ text: setting.text,
116
+ textColor: setting.textColor,
117
+ backgroundColor: setting.backgroundColor
118
+ };
119
+ }
120
+ }
121
+ if (setting.condition.kind === 'Regex' && setting.condition.spec?.expr) {
122
+ const regex = new RegExp(setting.condition.spec?.expr);
123
+ if (regex.test(String(value))) {
124
+ return {
125
+ text: setting.text,
126
+ textColor: setting.textColor,
127
+ backgroundColor: setting.backgroundColor
128
+ };
129
+ }
130
+ }
131
+ if (setting.condition.kind === 'Misc' && setting.condition.spec?.value) {
132
+ if (setting.condition.spec?.value === 'empty' && value === '') {
133
+ return {
134
+ text: setting.text,
135
+ textColor: setting.textColor,
136
+ backgroundColor: setting.backgroundColor
137
+ };
138
+ }
139
+ if (setting.condition.spec?.value === 'null' && (value === null || value === undefined)) {
140
+ return {
141
+ text: setting.text,
142
+ textColor: setting.textColor,
143
+ backgroundColor: setting.backgroundColor
144
+ };
145
+ }
146
+ if (setting.condition.spec?.value === 'NaN' && Number.isNaN(value)) {
147
+ return {
148
+ text: setting.text,
149
+ textColor: setting.textColor,
150
+ backgroundColor: setting.backgroundColor
151
+ };
152
+ }
153
+ if (setting.condition.spec?.value === 'true' && value === true) {
154
+ return {
155
+ text: setting.text,
156
+ textColor: setting.textColor,
157
+ backgroundColor: setting.backgroundColor
158
+ };
159
+ }
160
+ if (setting.condition.spec?.value === 'false' && value === false) {
161
+ return {
162
+ text: setting.text,
163
+ textColor: setting.textColor,
164
+ backgroundColor: setting.backgroundColor
165
+ };
166
+ }
167
+ }
168
+ }
169
+ return undefined;
170
+ }
171
+ function getTablePanelQueryOptions(spec) {
172
+ // if any cell renders a panel plugin, perform a range query instead of an instant query
173
+ return {
174
+ mode: (spec.columnSettings ?? []).some((c)=>c.plugin) ? 'range' : 'instant'
175
+ };
176
+ }
177
+ function TablePanel({ contentDimensions, spec, queryResults }) {
178
+ // TODO: handle other query types
179
+ const queryMode = getTablePanelQueryOptions(spec).mode;
180
+ const rawData = (0, _react.useMemo)(()=>{
181
+ // Transform query results to a tabular format:
182
+ // [ { timestamp: 123, value: 456, labelName1: labelValue1 }, ... ]
183
+ return queryResults.flatMap((data, queryIndex)=>data.data.series.map((ts)=>({
184
+ data,
185
+ ts,
186
+ queryIndex
187
+ }))).map(({ data, ts, queryIndex })=>{
188
+ if (ts.values[0] === undefined) {
189
+ return {
190
+ ...ts.labels
191
+ };
192
+ }
193
+ // If there are multiple queries, we need to add the query index to the value key and label key to avoid conflicts
194
+ const valueColumnName = queryResults.length === 1 ? 'value' : `value #${queryIndex + 1}`;
195
+ const labels = queryResults.length === 1 ? ts.labels : Object.entries(ts.labels ?? {}).reduce((acc, [key, value])=>{
196
+ if (key) acc[`${key} #${queryIndex + 1}`] = value;
197
+ return acc;
198
+ }, {});
199
+ // If the cell visualization is a panel plugin, filter the data by the current series
200
+ const columnValue = (spec.columnSettings ?? []).find((x)=>x.name === valueColumnName)?.plugin ? {
201
+ ...data,
202
+ data: {
203
+ ...data.data,
204
+ series: data.data.series.filter((s)=>s === ts)
205
+ }
206
+ } : ts.values[0][1];
207
+ if (queryMode === 'instant') {
208
+ // Timestamp is not indexed as it will be the same for all queries
209
+ return {
210
+ timestamp: ts.values[0][0],
211
+ [valueColumnName]: columnValue,
212
+ ...labels
213
+ };
214
+ } else {
215
+ // Don't add a timestamp for range queries
216
+ return {
217
+ [valueColumnName]: columnValue,
218
+ ...labels
219
+ };
220
+ }
221
+ });
222
+ }, [
223
+ queryResults,
224
+ queryMode,
225
+ spec.columnSettings
226
+ ]);
227
+ // Transform will be applied by their orders on the original data
228
+ const data = (0, _core.useTransformData)(rawData, spec.transforms ?? []);
229
+ const keys = (0, _react.useMemo)(()=>{
230
+ const result = [];
231
+ for (const entry of data){
232
+ for (const key of Object.keys(entry)){
233
+ if (!result.includes(key)) {
234
+ result.push(key);
235
+ }
236
+ }
237
+ }
238
+ return result;
239
+ }, [
240
+ data
241
+ ]);
242
+ const columns = (0, _react.useMemo)(()=>{
243
+ const columns = [];
244
+ // Taking the customized columns first for the ordering of the columns in the table
245
+ const customizedColumns = spec.columnSettings?.map((column)=>column.name).filter((name)=>keys.includes(name)) ?? [];
246
+ const defaultColumns = keys.filter((key)=>!customizedColumns.includes(key));
247
+ for (const key of customizedColumns){
248
+ const columnConfig = generateColumnConfig(key, spec.columnSettings ?? []);
249
+ if (columnConfig !== undefined) {
250
+ columns.push(columnConfig);
251
+ }
252
+ }
253
+ for (const key of defaultColumns){
254
+ const columnConfig = generateColumnConfig(key, spec.columnSettings ?? []);
255
+ if (columnConfig !== undefined) {
256
+ columns.push(columnConfig);
257
+ }
258
+ }
259
+ return columns;
260
+ }, [
261
+ keys,
262
+ spec.columnSettings
263
+ ]);
264
+ // Generate cell settings that will be used by the table to render cells (text color, background color, ...)
265
+ const cellConfigs = (0, _react.useMemo)(()=>{
266
+ // If there is no cell settings, return an empty array
267
+ if (spec.cellSettings === undefined) {
268
+ return {};
269
+ }
270
+ const result = {};
271
+ let index = 0;
272
+ for (const row of data){
273
+ // Transforming key to object to extend the row with undefined values if the key is not present
274
+ // for checking the cell config "Misc" condition with "null"
275
+ const keysAsObj = keys.reduce((acc, key)=>{
276
+ acc[key] = undefined;
277
+ return acc;
278
+ }, {});
279
+ const extendRow = {
280
+ ...keysAsObj,
281
+ ...row
282
+ };
283
+ for (const [key, value] of Object.entries(extendRow)){
284
+ const cellConfig = generateCellConfig(value, spec.cellSettings ?? []);
285
+ if (cellConfig) {
286
+ result[`${index}_${key}`] = cellConfig;
287
+ }
288
+ }
289
+ index++;
290
+ }
291
+ return result;
292
+ }, [
293
+ data,
294
+ keys,
295
+ spec.cellSettings
296
+ ]);
297
+ function generateDefaultSortingState() {
298
+ return spec.columnSettings?.filter((column)=>column.sort !== undefined).map((column)=>{
299
+ return {
300
+ id: column.name,
301
+ desc: column.sort === 'desc'
302
+ };
303
+ }) ?? [];
304
+ }
305
+ const [sorting, setSorting] = (0, _react.useState)(generateDefaultSortingState());
306
+ const [pagination, setPagination] = (0, _react.useState)(spec.pagination ? {
307
+ pageIndex: 0,
308
+ pageSize: 10
309
+ } : undefined);
310
+ (0, _react.useEffect)(()=>{
311
+ // If the pagination setting changes from no pagination to pagination, but the pagination state is undefined, update the pagination state
312
+ if (spec.pagination && !pagination) {
313
+ setPagination({
314
+ pageIndex: 0,
315
+ pageSize: 10
316
+ });
317
+ } else if (!spec.pagination && pagination) {
318
+ setPagination(undefined);
319
+ }
320
+ }, [
321
+ spec.pagination,
322
+ pagination
323
+ ]);
324
+ if (contentDimensions === undefined) {
325
+ return null;
326
+ }
327
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.Table, {
328
+ data: data,
329
+ columns: columns,
330
+ cellConfigs: cellConfigs,
331
+ height: contentDimensions.height,
332
+ width: contentDimensions.width,
333
+ density: spec.density,
334
+ defaultColumnWidth: spec.defaultColumnWidth,
335
+ defaultColumnHeight: spec.defaultColumnHeight,
336
+ sorting: sorting,
337
+ onSortingChange: setSorting,
338
+ pagination: pagination,
339
+ onPaginationChange: setPagination
340
+ });
341
+ }
@@ -0,0 +1,116 @@
1
+ // Copyright 2024 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
+ Object.defineProperty(exports, "TableSettingsEditor", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return TableSettingsEditor;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _material = require("@mui/material");
25
+ const _components = require("@perses-dev/components");
26
+ function DefaultColumnsDimensionsControl({ label, defaultValue, value, onChange }) {
27
+ function handleAutoSwitchChange(_, checked) {
28
+ if (checked) {
29
+ return onChange('auto');
30
+ }
31
+ onChange(defaultValue);
32
+ }
33
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
34
+ children: [
35
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
36
+ label: `Auto Columns ${label}`,
37
+ control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Switch, {
38
+ checked: value === undefined || value === 'auto',
39
+ onChange: handleAutoSwitchChange
40
+ })
41
+ }),
42
+ value !== undefined && value !== 'auto' && /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
43
+ label: `Default Columns ${label}`,
44
+ control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
45
+ type: "number",
46
+ value: value ?? defaultValue,
47
+ InputProps: {
48
+ inputProps: {
49
+ min: 1,
50
+ step: 1
51
+ }
52
+ },
53
+ onChange: (e)=>onChange(parseInt(e.target.value))
54
+ })
55
+ })
56
+ ]
57
+ });
58
+ }
59
+ function TableSettingsEditor({ onChange, value }) {
60
+ function handleDensityChange(density) {
61
+ onChange({
62
+ ...value,
63
+ density: density
64
+ });
65
+ }
66
+ function handlePaginationChange(_event, newValue) {
67
+ onChange({
68
+ ...value,
69
+ pagination: newValue
70
+ });
71
+ }
72
+ function handleAutoWidthChange(newValue) {
73
+ onChange({
74
+ ...value,
75
+ defaultColumnWidth: newValue
76
+ });
77
+ }
78
+ function handleAutoHeightChange(newValue) {
79
+ onChange({
80
+ ...value,
81
+ defaultColumnHeight: newValue
82
+ });
83
+ }
84
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorGrid, {
85
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorColumn, {
86
+ children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_components.OptionsEditorGroup, {
87
+ title: "Display",
88
+ children: [
89
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.DensitySelector, {
90
+ value: value.density,
91
+ onChange: handleDensityChange
92
+ }),
93
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
94
+ label: "Pagination",
95
+ control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Switch, {
96
+ checked: !!value.pagination,
97
+ onChange: handlePaginationChange
98
+ })
99
+ }),
100
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(DefaultColumnsDimensionsControl, {
101
+ label: "Width",
102
+ defaultValue: _components.DEFAULT_COLUMN_WIDTH,
103
+ value: value.defaultColumnWidth,
104
+ onChange: handleAutoWidthChange
105
+ }),
106
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(DefaultColumnsDimensionsControl, {
107
+ label: "Height",
108
+ defaultValue: _components.DEFAULT_COLUMN_HEIGHT,
109
+ value: value.defaultColumnHeight,
110
+ onChange: handleAutoHeightChange
111
+ })
112
+ ]
113
+ })
114
+ })
115
+ });
116
+ }