Skip to content

Commit

Permalink
fix: duplicate when restore workflows backup (AutomaApp#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kholid060 committed Jan 12, 2024
1 parent b0e4f6b commit f3c2dec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/newtab/pages/settings/SettingsBackup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ async function restoreWorkflows() {
};
if (state.updateIfExists) {
return workflowStore.insertOrUpdate(newWorkflows).then(showMessage);
return workflowStore
.insertOrUpdate(newWorkflows, { duplicateId: true })
.then(showMessage);
}
return workflowStore.insert(newWorkflows).then(showMessage);
Expand Down
8 changes: 6 additions & 2 deletions src/stores/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,15 @@ export const useWorkflowStore = defineStore('workflow', {

return updatedWorkflows;
},
async insertOrUpdate(data = [], { checkUpdateDate = false } = {}) {
async insertOrUpdate(
data = [],
{ checkUpdateDate = false, duplicateId = false } = {}
) {
const insertedData = {};

data.forEach((item) => {
const currentWorkflow = this.workflows[item.id];

if (currentWorkflow) {
let insert = true;
if (checkUpdateDate && currentWorkflow.createdAt && item.updatedAt) {
Expand All @@ -229,7 +233,7 @@ export const useWorkflowStore = defineStore('workflow', {
insertedData[item.id] = mergedData;
}
} else {
const workflow = defaultWorkflow(item);
const workflow = defaultWorkflow(item, { duplicateId });
this.workflows[workflow.id] = workflow;
insertedData[workflow.id] = workflow;
}
Expand Down

0 comments on commit f3c2dec

Please sign in to comment.