diff --git a/packages/datalib/src/PerspectiveTreeNode.ts b/packages/datalib/src/PerspectiveTreeNode.ts index 3d0f76a1..a98cd57e 100644 --- a/packages/datalib/src/PerspectiveTreeNode.ts +++ b/packages/datalib/src/PerspectiveTreeNode.ts @@ -139,6 +139,12 @@ export abstract class PerspectiveTreeNode { // return this.defaultChecked; return false; } + get isSecondaryChecked() { + return false; + } + get secondaryCheckable() { + return false; + } get columnTitle() { return this.title; } @@ -192,6 +198,8 @@ export abstract class PerspectiveTreeNode { // } } + toggleSecondaryChecked(value?: boolean) {} + createReferenceConfigColumns(): PerspectiveReferenceConfig['columns'] { return null; } @@ -531,6 +539,37 @@ export class PerspectiveTableColumnNode extends PerspectiveTreeNode { return !!this.parentNode?.parentNode?.hasTableCode(this.tableCode); } + get isSecondaryChecked() { + return super.isChecked; + } + get isChecked() { + if (this.foreignKey) return !!this.config.nodes?.find(x => x.designerId == this.designerId)?.isNodeChecked; + return super.isChecked; + } + 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 + ), + })); + } else { + super.toggleChecked(value); + } + } + toggleSecondaryChecked(value?: boolean) { + super.toggleChecked(value == null ? !this.isSecondaryChecked : value); + } + generateChildNodes(): PerspectiveTreeNode[] { if (!this.foreignKey) return []; const tbl = this?.db?.tables?.find( diff --git a/packages/web/src/designer/DesignerTable.svelte b/packages/web/src/designer/DesignerTable.svelte index e1e3738b..bb11e0cb 100644 --- a/packages/web/src/designer/DesignerTable.svelte +++ b/packages/web/src/designer/DesignerTable.svelte @@ -236,7 +236,14 @@ >
{#if settings?.canCheckTables} - + { + if (settings?.setTableChecked) { + settings?.setTableChecked(designerId, e.target.checked); + } + }} + /> {/if} {alias || pureName} diff --git a/packages/web/src/perspectives/PerspectiveDesigner.svelte b/packages/web/src/perspectives/PerspectiveDesigner.svelte index 5e0da8fb..ae023b66 100644 --- a/packages/web/src/perspectives/PerspectiveDesigner.svelte +++ b/packages/web/src/perspectives/PerspectiveDesigner.svelte @@ -108,6 +108,20 @@ ), })); }, + isTableChecked: designerId => config.nodes?.find(x => x.designerId == designerId)?.isNodeChecked, + setTableChecked: (designerId, value) => { + onChange(cfg => ({ + ...cfg, + nodes: cfg.nodes.map(node => + node.designerId == designerId + ? { + ...node, + isNodeChecked: value, + } + : node + ), + })); + }, }} referenceComponent={QueryDesignerReference} value={createDesignerModel(config, dbInfos)} diff --git a/packages/web/src/perspectives/PerspectiveNodeRow.svelte b/packages/web/src/perspectives/PerspectiveNodeRow.svelte index 7a7b2b29..1675321d 100644 --- a/packages/web/src/perspectives/PerspectiveNodeRow.svelte +++ b/packages/web/src/perspectives/PerspectiveNodeRow.svelte @@ -52,6 +52,22 @@ }} /> + {#if node.secondaryCheckable} + { + e.stopPropagation(); + }} + on:mousedown={e => { + e.stopPropagation(); + }} + on:change={() => { + node.toggleSecondaryChecked(); + }} + /> + {/if} + {node.title}