diff --git a/packages/datalib/src/PerspectiveConfig.ts b/packages/datalib/src/PerspectiveConfig.ts index e117cf94b..758508857 100644 --- a/packages/datalib/src/PerspectiveConfig.ts +++ b/packages/datalib/src/PerspectiveConfig.ts @@ -106,10 +106,11 @@ export function createPerspectiveNodeConfig(name: { schemaName?: string; pureNam expandedColumns: [], checkedColumns: [], - // uncheckedColumns: [], sort: [], filters: {}, + + isNodeChecked: true, }; return node; @@ -117,7 +118,6 @@ export function createPerspectiveNodeConfig(name: { schemaName?: string; pureNam export function createPerspectiveConfig(rootObject: { schemaName?: string; pureName: string }): PerspectiveConfig { const rootNode = createPerspectiveNodeConfig(rootObject); - rootNode.isNodeChecked = true; return { nodes: [rootNode], references: [], diff --git a/packages/datalib/src/processPerspectiveDefaultColunns.ts b/packages/datalib/src/processPerspectiveDefaultColunns.ts index ba9917fc0..6eb5f15a7 100644 --- a/packages/datalib/src/processPerspectiveDefaultColunns.ts +++ b/packages/datalib/src/processPerspectiveDefaultColunns.ts @@ -6,7 +6,7 @@ import { PerspectiveTableNode } from './PerspectiveTreeNode'; function getPerspectiveDefaultColumns( table: TableInfo | ViewInfo, db: DatabaseInfo, - circularColumns: string[] + circularColumns?: string[] ): [string[], string[]] { const columns = table.columns.map(x => x.columnName); const predicates = [ @@ -29,14 +29,16 @@ function getPerspectiveDefaultColumns( if (col) return [[col], null]; } - const keyPredicates = [ - x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1 && !circularColumns.includes(x), - x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1, - ]; + if (circularColumns) { + const keyPredicates = [ + x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1 && !circularColumns.includes(x), + x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1, + ]; - for (const predicate of keyPredicates) { - const col = columns.find(predicate); - if (col) return [null, [col]]; + for (const predicate of keyPredicates) { + const col = columns.find(predicate); + if (col) return [null, [col]]; + } } return [[columns[0]], null]; @@ -108,7 +110,24 @@ function processPerspectiveDefaultColunnsStep( if (table || view) { const treeNode = root.findNodeByDesignerId(node.designerId); - if (!treeNode) continue; + + if (!treeNode) { + const [defaultColumns] = getPerspectiveDefaultColumns(table || view, db, null); + + return { + ...config, + nodes: config.nodes.map(n => + n.designerId == node.designerId + ? { + ...n, + defaultColumnsProcessed: true, + checkedColumns: defaultColumns, + } + : n + ), + }; + } + const circularColumns = treeNode.childNodes.filter(x => x.isCircular).map(x => x.columnName); const [defaultColumns, defaultRefs] = getPerspectiveDefaultColumns(table || view, db, circularColumns); diff --git a/packages/web/src/perspectives/PerspectiveDesigner.svelte b/packages/web/src/perspectives/PerspectiveDesigner.svelte index bdc126077..d16cd9345 100644 --- a/packages/web/src/perspectives/PerspectiveDesigner.svelte +++ b/packages/web/src/perspectives/PerspectiveDesigner.svelte @@ -32,11 +32,14 @@ const table = dbInfos?.[node.conid || conid]?.[node.database || database]?.tables?.find( x => x.pureName == node.pureName && x.schemaName == node.schemaName ); - if (!table) return null; + const view = dbInfos?.[node.conid || conid]?.[node.database || database]?.views?.find( + x => x.pureName == node.pureName && x.schemaName == node.schemaName + ); + if (!table && !view) return null; const { designerId } = node; return { - ...table, + ...(table || view), left: node?.position?.x || 0, top: node?.position?.y || 0, alias: node.alias,