Skip to content

Commit 86dc188

Browse files
committed
fix: only print the base keys for the first row of a SOQL query with subqueries, like CLI plugins-data
1 parent ecc4f03 commit 86dc188

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

packages/salesforcedx-vscode-soql/src/commands/dataQuery.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ const isSubQueryResult = (
189189

190190
/**
191191
* Flattens a record into one or more rows.
192-
* Sub-query results are expanded: each sub-record produces a separate output row
193-
* that repeats the parent fields (denormalized, like a JOIN).
192+
* Sub-query results are expanded: each sub-record produces a separate output row.
193+
* Parent fields are shown only on the first child row; subsequent rows leave them blank,
194+
* matching the Salesforce CLI display style.
194195
* When a sub-query has no records the parent row is still emitted with empty sub-columns.
195196
*/
196197
const flattenRecord = (record: Record<string, unknown>): Record<string, unknown>[] => {
@@ -245,7 +246,20 @@ const flattenRecord = (record: Record<string, unknown>): Record<string, unknown>
245246
}
246247
rows = next;
247248
}
248-
return rows;
249+
250+
// Blank out parent fields on all rows after the first, matching the Salesforce CLI
251+
// display style where repeated parent values are omitted for readability.
252+
const baseKeys = Object.keys(baseRow);
253+
return rows.map((row, i) => {
254+
if (i === 0 || baseKeys.length === 0) {
255+
return row;
256+
}
257+
const blanked = { ...row };
258+
for (const key of baseKeys) {
259+
blanked[key] = '';
260+
}
261+
return blanked;
262+
});
249263
};
250264

251265
/**

packages/salesforcedx-vscode-soql/test/jest/commands/dataQuery.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,8 @@ describe('DataQuery Pure Functions', () => {
471471
expect(output).toContain('Con1');
472472
expect(output).toContain('003b');
473473
expect(output).toContain('Con2');
474-
// Parent fields repeat on each row
475-
expect(output.match(/001Rt00001iD52NIAS/g)?.length).toBe(2);
474+
// Parent fields appear only on the first child row
475+
expect(output.match(/001Rt00001iD52NIAS/g)?.length).toBe(1);
476476
// No leftover internal sub-query fields
477477
expect(output).not.toContain('Contacts.totalSize');
478478
expect(output).not.toContain('Contacts.done');

0 commit comments

Comments
 (0)