Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

W-16736203 Slac/table #736

Merged
merged 8 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@oclif/core": "^4",
"@salesforce/core": "^8.6.1",
"@salesforce/kit": "^3.2.3",
"@salesforce/sf-plugins-core": "^11.3.12",
"@salesforce/sf-plugins-core": "^12.0.7",
"change-case": "^5.4.4"
},
"devDependencies": {
Expand Down
14 changes: 8 additions & 6 deletions src/commands/org/delete/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const messages = Messages.loadMessages('@salesforce/plugin-signups', 'shape.dele

export type OrgShapeDeleteResult = {
orgId: string;
} & DeleteAllResult
} & DeleteAllResult;

export class OrgShapeDeleteCommand extends SfCommand<OrgShapeDeleteResult | undefined> {
public static readonly summary = messages.getMessage('summary');
Expand Down Expand Up @@ -73,11 +73,13 @@ export class OrgShapeDeleteCommand extends SfCommand<OrgShapeDeleteResult | unde
this.logSuccess(messages.getMessage('humanSuccess', [orgId]));
this.log('');
this.styledHeader('Failures');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can move this styledHeader into the title: property - check for all tables

const columns = {
shapeId: { header: 'Shape ID' },
message: { header: 'Error Message' },
};
this.table(deleteRes.failures, columns);
this.table({
data: deleteRes.failures,
columns: [
{ key: 'shapeId', name: 'Shape ID' },
{ key: 'message', name: 'Error Message' },
],
});
} else if (deleteRes.failures.length === deleteRes.shapeIds.length) {
setExitCode(1);
} else {
Expand Down
25 changes: 5 additions & 20 deletions src/commands/org/list/shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ import utils, { OrgShapeListResult } from '../../../shared/orgShapeListUtils.js'
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-signups', 'shape.list');

// default columns for the shape list
const orgShapeColumns = {
alias: {
header: 'ALIAS',
get: (data: OrgShapeListResult): string => data.alias ?? '',
},
username: { header: 'USERNAME' },
orgId: { header: 'ORG ID' },
status: { header: 'SHAPE STATUS' },
createdBy: { header: 'CREATED BY' },
createdDate: { header: 'CREATED DATE' },
};

export class OrgShapeListCommand extends SfCommand<OrgShapeListResult[]> {
public static readonly summary = messages.getMessage('summary');
public static readonly description = messages.getMessage('description');
Expand All @@ -50,14 +37,12 @@ export class OrgShapeListCommand extends SfCommand<OrgShapeListResult[]> {
this.info(messages.getMessage('noOrgShapes'));
return orgShapes;
}

this.styledHeader('Org Shapes');
this.table(
orgShapes.map((shape) =>
shape.status === 'Active' ? { ...shape, status: StandardColors.success(shape.status) } : shape
),
orgShapeColumns
);
this.table({
data: orgShapes.map((shape) => ({
...(shape.status === 'Active' ? { ...shape, status: StandardColors.success(shape.status) } : shape),
})),
});
return orgShapes;
}
}
51 changes: 18 additions & 33 deletions src/shared/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,6 @@ const dateTimeFormatter = (dateString?: string): string =>
})
: '';

const rowDateTimeFormatter = (row: OrgSnapshot, field: keyof OrgSnapshot): string => dateTimeFormatter(row[field]);

const ORG_SNAPSHOT_COLUMNS = {
Id: {},
SnapshotName: { header: 'Snapshot Name' },
Status: {},
SourceOrg: { header: 'Source Org Id' },
CreatedDate: {
header: 'Created Date',
get: (row: OrgSnapshot): string => rowDateTimeFormatter(row, 'CreatedDate'),
},
LastModifiedDate: {
header: 'Last Modified Date',
get: (row: OrgSnapshot): string => rowDateTimeFormatter(row, 'LastModifiedDate'),
},
ExpirationDate: {
header: 'Expiration Date',
get: (row: OrgSnapshot): string => (row.ExpirationDate ? new Date(row.ExpirationDate).toLocaleDateString() : ''),
},
};

export const invalidTypeErrorHandler = (e: unknown): never => {
if (e instanceof Error && e.name === 'INVALID_TYPE') {
e.message = messages.getMessage('snapshotNotEnabled');
Expand Down Expand Up @@ -104,8 +83,8 @@ export const queryByNameOrId = async (conn: Connection, nameOrId: string): Promi
};

export const printSingleRecordTable = (snapshotRecord: OrgSnapshot): void => {
new Ux().table(
Object.entries(snapshotRecord)
new Ux().table({
data: Object.entries(snapshotRecord)
.filter(([key]) => key !== 'attributes')
// remove empty error field
.filter(([key, value]) => key !== 'Error' || typeof value === 'string')
Expand All @@ -117,22 +96,28 @@ export const printSingleRecordTable = (snapshotRecord: OrgSnapshot): void => {
}))
// null/undefined becomes empty string
.map((row) => (row.Value ? row : { ...row, Value: '' })),
{ Name: {}, Value: {} }
);
columns: ['Name', 'Value'],
});
};

export const printRecordTable = (snapshotRecords: OrgSnapshot[]): void => {
if (snapshotRecords.length === 0) {
new Ux().log('No snapshots found');
return;
}

new Ux().table(
new Ux().table({
// we know what columns we want, so filter out the other fields
snapshotRecords.map((s) =>
Object.fromEntries(Object.entries(s).filter(([key]) => Object.keys(ORG_SNAPSHOT_COLUMNS).includes(key)))
),
ORG_SNAPSHOT_COLUMNS,
{ title: `Org Snapshots [${snapshotRecords.length}]`, 'no-truncate': true }
);
data: snapshotRecords.map((s) => ({
// ...Object.fromEntries(Object.entries(s).filter(([key]) => Object.keys(s).includes(key))),
Id: s.Id,
'Snapshot Name': s.SnapshotName,
Status: s.Status,
'Source Org Id': s.SourceOrg,
'Created Date': dateTimeFormatter(s.CreatedDate),
'Last Modified Date': dateTimeFormatter(s.LastModifiedDate),
'Expiration Date': s.ExpirationDate ? new Date(s.ExpirationDate).toLocaleDateString() : '',
})),
title: `Org Snapshots [${snapshotRecords.length}]`,
overflow: 'wrap',
});
};
10 changes: 6 additions & 4 deletions test/shape/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,12 @@ describe('org:shape:delete', () => {
expect(uxLogStub.getCalls().some((c) => c.args[0] === 'Successfully deleted org shape for 00D000000000000004.'));
expect(uxLogStub.getCalls().some((c) => c.args[0] === ''));
expect(uxStyledHeaderStub.secondCall.args[0]).to.equal('Failures');
expect(uxTableStub.firstCall.args[0]).to.deep.equal([{ shapeId: '3SR000000000124', message: 'MALFORMED ID' }]);
expect(uxTableStub.firstCall.args[1]).to.deep.equal({
shapeId: { header: 'Shape ID' },
message: { header: 'Error Message' },
expect(uxTableStub.firstCall.args[0]).to.deep.equal({
data: [{ shapeId: '3SR000000000124', message: 'MALFORMED ID' }],
columns: [
{ key: 'shapeId', name: 'Shape ID' },
{ key: 'message', name: 'Error Message' },
],
});
});

Expand Down
12 changes: 6 additions & 6 deletions test/shape/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ describe('org:shape:list', () => {
await command.run();
expect(uxLogStub.notCalled).to.be.true;
expect(uxStyledHeaderStub.firstCall.args[0]).to.equal('Org Shapes');
expect((uxTableStub.firstCall.args[0] as OrgShapeListResult[]).length).to.equal(2);
expect(uxTableStub.firstCall.args[0]).to.deep.equal(
shapes.map((shape) =>
shape.status === 'Active' ? { ...shape, status: StandardColors.success(shape.status) } : shape
)
);
expect((uxTableStub.firstCall.args[0] as { data: OrgShapeListResult[] }).data.length).to.equal(2);
expect(uxTableStub.firstCall.args[0]).to.deep.equal({
data: shapes.map((shape) => ({
...(shape.status === 'Active' ? { ...shape, status: StandardColors.success(shape.status) } : shape),
})),
});
});

it('no devhub org', async () => {
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"extends": "@salesforce/dev-config/tsconfig-strict-esm",
"compilerOptions": {
"outDir": "lib",
"baseUrl": ".",
"skipLibCheck": true,
"strictNullChecks": true,
"rootDir": "src",
"lib": ["es2020"]
Expand Down
Loading