Skip to content

Commit

Permalink
fix(diff), show component files as deleted when a component was delet…
Browse files Browse the repository at this point in the history
…ed (#8796)

(currently, it shows them all as new).
  • Loading branch information
davidfirst authored Apr 17, 2024
1 parent 28a8fbc commit d12fea5
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,26 @@ export class ComponentCompareMain {
}

async function getComponentDiff(component: Component): Promise<DiffResults> {
const diffResult = { id: component.id, hasDiff: false };
const diffResult: DiffResults = { id: component.id, hasDiff: false };
const consumerComponent = component.state._consumer as ConsumerComponent;
if (!consumerComponent.componentFromModel) {
if (component.isDeleted()) {
// component exists in the model but not in the filesystem, show all files as deleted
// the reason it is loaded without componentFromModel is because it was loaded from the scope, not workspace.
// as a proof, consumerComponent.loadedFromFileSystem is false.
const modelFiles = consumerComponent.files;
diffResult.filesDiff = await getFilesDiff(modelFiles, [], component.id.version, component.id.version);
if (hasDiff(diffResult)) diffResult.hasDiff = true;
return diffResult;
}
// it's a new component. not modified. show all files as new.
const fsFiles = consumerComponent.files;
// @ts-ignore version must be defined as the component.componentFromModel do exist
diffResult.filesDiff = await getFilesDiff([], fsFiles, component.id.version, component.id.version);
if (hasDiff(diffResult)) diffResult.hasDiff = true;
return diffResult;
}
const modelFiles = consumerComponent.componentFromModel.files;
const fsFiles = consumerComponent.files;
// @ts-ignore version must be defined as the component.componentFromModel do exist
diffResult.filesDiff = await getFilesDiff(modelFiles, fsFiles, component.id.version, component.id.version);
await updateFieldsDiff(consumerComponent.componentFromModel, consumerComponent, diffResult, diffOpts);

Expand Down

0 comments on commit d12fea5

Please sign in to comment.