Skip to content

Commit

Permalink
feat: update new table
Browse files Browse the repository at this point in the history
  • Loading branch information
soridalac committed Oct 24, 2024
1 parent 02e3c7d commit 3cb702c
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 66 deletions.
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
16 changes: 9 additions & 7 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 @@ -72,12 +72,14 @@ export class OrgShapeDeleteCommand extends SfCommand<OrgShapeDeleteResult | unde
this.styledHeader('Partial Success');
this.logSuccess(messages.getMessage('humanSuccess', [orgId]));
this.log('');
this.styledHeader('Failures');
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' },
],
title: 'Failures',
});
} else if (deleteRes.failures.length === deleteRes.shapeIds.length) {
setExitCode(1);
} else {
Expand Down
36 changes: 16 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 @@ -51,13 +38,22 @@ export class OrgShapeListCommand extends SfCommand<OrgShapeListResult[]> {
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) => ({
ALIAS: shape.alias ?? '',
USERNAME: shape.username,
'ORG ID': shape.orgId,
'Shape ID': shape.shapeId,
'CREATED BY': shape.createdBy,
'CREATED DATE': shape.createdDate,
...(shape.status === 'Active'
? {
STATUS: StandardColors.success(shape.status),
}
: {}),
})),
title: 'Org Shapes',
});
return orgShapes;
}
}
49 changes: 16 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,26 @@ export const printSingleRecordTable = (snapshotRecord: OrgSnapshot): void => {
}))
// null/undefined becomes empty string
.map((row) => (row.Value ? row : { ...row, Value: '' })),
{ 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) => ({
Id: s.Id,
'Snapshot Name': s.SnapshotName,
Status: s.Status,
'Source Org Id': s.SourceOrg,
CreatedDate: s.CreatedDate,
'Last Modified Date': s.LastModifiedDate,
'Expiration Date': s.ExpirationDate ? new Date(s.ExpirationDate).toLocaleDateString() : '',
})),
title: `Org Snapshots [${snapshotRecords.length}]`,
overflow: 'wrap',
});
};
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

0 comments on commit 3cb702c

Please sign in to comment.