Skip to content

Commit c8d1b56

Browse files
committed
Improve workspace error detection and refresh logic
Enhanced model dependency checking to better identify missing dependencies and workspace-loaded files. Added isLoadedInWorkspace flag to FileStatus, updated workspace refresh to clear namespace state, and improved file element loading logic for more accurate UI updates. Also improved error notification messaging for file imports.
1 parent 00e2f5a commit c8d1b56

File tree

6 files changed

+43
-15
lines changed

6 files changed

+43
-15
lines changed

core/libs/editor/src/lib/editor-toolbar/services/file-handling.service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,10 @@ export class FileHandlingService {
381381
return this.importFiles(file).pipe(
382382
tap(() => this.notificationsService.success({title: this.translate.language.NOTIFICATION_SERVICE.PACKAGE_IMPORTED_SUCCESS})),
383383
catchError(httpError => {
384-
// @TODO Temporary check until file blockage is fixed
385-
!httpError.error?.error?.message?.includes('import')
386-
? this.notificationsService.error({title: this.translate.language.NOTIFICATION_SERVICE.PACKAGE_IMPORTED_ERROR})
387-
: this.notificationsService.success({title: this.translate.language.NOTIFICATION_SERVICE.PACKAGE_IMPORTED_SUCCESS});
388-
384+
this.notificationsService.error({
385+
title: this.translate.language.NOTIFICATION_SERVICE.PACKAGE_IMPORTED_ERROR,
386+
message: httpError.error?.error?.message,
387+
});
389388
return of(null);
390389
}),
391390
finalize(() => this.loadingScreenService.close()),

core/libs/editor/src/lib/model-checker.service.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {ModelApiService, ModelData, WorkspaceStructure} from '@ame/api';
22
import {LoadedFilesService} from '@ame/cache';
33
import {RdfModelUtil} from '@ame/rdf/utils';
44
import {config} from '@ame/shared';
5-
import {ExporterHelper, FileStatus} from '@ame/sidebar';
5+
import {ExporterHelper, FileStatus, SidebarStateService} from '@ame/sidebar';
66
import {DestroyRef, Injectable, inject} from '@angular/core';
77
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
88
import {Samm} from '@esmf/aspect-model-loader';
@@ -15,6 +15,7 @@ export class ModelCheckerService {
1515
private modelApiService = inject(ModelApiService);
1616
private loadedFilesService = inject(LoadedFilesService);
1717
private modelLoader = inject(ModelLoaderService);
18+
private sidebarStateService = inject(SidebarStateService);
1819

1920
/**
2021
* Gets all files from workspace and process if they have any error or missing dependencies
@@ -24,22 +25,35 @@ export class ModelCheckerService {
2425
*/
2526
detectWorkspaceErrors(signal?: Subject<string>): Observable<Record<string, FileStatus>> {
2627
let namespacesStructure: WorkspaceStructure;
28+
const extractDependencies = (absoluteName: string, modelData: ModelData, modelVersion: string) => {
29+
const namespaces = this.sidebarStateService.namespacesState.namespaces();
30+
const chunks = RdfModelUtil.splitRdfIntoChunks(absoluteName);
31+
const namespace = namespaces[`${chunks[0]}:${chunks[1]}`];
32+
if (namespace?.find(n => n.name === chunks[2])?.isLoadedInWorkspace) {
33+
return null;
34+
}
2735

28-
const extractDependencies = (absoluteName: string, modelData: ModelData, modelVersion: string) =>
29-
this.modelApiService.fetchAspectMetaModel(modelData.aspectModelUrn).pipe(
36+
return this.modelApiService.fetchAspectMetaModel(modelData.aspectModelUrn).pipe(
3037
takeUntilDestroyed(this.destroyRef),
3138
switchMap(rdf => this.modelLoader.parseRdfModel([rdf])),
3239
map(rdfModel => {
3340
const dependencies = RdfModelUtil.resolveExternalNamespaces(rdfModel)
34-
.map(external => external.replace(/urn:samm:|urn:bamm:|#/gi, ''))
41+
.map(external => external.replace(/urn:samm:|#/gi, ''))
3542
.filter(dependency => !`urn:samm:${dependency}`.includes(Samm.BASE_URI));
3643

3744
const missingDependencies: string[] = [];
3845

3946
for (const dependency of dependencies) {
4047
const [namespace, version] = dependency.split(':');
41-
if (!namespacesStructure[`${namespace}:${version}`]) missingDependencies.push(dependency);
48+
const namespaceElements = namespacesStructure[namespace];
49+
50+
const versionExists = namespaceElements?.some(element => element.version === version);
51+
52+
if (!versionExists) {
53+
missingDependencies.push(dependency);
54+
}
4255
}
56+
4357
const status = new FileStatus(modelData.model);
4458
const currentFile = this.loadedFilesService.currentLoadedFile;
4559

@@ -56,6 +70,7 @@ export class ModelCheckerService {
5670
return status;
5771
}),
5872
);
73+
};
5974

6075
return this.modelApiService.loadNamespacesStructure().pipe(
6176
takeUntilDestroyed(this.destroyRef),
@@ -71,7 +86,11 @@ export class ModelCheckerService {
7186
}
7287
}
7388

74-
return Object.keys(requests).length ? forkJoin(requests) : of({});
89+
const entries = Object.fromEntries(
90+
Object.entries(requests).filter((entry): entry is [string, Observable<FileStatus>] => entry[1] !== null),
91+
);
92+
93+
return Object.keys(entries).length ? forkJoin(entries) : of({} as Record<string, FileStatus>);
7594
}),
7695
);
7796
}

core/libs/sidebar/src/lib/sidebar-state.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class FileStatus {
7272
public loaded: boolean;
7373
public outdated: boolean;
7474
public errored: boolean;
75+
public isLoadedInWorkspace: boolean;
7576
public sammVersion: string;
7677
public dependencies: string[];
7778
public missingDependencies: string[];
@@ -154,10 +155,10 @@ export class SidebarStateService {
154155
}
155156

156157
updateWorkspace(files: Record<string, FileStatus>) {
157-
this.namespacesState.clear();
158158
let hasOutdated = false;
159159
for (const absolute of Object.keys(files)) {
160160
const fs = files[absolute];
161+
fs.isLoadedInWorkspace = true;
161162
const [namespace, version] = RdfModelUtil.splitRdfIntoChunks(absolute);
162163
this.namespacesState.setFile(`${namespace}:${version}`, fs);
163164
hasOutdated ||= fs.outdated;

core/libs/sidebar/src/lib/workspace/workspace-file-elements/workspace-file-elements.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,13 @@ export class WorkspaceFileElementsComponent {
9898
this.searched[element] = this.elements[element].elements;
9999
}
100100

101-
if (this.loadedFilesService.getFile(`${this.selection.namespace}:${this.selection.file}`)) {
101+
const namespaceFile = this.loadedFilesService.getFile(`${this.selection.namespace}:${this.selection.file}`);
102+
103+
if (namespaceFile?.cachedFile.getAllElements().length) {
102104
this.updateElements(this.loadedFilesService.getFile(`${this.selection.namespace}:${this.selection.file}`));
103-
} else this.requestFile(`${this.selection.namespace}:${this.selection.file}`, this.selection.aspectModelUrn);
105+
} else {
106+
this.requestFile(`${this.selection.namespace}:${this.selection.file}`, this.selection.aspectModelUrn);
107+
}
104108
}
105109
});
106110
}

core/libs/sidebar/src/lib/workspace/workspace.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ <h2>{{ 'SIDEBAR.WORKSPACE.TITLE' | translate }}</h2>
2121
[class.disabled]="loading"
2222
[matTooltip]="loading ? ('SIDEBAR.WORKSPACE.REFRESHING' | translate) : ('SIDEBAR.WORKSPACE.REFRESH' | translate)"
2323
[disabled]="loading"
24-
(click)="sidebarService.workspace.refresh()"
24+
(click)="refreshWorkspace()"
2525
mat-mini-fab
2626
>
2727
<mat-icon>refresh</mat-icon>

core/libs/sidebar/src/lib/workspace/workspace.component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ export class WorkspaceComponent {
8282
});
8383
});
8484
}
85+
86+
refreshWorkspace() {
87+
this.sidebarService.namespacesState.clear();
88+
this.sidebarService.workspace.refresh();
89+
}
8590
}

0 commit comments

Comments
 (0)