From de53f689e30543da3181de7df99ce5f47f4c7c28 Mon Sep 17 00:00:00 2001 From: Patrik <35232443+PatrikKozak@users.noreply.github.com> Date: Mon, 14 Jul 2025 14:16:14 -0400 Subject: [PATCH] feat(plugin-import-export): adds pluginConfig options to disable Save and Download buttons in export UI (#13158) ### What? Adds support for two new plugin options in the import-export plugin: - `disableSave`: disables the "Save" button in the export UI view. - `disableDownload`: disables the "Download" button in the export UI view. ### Why? This allows implementers to control user access to export actions based on context or feature requirements. For example, some use cases may want to preview an export without saving it, or disable downloads entirely. ### How? - Injected `disableSave` and `disableDownload` into `admin.custom` for the `exports` collection. - Updated the `ExportSaveButton` component to conditionally render each button based on the injected flags. - Defaults to `false` if the values are not explicitly set in `pluginConfig`. ### Example ```ts importExportPlugin({ disableSave: true, // Defaults to false disableDownload: true, // Defaults to false }) --- .../src/components/ExportSaveButton/index.tsx | 17 +++++++++++++---- .../src/getExportCollection.ts | 4 ++++ packages/plugin-import-export/src/types.ts | 10 ++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/plugin-import-export/src/components/ExportSaveButton/index.tsx b/packages/plugin-import-export/src/components/ExportSaveButton/index.tsx index 4d1dbbc2f..cf8d0d3dc 100644 --- a/packages/plugin-import-export/src/components/ExportSaveButton/index.tsx +++ b/packages/plugin-import-export/src/components/ExportSaveButton/index.tsx @@ -24,11 +24,18 @@ export const ExportSaveButton: React.FC = () => { routes: { api }, serverURL, }, + getEntityConfig, } = useConfig() const { getData, setModified } = useForm() const modified = useFormModified() + const exportsCollectionConfig = getEntityConfig({ collectionSlug: 'exports' }) + + const disableSave = exportsCollectionConfig?.admin?.custom?.disableSave === true + + const disableDownload = exportsCollectionConfig?.admin?.custom?.disableDownload === true + const label = t('general:save') const handleDownload = async () => { @@ -99,10 +106,12 @@ export const ExportSaveButton: React.FC = () => { return ( - - + {!disableSave && } + {!disableDownload && ( + + )} ) } diff --git a/packages/plugin-import-export/src/getExportCollection.ts b/packages/plugin-import-export/src/getExportCollection.ts index 070a86902..8f184750a 100644 --- a/packages/plugin-import-export/src/getExportCollection.ts +++ b/packages/plugin-import-export/src/getExportCollection.ts @@ -34,6 +34,10 @@ export const getExportCollection = ({ SaveButton: '@payloadcms/plugin-import-export/rsc#ExportSaveButton', }, }, + custom: { + disableDownload: pluginConfig.disableDownload ?? false, + disableSave: pluginConfig.disableSave ?? false, + }, group: false, useAsTitle: 'name', }, diff --git a/packages/plugin-import-export/src/types.ts b/packages/plugin-import-export/src/types.ts index f0d9a5cb7..80955a0b7 100644 --- a/packages/plugin-import-export/src/types.ts +++ b/packages/plugin-import-export/src/types.ts @@ -15,10 +15,20 @@ export type ImportExportPluginConfig = { * If true, enables debug logging */ debug?: boolean + /** + * If true, disables the download button in the export preview UI + * @default false + */ + disableDownload?: boolean /** * Enable to force the export to run synchronously */ disableJobsQueue?: boolean + /** + * If true, disables the save button in the export preview UI + * @default false + */ + disableSave?: boolean /** * This function takes the default export collection configured in the plugin and allows you to override it by modifying and returning it * @param collection