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

Wr/tables #823

Merged
merged 13 commits into from
Oct 30, 2024
2 changes: 1 addition & 1 deletion messages/package_version_delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ Successfully deleted the package version with ID: %s

# humanSuccessUndelete

Successfully undeleted the package version.
Successfully undeleted the package version. %s
WillieRuemmele marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^4",
"@salesforce/core": "^8.6.1",
"@salesforce/core": "^8.6.2",
"@salesforce/kit": "^3.2.3",
"@salesforce/packaging": "^4.2.9",
"@salesforce/sf-plugins-core": "^11.3.12",
"@salesforce/packaging": "^4.2.15",
"@salesforce/sf-plugins-core": "^12.0.6",
"chalk": "^5.3.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ export class PackageCreateCommand extends SfCommand<PackageCreate> {

private display(result: PackageCreate): void {
this.styledHeader('Ids');
this.table([{ name: 'Package Id', value: result.Id }], { name: { header: 'NAME' }, value: { header: 'VALUE' } });
this.table({ data: [{ name: 'Package Id', value: result.Id }] });
Copy link
Contributor

Choose a reason for hiding this comment

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

you should use the title prop now,

this.table({
  data,
  title: 'Ids',
})

}
}
28 changes: 12 additions & 16 deletions src/commands/package/installed/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ export class PackageInstalledListCommand extends SfCommand<PackageInstalledComma
await SubscriberPackageVersion.installedList(flags['target-org'].getConnection(flags['api-version']))
).map(transformRow);

this.table(
records,
columns,

{ 'no-truncate': true }
);
this.table({
data: records,
columns: [
{ key: 'Id', name: 'ID' },
{ key: 'SubscriberPackageId', name: 'Package ID' },
{ key: 'SubscriberPackageName', name: 'Package Name' },
{ key: 'SubscriberPackageNamespace', name: 'Namespace' },
{ key: 'SubscriberPackageVersionId', name: 'Package Version ID' },
{ key: 'SubscriberPackageVersionName', name: 'Version Name' },
{ key: 'SubscriberPackageVersionNumber', name: 'Version' },
],
});

return records;
}
Expand All @@ -75,13 +81,3 @@ const transformRow = (r: InstalledPackages): PackageInstalledListResult => ({
}
: {}),
});

const columns = {
Id: { header: 'ID' },
SubscriberPackageId: { header: 'Package ID' },
SubscriberPackageName: { header: 'Package Name' },
SubscriberPackageNamespace: { header: 'Namespace' },
SubscriberPackageVersionId: { header: 'Package Version ID' },
SubscriberPackageVersionName: { header: 'Version Name' },
SubscriberPackageVersionNumber: { header: 'Version' },
};
36 changes: 16 additions & 20 deletions src/commands/package/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,26 @@ export class PackageListCommand extends SfCommand<PackageListCommandResult> {

private displayResults(results: Package2Result[], verbose = false, apiVersion: string): void {
this.styledHeader(chalk.blue(`Packages [${results.length}]`));
const columns = {
NamespacePrefix: { header: messages.getMessage('namespace') },
Name: { header: messages.getMessage('name') },
Id: { header: messages.getMessage('id') },
Alias: { header: messages.getMessage('alias') },
Description: { header: messages.getMessage('description') },
ContainerOptions: {
header: messages.getMessage('package-type'),
},

const data = results.map((r) => ({
'Namespace Prefix': r.NamespacePrefix,
Name: r.Name,
Id: r.Id,
Alias: r.Alias,
Description: r.Description,
ContainerOptions: r.ContainerOptions,
...(verbose
? {
SubscriberPackageId: { header: messages.getMessage('package-id') },
ConvertedFromPackageId: { header: messages.getMessage('convertedFromPackageId') },
IsOrgDependent: { header: messages.getMessage('isOrgDependent') },
PackageErrorUsername: { header: messages.getMessage('error-notification-username') },
CreatedBy: { header: messages.getMessage('createdBy') },
'Package Id': r.SubscriberPackageId,
'Converted From Package Id': r.ConvertedFromPackageId,
'Org-Dependent Unlocked Package': r.IsOrgDependent,
'Error Notification Username': r.PackageErrorUsername,
'Created By': r.CreatedBy,
...(parseInt(apiVersion, 10) >= 59 ? { 'App Analytics Enabled': r.AppAnalyticsEnabled } : {}),
}
: {}),
...(verbose && parseInt(apiVersion, 10) >= 59
? { AppAnalyticsEnabled: { header: messages.getMessage('app-analytics-enabled') } }
: {}),
};

this.table(results, columns);
}));
this.table({ data });
Copy link
Contributor

Choose a reason for hiding this comment

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

replace this.styledHeader by passing in the title prop to this.table

}
}

Expand Down
66 changes: 16 additions & 50 deletions src/commands/package/version/create/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,6 @@ export type CreateListCommandResult = Array<
}
>;

type ColumnDataHeader = {
header?: string;
};
type ColumnData = {
Id: ColumnDataHeader;
Status: ColumnDataHeader;
Package2Id: ColumnDataHeader;
Package2VersionId: ColumnDataHeader;
SubscriberPackageVersionId: ColumnDataHeader;
Tag: ColumnDataHeader;
Branch: ColumnDataHeader;
CreatedDate: ColumnDataHeader;
CreatedBy: ColumnDataHeader;
VersionName?: ColumnDataHeader;
VersionNumber?: ColumnDataHeader;
ConvertedFromVersionId?: ColumnDataHeader;
};

type Status = 'Queued' | 'InProgress' | 'Success' | 'Error';

export class PackageVersionCreateListCommand extends SfCommand<CreateListCommandResult> {
Expand Down Expand Up @@ -87,47 +69,31 @@ export class PackageVersionCreateListCommand extends SfCommand<CreateListCommand
this.warn('No results found');
} else {
this.styledHeader(chalk.blue(`Package Version Create Requests [${results.length}]`));
const columnData: ColumnData = {
Id: {},
Status: {
header: messages.getMessage('status'),
},
Package2Id: {
header: messages.getMessage('package-id'),
},
Package2VersionId: {
header: messages.getMessage('packageVersionId'),
},
SubscriberPackageVersionId: {
header: messages.getMessage('subscriberPackageVersionId'),
},
Tag: {
header: messages.getMessage('tag'),
},
Branch: {
header: messages.getMessage('branch'),
},
CreatedDate: { header: 'Created Date' },
CreatedBy: {
header: messages.getMessage('createdBy'),
},
};

if (flags['show-conversions-only']) {
columnData.ConvertedFromVersionId = { header: messages.getMessage('convertedFromVersionId') };
}

if (flags.verbose) {
try {
results = await this.fetchVerboseData(results);
columnData.VersionName = { header: 'Version Name' };
columnData.VersionNumber = { header: 'Version Number' };
} catch (err) {
const errMsg = typeof err === 'string' ? err : err instanceof Error ? err.message : 'unknown error';
this.warn(`error when retrieving verbose data (package name and version) due to: ${errMsg}`);
}
}
this.table(results, columnData, { 'no-truncate': true });

const data = results.map((r) => ({
Id: r.Id,
Status: r.Status,
'Package Id': r.Package2Id,
'Package Version Id': r.Package2VersionId,
'Subscriber Package Version Id': r.SubscriberPackageVersionId,
Tag: r.Tag,
Branch: r.Branch,
'Created Date': r.CreatedDate,
'Created By': r.CreatedBy,
...(flags['show-conversions-only'] ? { 'Converted From Version Id': r.ConvertedFromVersionId } : {}),
...(flags.verbose ? { 'Version Name': r.VersionName, 'Version Number': r.VersionNumber } : {}),
}));

this.table({ data });
}

return results;
Expand Down
5 changes: 1 addition & 4 deletions src/commands/package/version/create/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,7 @@ export class PackageVersionCreateReportCommand extends SfCommand<ReportCommandRe
}

this.styledHeader(chalk.blue('Package Version Create Request'));
this.table(data, {
key: { header: 'Name' },
value: { header: 'Value' },
});
this.table({ data });
Copy link
Contributor

Choose a reason for hiding this comment

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

replace this.styledHeader by passing in the title prop to this.table


if (record.Error?.length > 0) {
this.log('');
Expand Down
109 changes: 48 additions & 61 deletions src/commands/package/version/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand, Ux } from '@salesforce/sf-plugins-core';
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import type { TableOptions } from '@oclif/table';
import {
getContainerOptions,
getPackageVersionStrings,
Expand Down Expand Up @@ -214,8 +215,9 @@ export class PackageVersionListCommand extends SfCommand<PackageVersionListComma
});
});
this.styledHeader(`Package Versions [${results.length}]`);
this.table(results, getColumnData(flags.concise, flags.verbose, flags['show-conversions-only']), {
'no-truncate': true,
this.table({
Copy link
Contributor

Choose a reason for hiding this comment

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

replace this.styledHeader by passing in the title prop to this.table

data: results,
columns: getColumnData(flags.concise, flags.verbose, flags['show-conversions-only']),
});
} else {
this.warn('No results found');
Expand All @@ -229,73 +231,58 @@ const getColumnData = (
concise: boolean,
verbose: boolean,
conversions: boolean
): Ux.Table.Columns<Record<string, unknown>> => {
): TableOptions<PackageVersionListDetails>['columns'] => {
if (concise) {
return {
Package2Id: { header: messages.getMessage('package-id') },
Version: { header: messages.getMessage('version') },
SubscriberPackageVersionId: {
header: messages.getMessage('subscriberPackageVersionId'),
},
IsReleased: { header: 'Released' },
};
return [
{ key: 'Package2Id', name: messages.getMessage('package-id') },
{ key: 'Version', name: messages.getMessage('version') },
{ key: 'SubscriberPackageVersionId', name: messages.getMessage('subscriberPackageVersionId') },
{ key: 'IsReleased', name: 'Released' },
];
}
let defaultCols = {
Package2Name: { header: 'Package Name' },
NamespacePrefix: { header: 'Namespace' },
Name: { header: 'Version Name' },
Version: { header: messages.getMessage('version') },
SubscriberPackageVersionId: {
header: messages.getMessage('subscriberPackageVersionId'),
},
Alias: { header: messages.getMessage('alias') },
IsPasswordProtected: { header: messages.getMessage('installKey') },
IsReleased: { header: 'Released' },
ValidationSkipped: { header: messages.getMessage('validationSkipped') },
ValidatedAsync: { header: messages.getMessage('validatedAsync') },
AncestorId: { header: 'Ancestor' },
AncestorVersion: { header: 'Ancestor Version' },
Branch: { header: messages.getMessage('packageBranch') },
};
const defaultCols = [
{ key: 'Package2Name', name: 'Package Name' },
{ key: 'NamespacePrefix', name: 'Namespace' },
{ key: 'Name', name: 'Version Name' },
{ key: 'Version', name: messages.getMessage('version') },
{ key: 'SubscriberPackageVersionId', name: messages.getMessage('subscriberPackageVersionId') },
{ key: 'Alias', name: messages.getMessage('alias') },
{ key: 'IsPasswordProtected', name: messages.getMessage('installKey') },
{ key: 'IsReleased', name: 'Released' },
{ key: 'ValidationSkipped', name: messages.getMessage('validationSkipped') },
{ key: 'ValidatedAsync', name: messages.getMessage('validatedAsync') },
{ key: 'AncestorId', name: 'Ancestor' },
{ key: 'AncestorVersion', name: 'Ancestor Version' },
{ key: 'Branch', name: messages.getMessage('packageBranch') },
];

if (conversions && !verbose) {
defaultCols = Object.assign(defaultCols, {
ConvertedFromVersionId: {
header: messages.getMessage('convertedFromVersionId'),
},
});
defaultCols.push({ key: 'ConvertedFromVersionId', name: messages.getMessage('convertedFromVersionId') });
}

if (!verbose) {
// @ts-expect-error the default cols don't match 1:1 to the data in the table, but that's on purpose
return defaultCols;
} else {
// add additional columns for verbose output
return {
...defaultCols,
Package2Id: { header: messages.getMessage('package-id') },
InstallUrl: { header: messages.getMessage('installUrl') },
Id: { header: messages.getMessage('id') },
CreatedDate: { header: 'Created Date' },
LastModifiedDate: { header: 'Last Modified Date' },
Tag: { header: messages.getMessage('packageTag') },
Description: { header: messages.getMessage('description') },
CodeCoverage: { header: messages.getMessage('codeCoverage') },
HasPassedCodeCoverageCheck: {
header: messages.getMessage('hasPassedCodeCoverageCheck'),
},
ConvertedFromVersionId: {
header: messages.getMessage('convertedFromVersionId'),
},
IsOrgDependent: { header: messages.getMessage('isOrgDependent') },
ReleaseVersion: { header: messages.getMessage('releaseVersion') },
BuildDurationInSeconds: {
header: messages.getMessage('buildDurationInSeconds'),
},
HasMetadataRemoved: {
header: messages.getMessage('hasMetadataRemoved'),
},
CreatedBy: { header: messages.getMessage('createdBy') },
Language: { header: messages.getMessage('language') },
};
// @ts-expect-error the verbose match 1:1 to the data in the table, but that's on purpose, but the OCLIF types can't determine tha
return defaultCols.concat([
{ key: 'Package2Id', name: messages.getMessage('package-id') },
{ key: 'InstallUrl', name: messages.getMessage('installUrl') },
{ key: 'Id', name: messages.getMessage('id') },
{ key: 'CreatedDate', name: 'Created Date' },
{ key: 'LastModifiedDate', name: 'Last Modified Date' },
{ key: 'Tag', name: messages.getMessage('packageTag') },
{ key: 'Description', name: messages.getMessage('description') },
{ key: 'CodeCoverage', name: messages.getMessage('codeCoverage') },
{ key: 'HasPassedCodeCoverageCheck', name: messages.getMessage('hasPassedCodeCoverageCheck') },
{ key: 'ConvertedFromVersionId', name: messages.getMessage('convertedFromVersionId') },
{ key: 'IsOrgDependent', name: messages.getMessage('isOrgDependent') },
{ key: 'ReleaseVersion', name: messages.getMessage('releaseVersion') },
{ key: 'BuildDurationInSeconds', name: messages.getMessage('buildDurationInSeconds') },
{ key: 'HasMetadataRemoved', name: messages.getMessage('hasMetadataRemoved') },
{ key: 'CreatedBy', name: messages.getMessage('createdBy') },
{ key: 'Language', name: messages.getMessage('language') },
]);
}
};
4 changes: 2 additions & 2 deletions src/commands/package/version/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ export class PackageVersionReportCommand extends SfCommand<PackageVersionReportR
displayCoverageRecords.splice(0, displayCoverageRecords.length);
}
this.styledHeader(chalk.blue('Package Version'));
this.table(displayRecords, { key: { header: 'Name' }, value: { header: 'Value' } });
this.table({ data: displayRecords });
Copy link
Contributor

Choose a reason for hiding this comment

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

replace this.styledHeader by passing in the title prop to this.table

if (displayCoverageRecords.length > 0) {
this.table(displayCoverageRecords, { key: { header: 'Class Name' }, value: { header: 'Code Coverage' } });
this.table({ data: displayCoverageRecords });
}
}

Expand Down
17 changes: 8 additions & 9 deletions src/commands/package/version/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,14 @@ export class PackageVersionRetrieveCommand extends SfCommand<PackageVersionRetri
}
});

this.table(
results,
{
fullName: { header: messages.getMessage('headers.fullName') },
type: { header: messages.getMessage('headers.type') },
filePath: { header: messages.getMessage('headers.filePath') },
},
{ 'no-truncate': true }
);
this.table({
data: results,
columns: [
{ key: 'fullName', name: messages.getMessage('headers.fullName') },
{ key: 'type', name: messages.getMessage('headers.type') },
{ key: 'filePath', name: messages.getMessage('headers.filePath') },
],
});

return results;
}
Expand Down
Loading
Loading