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 { ...@@ -35,15 +35,21 @@ export class SourceGroupsManager {
} }
createImportState(importId, jobConfig) { createImportState(importId, jobConfig) {
this.importStates[this.getStorageKey(importId)] = { this.importStates[importId] = {
status: jobConfig.status, 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(); this.saveImportStatesToStorage();
} }
updateImportProgress(importId, status) { updateImportProgress(importId, status) {
const currentState = this.importStates[this.getStorageKey(importId)]; const currentState = this.importStates[importId];
if (!currentState) { if (!currentState) {
return; return;
} }
...@@ -52,12 +58,15 @@ export class SourceGroupsManager { ...@@ -52,12 +58,15 @@ export class SourceGroupsManager {
this.saveImportStatesToStorage(); this.saveImportStatesToStorage();
} }
getImportedGroupsByJobId(jobId) {
return this.importStates[jobId]?.groups ?? [];
}
getImportStateFromStorageByGroupId(groupId) { getImportStateFromStorageByGroupId(groupId) {
const PREFIX = this.getStorageKey('');
const [jobId, importState] = const [jobId, importState] =
Object.entries(this.importStates).find( Object.entries(this.importStates)
([key, state]) => key.startsWith(PREFIX) && state.groups.some((g) => g.id === groupId), .reverse()
) ?? []; .find(([, state]) => state.groups.some((g) => g.id === groupId)) ?? [];
if (!jobId) { if (!jobId) {
return null; return null;
...@@ -67,10 +76,6 @@ export class SourceGroupsManager { ...@@ -67,10 +76,6 @@ export class SourceGroupsManager {
return { jobId, importState: { ...group, status: importState.status } }; return { jobId, importState: { ...group, status: importState.status } };
} }
getStorageKey(importId) {
return `${this.sourceUrl}|${importId}`;
}
saveImportStatesToStorage = debounce(() => { saveImportStatesToStorage = debounce(() => {
try { try {
// storage might be changed in other tab so fetch first // 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