Commit c44040bb authored by Illya Klymov's avatar Illya Klymov Committed by Jacques Erasmus

Fix source groups manager for bulk imports

* remove prefixing of state with url since ids are global for
entire instance
* reverse saved state when searching since now we might have
multiple imports matching same group
* introduce ability to get affected groups for specific job id
parent 054afda3
......@@ -35,15 +35,21 @@ export class SourceGroupsManager {
}
createImportState(importId, jobConfig) {
this.importStates[this.getStorageKey(importId)] = {
this.importStates[importId] = {
status: jobConfig.status,
groups: jobConfig.groups.map((g) => ({ importTarget: g.import_target, id: g.id })),
groups: jobConfig.groups.map((g) => ({
importTarget: {
target_namespace: g.import_target.target_namespace,
new_name: g.import_target.new_name,
},
id: g.id,
})),
};
this.saveImportStatesToStorage();
}
updateImportProgress(importId, status) {
const currentState = this.importStates[this.getStorageKey(importId)];
const currentState = this.importStates[importId];
if (!currentState) {
return;
}
......@@ -52,12 +58,15 @@ export class SourceGroupsManager {
this.saveImportStatesToStorage();
}
getImportedGroupsByJobId(jobId) {
return this.importStates[jobId]?.groups ?? [];
}
getImportStateFromStorageByGroupId(groupId) {
const PREFIX = this.getStorageKey('');
const [jobId, importState] =
Object.entries(this.importStates).find(
([key, state]) => key.startsWith(PREFIX) && state.groups.some((g) => g.id === groupId),
) ?? [];
Object.entries(this.importStates)
.reverse()
.find(([, state]) => state.groups.some((g) => g.id === groupId)) ?? [];
if (!jobId) {
return null;
......@@ -67,10 +76,6 @@ export class SourceGroupsManager {
return { jobId, importState: { ...group, status: importState.status } };
}
getStorageKey(importId) {
return `${this.sourceUrl}|${importId}`;
}
saveImportStatesToStorage = debounce(() => {
try {
// storage might be changed in other tab so fetch first
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment