Skip to content

Commit

Permalink
fix: null check (#8429)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle committed Oct 12, 2021
1 parent 3a0c29f commit e190292
Showing 1 changed file with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import { IResourceDiffCollection, capitalize } from './resource-status-diff';

//API: Filter resource status for the given categories
export async function getMultiCategoryStatus(inputs: ViewResourceTableParams | undefined) {
let resourceStatusResults = await getResourceStatus();
if (inputs?.categoryList?.length) {
//diffs for only the required categories (amplify -v <category1>...<categoryN>)
//TBD: optimize search
resourceStatusResults.resourcesToBeCreated = filterResourceCategory(resourceStatusResults.resourcesToBeCreated, inputs.categoryList);
resourceStatusResults.resourcesToBeUpdated = filterResourceCategory(resourceStatusResults.resourcesToBeUpdated, inputs.categoryList);
resourceStatusResults.resourcesToBeSynced = filterResourceCategory(resourceStatusResults.resourcesToBeSynced, inputs.categoryList);
resourceStatusResults.resourcesToBeDeleted = filterResourceCategory(resourceStatusResults.resourcesToBeDeleted, inputs.categoryList);
resourceStatusResults.allResources = filterResourceCategory(resourceStatusResults.allResources, inputs.categoryList);
}
return resourceStatusResults;
let resourceStatusResults = await getResourceStatus();
if (inputs?.categoryList?.length) {
//diffs for only the required categories (amplify -v <category1>...<categoryN>)
//TBD: optimize search
resourceStatusResults.resourcesToBeCreated = filterResourceCategory(resourceStatusResults.resourcesToBeCreated, inputs.categoryList);
resourceStatusResults.resourcesToBeUpdated = filterResourceCategory(resourceStatusResults.resourcesToBeUpdated, inputs.categoryList);
resourceStatusResults.resourcesToBeSynced = filterResourceCategory(resourceStatusResults.resourcesToBeSynced, inputs.categoryList);
resourceStatusResults.resourcesToBeDeleted = filterResourceCategory(resourceStatusResults.resourcesToBeDeleted, inputs.categoryList);
resourceStatusResults.allResources = filterResourceCategory(resourceStatusResults.allResources, inputs.categoryList);
}
return resourceStatusResults;
}

export async function getResourceDiffs(resourcesToBeUpdated, resourcesToBeDeleted, resourcesToBeCreated) {
Expand All @@ -33,32 +33,27 @@ export async function getResourceDiffs(resourcesToBeUpdated, resourcesToBeDelete
return result;
}

function resourceToTableRow( resource, operation ){
return [
capitalize(resource.category),
resource.resourceName,
operation /*syncOperationLabel*/,
resource.providerPlugin,
]
function resourceToTableRow(resource, operation) {
return [capitalize(resource.category), resource.resourceName, operation /*syncOperationLabel*/, resource.providerPlugin];
}

const ResourceOperationLabel = {
Create : 'Create',
Update : 'Update',
Delete : 'Delete',
Import : 'Import',
Unlink : 'Unlink',
NoOp : 'No Change',
}
Create: 'Create',
Update: 'Update',
Delete: 'Delete',
Import: 'Import',
Unlink: 'Unlink',
NoOp: 'No Change',
};

const TableColumnLabels = {
Category: 'Category',
ResourceName: 'Resource name',
Operation: 'Operation',
ProviderPlugin: 'Provider plugin'
}
ProviderPlugin: 'Provider plugin',
};

function getLabelForResourceSyncOperation( syncOperationType : string ) {
function getLabelForResourceSyncOperation(syncOperationType: string) {
switch (syncOperationType) {
case 'import':
return ResourceOperationLabel.Import;
Expand All @@ -84,30 +79,29 @@ export function getSummaryTableData({
);
noChangeResources = noChangeResources.filter(resource => resource.category !== 'providers');

const tableOptions = [[TableColumnLabels.Category,
TableColumnLabels.ResourceName,
TableColumnLabels.Operation,
TableColumnLabels.ProviderPlugin]];
const tableOptions = [
[TableColumnLabels.Category, TableColumnLabels.ResourceName, TableColumnLabels.Operation, TableColumnLabels.ProviderPlugin],
];

for ( const resource of resourcesToBeCreated ) {
tableOptions.push( resourceToTableRow(resource, ResourceOperationLabel.Create) );
for (const resource of resourcesToBeCreated) {
tableOptions.push(resourceToTableRow(resource, ResourceOperationLabel.Create));
}

for (const resource of resourcesToBeUpdated) {
tableOptions.push( resourceToTableRow(resource, ResourceOperationLabel.Update) )
tableOptions.push(resourceToTableRow(resource, ResourceOperationLabel.Update));
}

for (const resource of resourcesToBeSynced) {
const operation = getLabelForResourceSyncOperation(resource.sync);
tableOptions.push( resourceToTableRow( resource, operation /*syncOperationLabel*/ ) )
tableOptions.push(resourceToTableRow(resource, operation /*syncOperationLabel*/));
}

for (const resource of resourcesToBeDeleted) {
tableOptions.push(resourceToTableRow(resource, ResourceOperationLabel.Delete));
}

for (const resource of noChangeResources ) {
tableOptions.push(resourceToTableRow( resource, ResourceOperationLabel.NoOp));
for (const resource of noChangeResources) {
tableOptions.push(resourceToTableRow(resource, ResourceOperationLabel.NoOp));
}
return tableOptions;
}
Expand Down Expand Up @@ -181,7 +175,7 @@ export function getResourcesToBeCreated(amplifyMeta, currentAmplifyMeta, categor
const categoryItem = amplifyMeta[categoryName];
Object.keys(categoryItem).forEach(resource => {
if (
(!amplifyMeta[categoryName][resource].lastPushTimeStamp ||
(!amplifyMeta[categoryName][resource]?.lastPushTimeStamp ||
!currentAmplifyMeta[categoryName] ||
!currentAmplifyMeta[categoryName][resource]) &&
categoryName !== 'providers' &&
Expand Down Expand Up @@ -215,7 +209,7 @@ export function getResourcesToBeCreated(amplifyMeta, currentAmplifyMeta, categor
const dependsOnResourcename = resources[i].dependsOn[j].resourceName;
if (
amplifyMeta[dependsOnCategory] &&
(!amplifyMeta[dependsOnCategory][dependsOnResourcename].lastPushTimeStamp ||
(!amplifyMeta[dependsOnCategory][dependsOnResourcename]?.lastPushTimeStamp ||
!currentAmplifyMeta[dependsOnCategory] ||
!currentAmplifyMeta[dependsOnCategory][dependsOnResourcename]) &&
amplifyMeta[dependsOnCategory][dependsOnResourcename].serviceType !== 'imported'
Expand Down Expand Up @@ -280,7 +274,7 @@ export async function getResourcesToBeUpdated(amplifyMeta, currentAmplifyMeta, c
const backendModified = await isBackendDirModifiedSinceLastPush(
resource,
categoryName,
currentAmplifyMeta[categoryName][resource].lastPushTimeStamp,
currentAmplifyMeta[categoryName][resource]?.lastPushTimeStamp,
hashLayerResource,
);

Expand All @@ -293,7 +287,7 @@ export async function getResourcesToBeUpdated(amplifyMeta, currentAmplifyMeta, c
const backendModified = await isBackendDirModifiedSinceLastPush(
resource,
categoryName,
currentAmplifyMeta[categoryName][resource].lastPushTimeStamp,
currentAmplifyMeta[categoryName][resource]?.lastPushTimeStamp,
getHashForResourceDir,
);

Expand Down Expand Up @@ -523,4 +517,3 @@ async function asyncForEach(array, callback) {
await callback(array[index], index, array);
}
}

0 comments on commit e190292

Please sign in to comment.