diff --git a/packages/obc/src/components/tables/ElementProperties/src/template.ts b/packages/obc/src/components/tables/ElementProperties/src/template.ts index 735b761..64f32df 100644 --- a/packages/obc/src/components/tables/ElementProperties/src/template.ts +++ b/packages/obc/src/components/tables/ElementProperties/src/template.ts @@ -373,15 +373,7 @@ const computeTableData = async ( return rows; }; -const table = document.createElement("bim-table"); -table.columns = [{ name: "Name", width: "12rem" }]; -table.headersHidden = true; -table.addEventListener("cellcreated", ({ detail }) => { - const { cell } = detail; - if (cell.column === "Name" && !("Value" in cell.rowData)) { - cell.style.gridColumn = "1 / -1"; - } -}); +let table: BUI.Table; /** * Heloooooooooo @@ -389,6 +381,18 @@ table.addEventListener("cellcreated", ({ detail }) => { export const elementPropertiesTemplate = (state: ElementPropertiesUIState) => { const { components, fragmentIdMap } = state; + if (!table) { + table = document.createElement("bim-table"); + table.columns = [{ name: "Name", width: "12rem" }]; + table.headersHidden = true; + table.addEventListener("cellcreated", ({ detail }) => { + const { cell } = detail; + if (cell.column === "Name" && !("Value" in cell.rowData)) { + cell.style.gridColumn = "1 / -1"; + } + }); + } + computeTableData(components, fragmentIdMap).then( (data) => (table.data = data), ); diff --git a/packages/obc/src/components/tables/RelationsTree/src/template.ts b/packages/obc/src/components/tables/RelationsTree/src/template.ts index d8356e3..cdb2fea 100644 --- a/packages/obc/src/components/tables/RelationsTree/src/template.ts +++ b/packages/obc/src/components/tables/RelationsTree/src/template.ts @@ -102,17 +102,7 @@ const computeRowData = async ( return rows; }; -const table = document.createElement("bim-table"); -table.hiddenColumns = ["modelID", "expressID", "relations"]; -table.columns = ["Entity", "Name"]; -table.headersHidden = true; - -table.addEventListener("cellcreated", ({ detail }) => { - const { cell } = detail; - if (cell.column === "Entity" && !("Name" in cell.rowData)) { - cell.style.gridColumn = "1 / -1"; - } -}); +let table: BUI.Table; const getRowFragmentIdMap = (components: OBC.Components, row: BUI.TableRow) => { const fragments = components.get(OBC.FragmentsManager); @@ -141,10 +131,19 @@ export const relationsTreeTemplate = (state: RelationsTreeUIState) => { expressID, } = state; - const _inverseAttributes: OBC.InverseAttribute[] = inverseAttributes ?? [ - "IsDecomposedBy", - "ContainsElements", - ]; + if (!table) { + table = document.createElement("bim-table"); + table.hiddenColumns = ["modelID", "expressID", "relations"]; + table.columns = ["Entity", "Name"]; + table.headersHidden = true; + + table.addEventListener("cellcreated", ({ detail }) => { + const { cell } = detail; + if (cell.column === "Entity" && !("Name" in cell.rowData)) { + cell.style.gridColumn = "1 / -1"; + } + }); + } table.addEventListener("rowcreated", (e) => { e.stopImmediatePropagation(); @@ -181,6 +180,11 @@ export const relationsTreeTemplate = (state: RelationsTreeUIState) => { }; }); + const _inverseAttributes: OBC.InverseAttribute[] = inverseAttributes ?? [ + "IsDecomposedBy", + "ContainsElements", + ]; + computeRowData(components, models, _inverseAttributes, expressID).then( (data) => (table.data = data), );