-
Notifications
You must be signed in to change notification settings - Fork 620
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add bulk edit to File Manager #3715
Conversation
packages/api-file-manager/src/modelModifier/CmsModelModifier.ts
Outdated
Show resolved
Hide resolved
const openWorkerDialog = (batch: BatchDTO) => { | ||
showConfirmationDialog({ | ||
title: "Edit files", | ||
message: `You are about to edit ${filesLabel}. Are you sure you want to continue?`, | ||
loadingLabel: `Processing ${filesLabel}`, | ||
execute: async () => { | ||
await worker.processInSeries(async ({ item, report }) => { | ||
try { | ||
const extensions = defaultFields.find( | ||
field => field.fieldId === "extensions" | ||
); | ||
|
||
const extensionsData = GraphQLInputMapper.toGraphQLExtensions( | ||
item.extensions, | ||
batch | ||
); | ||
|
||
const output = omit(item, ["id", "createdBy", "createdOn", "src"]); | ||
|
||
const fileData = { | ||
...output, | ||
extensions: prepareFormData( | ||
extensionsData, | ||
extensions?.settings?.fields || [] | ||
) | ||
}; | ||
|
||
await updateFile(item.id, fileData); | ||
|
||
report.success({ | ||
title: `${item.name}`, | ||
message: "File successfully edited." | ||
}); | ||
} catch (e) { | ||
report.error({ | ||
title: `${item.name}`, | ||
message: e.message | ||
}); | ||
} | ||
}); | ||
|
||
worker.resetItems(); | ||
|
||
showResultsDialog({ | ||
results: worker.results, | ||
title: "Edit files", | ||
message: "Finished editing files! See full report below:" | ||
}); | ||
} | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment on this: I think it would be great to create a generic DialogPresenter
class which can be reused across other presenter implementations, to manage thee dialog interactions. That way we'll be able to remove this huge bloat of coad from the components. Something to try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Let's merge this! 🚀 🎸
Changes
With this PR, we can bulk edit file custom registered fields.
To work, the field should be registered as
bulkEdit: true
as follows:By clicking on the action, the user will have the possibility to select the fields to edit and:
multipleValues
)The file data is updated using the default bulk actions worker.
How Has This Been Tested?
Jest + Manually