perspective: view fix, UX

This commit is contained in:
Jan Prochazka 2022-08-29 22:37:04 +02:00
parent c1627b8546
commit e64d013fee
3 changed files with 35 additions and 13 deletions

View File

@ -106,10 +106,11 @@ export function createPerspectiveNodeConfig(name: { schemaName?: string; pureNam
expandedColumns: [], expandedColumns: [],
checkedColumns: [], checkedColumns: [],
// uncheckedColumns: [],
sort: [], sort: [],
filters: {}, filters: {},
isNodeChecked: true,
}; };
return node; return node;
@ -117,7 +118,6 @@ export function createPerspectiveNodeConfig(name: { schemaName?: string; pureNam
export function createPerspectiveConfig(rootObject: { schemaName?: string; pureName: string }): PerspectiveConfig { export function createPerspectiveConfig(rootObject: { schemaName?: string; pureName: string }): PerspectiveConfig {
const rootNode = createPerspectiveNodeConfig(rootObject); const rootNode = createPerspectiveNodeConfig(rootObject);
rootNode.isNodeChecked = true;
return { return {
nodes: [rootNode], nodes: [rootNode],
references: [], references: [],

View File

@ -6,7 +6,7 @@ import { PerspectiveTableNode } from './PerspectiveTreeNode';
function getPerspectiveDefaultColumns( function getPerspectiveDefaultColumns(
table: TableInfo | ViewInfo, table: TableInfo | ViewInfo,
db: DatabaseInfo, db: DatabaseInfo,
circularColumns: string[] circularColumns?: string[]
): [string[], string[]] { ): [string[], string[]] {
const columns = table.columns.map(x => x.columnName); const columns = table.columns.map(x => x.columnName);
const predicates = [ const predicates = [
@ -29,6 +29,7 @@ function getPerspectiveDefaultColumns(
if (col) return [[col], null]; if (col) return [[col], null];
} }
if (circularColumns) {
const keyPredicates = [ const keyPredicates = [
x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1 && !circularColumns.includes(x), x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1 && !circularColumns.includes(x),
x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1, x => findForeignKeyForColumn(table as TableInfo, x)?.columns?.length == 1,
@ -38,6 +39,7 @@ function getPerspectiveDefaultColumns(
const col = columns.find(predicate); const col = columns.find(predicate);
if (col) return [null, [col]]; if (col) return [null, [col]];
} }
}
return [[columns[0]], null]; return [[columns[0]], null];
} }
@ -108,7 +110,24 @@ function processPerspectiveDefaultColunnsStep(
if (table || view) { if (table || view) {
const treeNode = root.findNodeByDesignerId(node.designerId); 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 circularColumns = treeNode.childNodes.filter(x => x.isCircular).map(x => x.columnName);
const [defaultColumns, defaultRefs] = getPerspectiveDefaultColumns(table || view, db, circularColumns); const [defaultColumns, defaultRefs] = getPerspectiveDefaultColumns(table || view, db, circularColumns);

View File

@ -32,11 +32,14 @@
const table = dbInfos?.[node.conid || conid]?.[node.database || database]?.tables?.find( const table = dbInfos?.[node.conid || conid]?.[node.database || database]?.tables?.find(
x => x.pureName == node.pureName && x.schemaName == node.schemaName 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; const { designerId } = node;
return { return {
...table, ...(table || view),
left: node?.position?.x || 0, left: node?.position?.x || 0,
top: node?.position?.y || 0, top: node?.position?.y || 0,
alias: node.alias, alias: node.alias,