Skip to content

Commit d2383bc

Browse files
authored
Merge pull request #1243 from salesforcecli/mdonnalley/new-table
feat: use new table
2 parents ceb1b5b + d554647 commit d2383bc

File tree

13 files changed

+142
-140
lines changed

13 files changed

+142
-140
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@oclif/multi-stage-output": "^0.7.7",
1010
"@salesforce/core": "^8.6.1",
1111
"@salesforce/kit": "^3.2.3",
12-
"@salesforce/sf-plugins-core": "^11.3.12",
12+
"@salesforce/sf-plugins-core": "^12.0.6",
1313
"@salesforce/source-deploy-retrieve": "^12.8.1",
1414
"ansis": "^3.2.0",
1515
"change-case": "^5.4.4",

src/commands/force/org/create.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,12 @@ export class Create extends SfCommand<CreateResult> {
190190
lifecycle.on(SandboxEvents.EVENT_RESULT, async (results: ResultEvent) => {
191191
const { sandboxReadyForUse, data } = SandboxReporter.logSandboxProcessResult(results);
192192
this.log(sandboxReadyForUse);
193-
this.styledHeader('Sandbox Org Creation Status');
194-
this.table(data, {
195-
key: { header: 'Name' },
196-
value: { header: 'Value' },
193+
this.table({
194+
data,
195+
columns: [{ key: 'key', name: 'Name' }, 'value'],
196+
title: 'Sandbox Org Creation Status',
197197
});
198+
198199
if (results.sandboxRes?.authUserName) {
199200
if (this.flags.setalias) {
200201
const stateAggregator = await StateAggregator.getInstance();

src/commands/org/create/sandbox.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,13 @@ export default class CreateSandbox extends SandboxCommandBase<SandboxCommandResp
237237
if (this.flags['no-prompt'] || this.jsonEnabled()) return;
238238

239239
const data = Object.entries(sandboxReq).map(([key, value]) => ({ key, value }));
240-
this.styledHeader('Config Sandbox Request');
241-
this.table(data, {
242-
key: { header: 'Field' },
243-
value: { header: 'Value' },
240+
this.table({
241+
data,
242+
columns: [
243+
{ key: 'key', name: 'Field' },
244+
{ key: 'value', name: 'Value' },
245+
],
246+
title: 'Config Sandbox Request',
244247
});
245248

246249
if (

src/commands/org/display.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,13 @@ export class OrgDisplayCommand extends SfCommand<OrgDisplayReturn> {
9595
value: typeof value === 'string' ? getStyledValue(key, value) : value,
9696
}));
9797

98-
this.styledHeader('Org Description');
99-
this.table(tableRows, {
100-
key: { header: 'KEY' },
101-
value: { header: 'VALUE' },
98+
this.table({
99+
data: tableRows,
100+
columns: [
101+
{ key: 'key', name: 'KEY' },
102+
{ key: 'value', name: 'VALUE' },
103+
],
104+
title: 'Org Description',
102105
});
103106
}
104107

src/commands/org/list.ts

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -189,32 +189,25 @@ Legend: ${defaultHubEmoji}=Default DevHub, ${defaultOrgEmoji}=Default Org ${
189189
.map((row) => getStyledObject(row))
190190
.map(statusToEmoji),
191191
];
192-
193-
this.table(allOrgs, {
194-
defaultMarker: {
195-
header: '',
196-
},
197-
type: {
198-
header: 'Type',
199-
},
200-
alias: {
201-
header: 'Alias',
202-
},
203-
username: { header: 'Username' },
204-
orgId: { header: 'Org ID' },
205-
...(!skipconnectionstatus ? { connectedStatus: { header: 'Status' } } : {}),
206-
...(this.flags.verbose
207-
? {
208-
instanceUrl: { header: 'Instance URL' },
209-
namespacePrefix: { header: 'Namespace' },
210-
devHubOrgId: { header: 'Dev Hub ID' },
211-
createdDate: {
212-
header: 'Created',
213-
get: (data): string => ('createdDate' in data ? data.createdDate?.split('T')?.[0] ?? '' : ''),
214-
},
215-
}
216-
: {}),
217-
expirationDate: { header: 'Expires' },
192+
this.table({
193+
data: allOrgs.map((row) => ({
194+
' ': row.defaultMarker,
195+
...('type' in row ? { Type: row.type } : {}),
196+
Alias: row.alias,
197+
Username: row.username,
198+
'Org ID': row.orgId,
199+
...(skipconnectionstatus ? {} : { Status: row.connectedStatus }),
200+
...(this.flags.verbose
201+
? {
202+
'Instance URL': row.instanceUrl,
203+
Namespace: row.namespacePrefix,
204+
...('devHubOrgId' in row ? { 'Dev Hub ID': row.devHubOrgId } : {}),
205+
...('createdDate' in row ? { Created: row.createdDate } : {}),
206+
}
207+
: {}),
208+
...('expirationDate' in row ? { Expires: row.expirationDate } : {}),
209+
})),
210+
...(this.flags.verbose ? { overflow: 'wrap' } : {}),
218211
});
219212
}
220213
}

src/commands/org/list/metadata-types.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import fs from 'node:fs';
88

99
import { Messages } from '@salesforce/core';
10-
import type { DescribeMetadataObject, DescribeMetadataResult } from '@jsforce/jsforce-node/lib/api/metadata.js';
10+
import type { DescribeMetadataResult } from '@jsforce/jsforce-node/lib/api/metadata.js';
1111
import { RegistryAccess } from '@salesforce/source-deploy-retrieve';
1212
import { Flags, loglevel, requiredOrgFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
1313

@@ -68,26 +68,21 @@ export class ListMetadataTypes extends SfCommand<DescribeMetadataResult> {
6868
await fs.promises.writeFile(flags['output-file'], JSON.stringify(describeResult, null, 2));
6969
this.logSuccess(`Wrote result file to ${flags['output-file']}.`);
7070
} else {
71-
this.table(
72-
describeResult.metadataObjects,
73-
{
74-
xmlName: { header: 'Xml Names' },
75-
childXmlNames: {
76-
header: 'Child Xml Names',
77-
get: (row: DescribeMetadataObject) =>
78-
row.childXmlNames.length ? `[ ${row.childXmlNames.join('\n')} ]` : '',
79-
},
80-
directoryName: { header: 'Directory Name' },
81-
inFolder: { header: 'In Folder' },
82-
metaFile: { header: 'Meta File' },
83-
suffix: { header: 'Suffix' },
71+
this.table({
72+
data: describeResult.metadataObjects.map((md) => ({
73+
'Xml Names': md.xmlName,
74+
'Child Xml Names': md.childXmlNames.length ? `[ ${md.childXmlNames.join('\n')} ]` : '',
75+
'Directory Name': md.directoryName,
76+
'In Folder': md.inFolder,
77+
'Meta File': md.metaFile,
78+
suffix: md.suffix,
79+
})),
80+
title: 'Metadata',
81+
overflow: 'wrap',
82+
sort: {
83+
'Xml Names': 'asc',
8484
},
85-
{
86-
'no-truncate': true,
87-
title: 'Metadata',
88-
sort: 'Xml Names',
89-
}
90-
);
85+
});
9186
this.log(`Organizational Namespace: ${describeResult.organizationNamespace}`);
9287
this.log(`Partial Save Allowed: ${describeResult.partialSaveAllowed}`);
9388
this.log(`Test Required: ${describeResult.testRequired}`);

src/commands/org/list/metadata.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,29 +62,22 @@ export class ListMetadata extends SfCommand<ListMetadataCommandResult> {
6262
fs.writeFileSync(flags['output-file'], JSON.stringify(listResult, null, 2));
6363
this.logSuccess(`Wrote result file to ${flags['output-file']}.`);
6464
} else if (listResult?.length) {
65-
this.table(
66-
listResult,
67-
{
68-
createdByName: { header: 'Created By' },
69-
createdDate: {
70-
header: 'Created Date',
71-
get: (row: FileProperties) => row.createdDate.split('T')[0],
72-
},
73-
fullName: { header: 'Full Name' },
74-
id: { header: 'Id' },
75-
lastModifiedByName: { header: 'Last Modified By' },
76-
lastModifiedDate: {
77-
header: 'Last Modified',
78-
get: (row: FileProperties) => row.createdDate.split('T')[0],
79-
},
80-
manageableState: { header: 'Manageable State' },
81-
namespacePrefix: { header: 'Namespace Prefix' },
65+
this.table({
66+
data: listResult.map((md) => ({
67+
'Created By': md.createdByName,
68+
'Created Date': md.createdDate.split('T')[0],
69+
'Full Name': md.fullName,
70+
Id: md.id,
71+
'Last Modified By': md.lastModifiedByName,
72+
'Last Modified': md.lastModifiedDate.split('T')[0],
73+
'Manageable State': md.manageableState,
74+
'Namespace Prefix': md.namespacePrefix,
75+
})),
76+
title: flags['metadata-type'],
77+
sort: {
78+
'Manageable State': 'asc',
8279
},
83-
{
84-
title: flags['metadata-type'],
85-
sort: 'Manageable State',
86-
}
87-
);
80+
});
8881
} else {
8982
this.warn(messages.getMessage('noMatchingMetadata', [flags['metadata-type'], conn.getUsername()]));
9083
}

src/commands/org/refresh/sandbox.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,14 @@ export default class RefreshSandbox extends SandboxCommandBase<SandboxCommandRes
268268
if (this.flags['no-prompt'] || this.jsonEnabled()) return;
269269

270270
const data = Object.entries(sandboxInfo).map(([key, value]) => ({ key, value: value ?? 'null' }));
271-
this.styledHeader('Config Sandbox Refresh');
272-
this.table(data, {
273-
key: { header: 'Field' },
274-
value: { header: 'Value' },
271+
this.table({
272+
data,
273+
columns: [
274+
{ key: 'key', name: 'Field' },
275+
{ key: 'value', name: 'Value' },
276+
],
277+
title: 'Config Sandbox Refresh',
275278
});
276-
277279
if (
278280
!(await this.confirm({
279281
message: messages.getMessage('isConfigurationOk'),

src/shared/sandboxCommandBase.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
SandboxUserAuthResponse,
2222
StatusEvent,
2323
} from '@salesforce/core';
24-
import { SandboxProgress, SandboxStatusData } from './sandboxProgress.js';
24+
import { SandboxProgress } from './sandboxProgress.js';
2525
import { State } from './stagedProgress.js';
2626

2727
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -206,12 +206,11 @@ export abstract class SandboxCommandBase<T> extends SfCommand<T> {
206206
): void {
207207
const sandboxProgress = this.sandboxProgress.getSandboxProgress(event);
208208
this.sandboxUsername = (event as ResultEvent).sandboxRes?.authUserName;
209-
const sandboxData = {
209+
this.sandboxProgress.statusData = {
210210
sandboxUsername: this.sandboxUsername,
211211
sandboxProgress,
212212
sandboxProcessObj: event.sandboxProcessObj,
213-
} as SandboxStatusData;
214-
this.sandboxProgress.statusData = sandboxData;
213+
};
215214
if (!isAsync) {
216215
this.spinner.status = this.sandboxProgress.formatProgressStatus();
217216
}

src/shared/sandboxProgress.ts

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77
import os from 'node:os';
8+
import { colorize } from '@oclif/core/ux';
89
import { StatusEvent, ResultEvent, SandboxProcessObject } from '@salesforce/core';
9-
import { Ux } from '@salesforce/sf-plugins-core';
1010
import { getClockForSeconds } from '../shared/timeUtils.js';
1111
import { StagedProgress } from './stagedProgress.js';
1212
import { isDefined } from './utils.js';
1313

14-
const columns: Ux.Table.Columns<{ key: string; value: string }> = {
15-
key: { header: 'Field' },
16-
value: { header: 'Value' },
17-
};
18-
19-
const ux = new Ux();
20-
2114
export type SandboxProgressData = {
2215
id: string;
2316
status: string;
@@ -73,7 +66,7 @@ export class SandboxProgress extends StagedProgress<SandboxStatusData> {
7366
}
7467

7568
public formatProgressStatus(withClock = true): string {
76-
const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj).join(os.EOL);
69+
const table = getSandboxTableAsText(undefined, this.statusData?.sandboxProcessObj);
7770
return [
7871
withClock && this.statusData
7972
? `${getClockForSeconds(this.statusData.sandboxProgress.remainingWaitTime)} until timeout. ${
@@ -123,15 +116,20 @@ export const getTableDataFromProcessObj = (
123116
...(authUserName ? [{ key: 'Authorized Sandbox Username', value: authUserName }] : []),
124117
];
125118

126-
export const getSandboxTableAsText = (sandboxUsername?: string, sandboxProgress?: SandboxProcessObject): string[] => {
119+
export const getSandboxTableAsText = (sandboxUsername?: string, sandboxProgress?: SandboxProcessObject): string => {
127120
if (!sandboxProgress) {
128-
return [];
121+
return '';
129122
}
130-
const tableRows: string[] = [];
131-
ux.table(getTableDataFromProcessObj(sandboxProgress, sandboxUsername), columns, {
132-
printLine: (s: string): void => {
133-
tableRows.push(s);
134-
},
135-
});
136-
return tableRows;
123+
124+
const data = getTableDataFromProcessObj(sandboxProgress, sandboxUsername);
125+
const longestKey = data.reduce((acc, row) => (row.key.length > acc ? row.key.length : acc), 0);
126+
const longestValue = data.reduce(
127+
(acc, row) => (row.value.toString().length > acc ? row.value.toString().length : acc),
128+
0
129+
);
130+
return [
131+
colorize('bold', `${'Field'.padEnd(longestKey)} Value`),
132+
`${'-'.repeat(longestKey)} ${'-'.repeat(longestValue)}`,
133+
...data.map((row) => `${row.key.padEnd(longestKey)} ${row.value}`),
134+
].join(os.EOL);
137135
};

0 commit comments

Comments
 (0)