diff --git a/packages/datalib/src/PerspectiveDisplay.ts b/packages/datalib/src/PerspectiveDisplay.ts index ad4228cd..692c478f 100644 --- a/packages/datalib/src/PerspectiveDisplay.ts +++ b/packages/datalib/src/PerspectiveDisplay.ts @@ -125,21 +125,14 @@ export class PerspectiveDisplay { fillColumns(children: PerspectiveTreeNode[], parentNodes: PerspectiveTreeNode[]) { for (const child of children) { - if (child.isChecked) { + if (child.isCheckedColumn || child.isCheckedNode) { this.processColumn(child, parentNodes); } } } processColumn(node: PerspectiveTreeNode, parentNodes: PerspectiveTreeNode[]) { - if (node.isExpandable) { - const countBefore = this.columns.length; - this.fillColumns(node.childNodes, [...parentNodes, node]); - - if (this.columns.length > countBefore) { - this.columns[countBefore].colSpanAtLevel[parentNodes.length] = this.columns.length - countBefore; - } - } else { + if (node.isCheckedColumn) { const column = new PerspectiveDisplayColumn(this); column.title = node.columnTitle; column.dataField = node.dataField; @@ -149,6 +142,15 @@ export class PerspectiveDisplay { column.dataNode = node; this.columns.push(column); } + + if (node.isExpandable && node.isCheckedNode) { + const countBefore = this.columns.length; + this.fillColumns(node.childNodes, [...parentNodes, node]); + + if (this.columns.length > countBefore) { + this.columns[countBefore].colSpanAtLevel[parentNodes.length] = this.columns.length - countBefore; + } + } } findColumnIndexFromNode(node: PerspectiveTreeNode) { @@ -165,8 +167,8 @@ export class PerspectiveDisplay { collectRows(sourceRows: any[], nodes: PerspectiveTreeNode[]): CollectedPerspectiveDisplayRow[] { // console.log('********** COLLECT ROWS', sourceRows); - const columnNodes = nodes.filter(x => x.isChecked && !x.isExpandable); - const treeNodes = nodes.filter(x => x.isChecked && x.isExpandable); + const columnNodes = nodes.filter(x => x.isCheckedColumn); + const treeNodes = nodes.filter(x => x.isCheckedNode); // console.log('columnNodes', columnNodes); // console.log('treeNodes', treeNodes); diff --git a/packages/datalib/src/PerspectiveTreeNode.ts b/packages/datalib/src/PerspectiveTreeNode.ts index a98cd57e..c0c6dea9 100644 --- a/packages/datalib/src/PerspectiveTreeNode.ts +++ b/packages/datalib/src/PerspectiveTreeNode.ts @@ -133,12 +133,16 @@ export abstract class PerspectiveTreeNode { get isExpanded() { return this.parentNodeConfig?.expandedColumns?.includes(this.codeName); } - get isChecked() { + get isCheckedColumn() { if (this.parentNodeConfig?.checkedColumns?.includes(this.codeName)) return true; - // if (this.parentNodeConfig?.uncheckedColumns?.includes(this.codeName)) return false; - // return this.defaultChecked; return false; } + get isChecked() { + return this.isCheckedColumn; + } + get isCheckedNode() { + return !!this.config.nodes?.find(x => x.designerId == this.designerId)?.isNodeChecked; + } get isSecondaryChecked() { return false; } @@ -198,6 +202,20 @@ export abstract class PerspectiveTreeNode { // } } + toggleCheckedNode(value?: boolean) { + this.setConfig(cfg => ({ + ...cfg, + nodes: cfg.nodes.map(node => + node.designerId == this.designerId + ? { + ...node, + isNodeChecked: value == null ? !node.isNodeChecked : value, + } + : node + ), + })); + } + toggleSecondaryChecked(value?: boolean) {} createReferenceConfigColumns(): PerspectiveReferenceConfig['columns'] { @@ -540,28 +558,18 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode { } get isSecondaryChecked() { - return super.isChecked; + return super.isCheckedColumn; } get isChecked() { - if (this.foreignKey) return !!this.config.nodes?.find(x => x.designerId == this.designerId)?.isNodeChecked; - return super.isChecked; + if (this.foreignKey) return this.isCheckedNode; + return super.isCheckedColumn; } get secondaryCheckable() { return !!this.foreignKey; } toggleChecked(value?: boolean) { if (this.foreignKey) { - this.setConfig(cfg => ({ - ...cfg, - nodes: cfg.nodes.map(node => - node.designerId == this.designerId - ? { - ...node, - isNodeChecked: value == null ? !node.isNodeChecked : value, - } - : node - ), - })); + this.toggleCheckedNode(value); } else { super.toggleChecked(value); } @@ -855,6 +863,14 @@ export class PerspectiveTableReferenceNode extends PerspectiveTableNode { return super.codeName; } + get isChecked() { + return this.isCheckedNode; + } + + toggleChecked(value?: boolean) { + this.toggleCheckedNode(value); + } + getParentJoinCondition(alias: string, parentAlias: string): Condition[] { if (!this.foreignKey) return []; return this.foreignKey.columns.map(column => {