Skip to content

Commit

Permalink
feat: status result sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 19, 2021
1 parent c71e66f commit b7b109c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/commands/source/status.ts
Expand Up @@ -63,7 +63,8 @@ export default class SourceStatus extends SfdxCommand {
}

if (this.flags.remote || this.flags.all || (!this.flags.local && !this.flags.all)) {
await tracking.ensureRemoteTracking();
// by initializeWithQuery true, one query runs so that parallel getChanges aren't doing parallel queries
await tracking.ensureRemoteTracking(true);
const [remoteDeletes, remoteModifies] = await Promise.all([
tracking.getChanges({ origin: 'remote', state: 'delete' }),
tracking.getChanges({ origin: 'remote', state: 'changed' }),
Expand Down Expand Up @@ -92,7 +93,16 @@ export default class SourceStatus extends SfdxCommand {
);
}
}

// sort order is state, type, fullname
outputRows.sort((a, b) => {
if (a.state.toLowerCase() === b.state.toLowerCase()) {
if (a.type.toLowerCase() === b.type.toLowerCase()) {
return a.fullName.toLowerCase() < b.fullName.toLowerCase() ? -1 : 1;
}
return a.type.toLowerCase() < b.type.toLowerCase() ? -1 : 1;
}
return a.state.toLowerCase() < b.state.toLowerCase() ? -1 : 1;
});
this.ux.table(outputRows, {
columns: [
{ label: 'STATE', key: 'state' },
Expand Down Expand Up @@ -122,9 +132,9 @@ export default class SourceStatus extends SfdxCommand {
return 'Add';
};
const baseObject = {
type: input.type || 'TODO',
type: input.type ?? '',
state: `${input.origin} ${state()}`,
fullName: input.name || 'TODO',
fullName: input.name ?? '',
};
this.logger.debug(baseObject);

Expand Down
9 changes: 6 additions & 3 deletions src/sourceTracking.ts
Expand Up @@ -155,7 +155,7 @@ export class SourceTracking {
* Does nothing if it already exists.
* Useful before parallel operations
*/
public async ensureRemoteTracking(): Promise<void> {
public async ensureRemoteTracking(initializeWithQuery = false): Promise<void> {
if (this.remoteSourceTrackingService) {
this.logger.debug('ensureRemoteTracking: remote tracking already exists');
return;
Expand All @@ -165,6 +165,9 @@ export class SourceTracking {
username: this.username,
orgId: this.orgId,
});
if (initializeWithQuery) {
await this.remoteSourceTrackingService.retrieveUpdates();
}
}

/**
Expand Down Expand Up @@ -272,15 +275,15 @@ export class SourceTracking {
}

/**
* uses SDR to translate remote metadata records into local file paths
* uses SDR to translate remote metadata records into local file paths (which only typically have the filename)
*/
// public async populateFilePaths(elements: ChangeResult[]): Promise<ChangeResult[]> {
public populateTypesAndNames(elements: ChangeResult[]): ChangeResult[] {
if (elements.length === 0) {
return [];
}

this.logger.debug('populateTypesAndNames for change elements', elements);
this.logger.debug(`populateTypesAndNames for ${elements.length} change elements`);
// component set generated from an filenames on all local changes
const matchingLocalSourceComponentsSet = ComponentSet.fromSource({
fsPaths: elements
Expand Down

0 comments on commit b7b109c

Please sign in to comment.