From 440f979f23ee308e30a603e5bac97b811a18ba83 Mon Sep 17 00:00:00 2001 From: Nijat Khanbabayev Date: Tue, 21 Oct 2025 00:14:54 -0400 Subject: [PATCH 1/2] Update js code for bug Signed-off-by: Nijat Khanbabayev --- js/src/common.js | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ js/src/index.jsx | 3 ++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/js/src/common.js b/js/src/common.js index e849f41..bded22c 100644 --- a/js/src/common.js +++ b/js/src/common.js @@ -27,3 +27,63 @@ export const shutdownDefault = async () => { { method: "POST" }, ); }; + +export const processTables = (to_restore, tables, workspace, theme) => { + // handle tables + // sort, but then put them into "best" order + const sortedTables = Object.keys(tables); + sortedTables.sort(); + + const allTables = []; + + sortedTables.forEach((name) => { + if (allTables.indexOf(name) < 0) { + allTables.push(name); + } + }); + + allTables.forEach((tableName, index) => { + const { table } = tables[tableName]; + const { schema } = tables[tableName]; + + workspace.addTable(tableName, table); + + const generated_id = `${tableName.toUpperCase()}_GENERATED_${index + 1}`; + + to_restore.detail.main.widgets.push(generated_id); + + const viewer_config = { + title: tableName, + table: tableName, + sort: [["timestamp", "desc"]], + theme: theme === "dark" ? "Pro Dark" : "Pro Light", + }; + // include all columns except id by default + viewer_config.columns = Object.keys(schema).filter((col) => col !== "id"); + + if (tableName === "my_bad_struct") { + viewer_config.group_by = [ + "group_by_col_a", + "group_by_col_b", + "group_by_col_c", + ]; + viewer_config.columns = Object.keys(schema).filter( + (col) => + ![ + "id", + "group_by_col_a", + "group_by_col_b", + "group_by_col_c", + ].includes(col), + ); + } + // groupby last for all by default + viewer_config.aggregates = Object.keys(schema).reduce((attrs, key) => { + // eslint-disable-next-line no-param-reassign + attrs[key] = "last"; + return attrs; + }, {}); + + to_restore.viewers[generated_id] = viewer_config; + }); +}; diff --git a/js/src/index.jsx b/js/src/index.jsx index 9b0c430..bfd7d33 100644 --- a/js/src/index.jsx +++ b/js/src/index.jsx @@ -8,6 +8,8 @@ import { getServerDefinedLayouts, } from "./components/perspective"; +import { processTables } from "./common"; + /* exports */ export * from "./common"; export * from "./components"; @@ -16,7 +18,6 @@ export default function App(props) { const { headerLogo, footerLogo, - processTables, overrideSettingsButtons, extraSettingsButtons, shutdown, From 500f3a9fdce01dd03bc6fec1a36a1c288110d449 Mon Sep 17 00:00:00 2001 From: Nijat Khanbabayev Date: Tue, 21 Oct 2025 14:17:46 -0400 Subject: [PATCH 2/2] Simplify common.js Signed-off-by: Nijat Khanbabayev --- js/src/common.js | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/js/src/common.js b/js/src/common.js index bded22c..f31aa9f 100644 --- a/js/src/common.js +++ b/js/src/common.js @@ -34,15 +34,7 @@ export const processTables = (to_restore, tables, workspace, theme) => { const sortedTables = Object.keys(tables); sortedTables.sort(); - const allTables = []; - - sortedTables.forEach((name) => { - if (allTables.indexOf(name) < 0) { - allTables.push(name); - } - }); - - allTables.forEach((tableName, index) => { + sortedTables.forEach((tableName, index) => { const { table } = tables[tableName]; const { schema } = tables[tableName]; @@ -58,8 +50,6 @@ export const processTables = (to_restore, tables, workspace, theme) => { sort: [["timestamp", "desc"]], theme: theme === "dark" ? "Pro Dark" : "Pro Light", }; - // include all columns except id by default - viewer_config.columns = Object.keys(schema).filter((col) => col !== "id"); if (tableName === "my_bad_struct") { viewer_config.group_by = [ @@ -67,15 +57,6 @@ export const processTables = (to_restore, tables, workspace, theme) => { "group_by_col_b", "group_by_col_c", ]; - viewer_config.columns = Object.keys(schema).filter( - (col) => - ![ - "id", - "group_by_col_a", - "group_by_col_b", - "group_by_col_c", - ].includes(col), - ); } // groupby last for all by default viewer_config.aggregates = Object.keys(schema).reduce((attrs, key) => {