Skip to content

Commit

Permalink
Allow Cube Query to opt-out of flattening redundant children (#3867)
Browse files Browse the repository at this point in the history
* Allow Cube Query to opt-out of flattening redundant children

* Rename flat to `omitRedundantNodes`
  • Loading branch information
TomTirapani authored Dec 24, 2024
1 parent 99cf43a commit 5fb6b28
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
11 changes: 11 additions & 0 deletions data/cube/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export interface QueryConfig {
/** True to include leaf nodes in return.*/
includeLeaves?: boolean;

/**
* True (default) to recursively omit single-child parents in the hierarchy.
* Apps can implement further omit logic using `omitFn`.
*/
omitRedundantNodes?: boolean;

/**
* Optional function to be called for each aggregate node to determine if it should be "locked",
* preventing drill-down into its children. Defaults to Cube.lockFn.
Expand Down Expand Up @@ -79,6 +85,7 @@ export class Query {
readonly filter: Filter;
readonly includeRoot: boolean;
readonly includeLeaves: boolean;
readonly omitRedundantNodes: boolean;
readonly cube: Cube;
readonly lockFn: LockFn;
readonly bucketSpecFn: BucketSpecFn;
Expand All @@ -93,6 +100,7 @@ export class Query {
filter = null,
includeRoot = false,
includeLeaves = false,
omitRedundantNodes = true,
lockFn = cube.lockFn,
bucketSpecFn = cube.bucketSpecFn,
omitFn = cube.omitFn
Expand All @@ -102,6 +110,7 @@ export class Query {
this.dimensions = this.parseDimensions(dimensions);
this.includeRoot = includeRoot;
this.includeLeaves = includeLeaves;
this.omitRedundantNodes = omitRedundantNodes;
this.filter = parseFilter(filter);
this.lockFn = lockFn;
this.bucketSpecFn = bucketSpecFn;
Expand All @@ -117,6 +126,7 @@ export class Query {
filter: this.filter,
includeRoot: this.includeRoot,
includeLeaves: this.includeLeaves,
omitRedundantNodes: this.omitRedundantNodes,
lockFn: this.lockFn,
bucketSpecFn: this.bucketSpecFn,
omitFn: this.omitFn,
Expand Down Expand Up @@ -153,6 +163,7 @@ export class Query {
this.cube === other.cube &&
this.includeRoot === other.includeRoot &&
this.includeLeaves === other.includeLeaves &&
this.omitRedundantNodes === other.omitRedundantNodes &&
this.bucketSpecFn == other.bucketSpecFn &&
this.omitFn == other.omitFn &&
this.lockFn == other.lockFn
Expand Down
14 changes: 8 additions & 6 deletions data/cube/row/BaseRow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ export abstract class BaseRow {

// 3a) Before attaching examine that we don't have a chain of redundant nodes
// (not sure if loop needed -- are these redundant relations transitive?)
while (dataChildren?.length === 1) {
const childRow = dataChildren[0]._meta;
if (this.isRedundantChild(this, childRow)) {
dataChildren = childRow.data.children;
} else {
break;
if (view.query.omitRedundantNodes) {
while (dataChildren?.length === 1) {
const childRow = dataChildren[0]._meta;
if (this.isRedundantChild(this, childRow)) {
dataChildren = childRow.data.children;
} else {
break;
}
}
}

Expand Down

0 comments on commit 5fb6b28

Please sign in to comment.