@payloadcms/plugin-import-export 3.69.0-internal.424436e → 3.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/ExportSaveButton/index.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,MAAM,OAAO,CAAA;AAOzB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EA+GpC,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Button, SaveButton, toast, Translation, useConfig, useForm, useFormModified, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import { formatAdminURL } from 'payload/shared';
|
|
4
5
|
import React from 'react';
|
|
5
6
|
export const ExportSaveButton = ()=>{
|
|
6
7
|
const { t } = useTranslation();
|
|
7
|
-
const { config: { routes: { api }
|
|
8
|
+
const { config: { routes: { api } }, getEntityConfig } = useConfig();
|
|
8
9
|
const { getData, setModified } = useForm();
|
|
9
10
|
const modified = useFormModified();
|
|
10
11
|
const exportsCollectionConfig = getEntityConfig({
|
|
@@ -23,7 +24,10 @@ export const ExportSaveButton = ()=>{
|
|
|
23
24
|
timeoutID = setTimeout(()=>{
|
|
24
25
|
toastID = toast.success('Your export is being processed...');
|
|
25
26
|
}, 200);
|
|
26
|
-
const response = await fetch(
|
|
27
|
+
const response = await fetch(formatAdminURL({
|
|
28
|
+
apiRoute: api,
|
|
29
|
+
path: '/exports/download'
|
|
30
|
+
}), {
|
|
27
31
|
body: JSON.stringify({
|
|
28
32
|
data
|
|
29
33
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/ExportSaveButton/index.tsx"],"sourcesContent":["'use client'\n\nimport {\n Button,\n SaveButton,\n toast,\n Translation,\n useConfig,\n useForm,\n useFormModified,\n useTranslation,\n} from '@payloadcms/ui'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nexport const ExportSaveButton: React.FC = () => {\n const { t } = useTranslation<PluginImportExportTranslations, PluginImportExportTranslationKeys>()\n const {\n config: {\n routes: { api },\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/ExportSaveButton/index.tsx"],"sourcesContent":["'use client'\n\nimport {\n Button,\n SaveButton,\n toast,\n Translation,\n useConfig,\n useForm,\n useFormModified,\n useTranslation,\n} from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type {\n PluginImportExportTranslationKeys,\n PluginImportExportTranslations,\n} from '../../translations/index.js'\n\nexport const ExportSaveButton: React.FC = () => {\n const { t } = useTranslation<PluginImportExportTranslations, PluginImportExportTranslationKeys>()\n const {\n config: {\n routes: { api },\n },\n getEntityConfig,\n } = useConfig()\n\n const { getData, setModified } = useForm()\n const modified = useFormModified()\n\n const exportsCollectionConfig = getEntityConfig({ collectionSlug: 'exports' })\n\n const disableSave = exportsCollectionConfig?.admin?.custom?.disableSave === true\n\n const disableDownload = exportsCollectionConfig?.admin?.custom?.disableDownload === true\n\n const label = t('general:save')\n\n const handleDownload = async () => {\n let timeoutID: null | ReturnType<typeof setTimeout> = null\n let toastID: null | number | string = null\n\n try {\n setModified(false) // Reset modified state\n const data = getData()\n\n // Set a timeout to show toast if the request takes longer than 200ms\n timeoutID = setTimeout(() => {\n toastID = toast.success('Your export is being processed...')\n }, 200)\n\n const response = await fetch(\n formatAdminURL({\n apiRoute: api,\n path: '/exports/download',\n }),\n {\n body: JSON.stringify({\n data,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n },\n )\n\n // Clear the timeout if fetch completes quickly\n if (timeoutID) {\n clearTimeout(timeoutID)\n }\n\n // Dismiss the toast if it was shown\n if (toastID) {\n toast.dismiss(toastID)\n }\n\n if (!response.ok) {\n // Try to parse the error message from the JSON response\n let errorMsg = 'Failed to download file'\n try {\n const errorJson = await response.json()\n if (errorJson?.errors?.[0]?.message) {\n errorMsg = errorJson.errors[0].message\n }\n } catch {\n // Ignore JSON parse errors, fallback to generic message\n }\n throw new Error(errorMsg)\n }\n\n const fileStream = response.body\n const reader = fileStream?.getReader()\n const decoder = new TextDecoder()\n let result = ''\n\n while (reader) {\n const { done, value } = await reader.read()\n if (done) {\n break\n }\n result += decoder.decode(value, { stream: true })\n }\n\n const blob = new Blob([result], { type: 'text/plain' })\n const url = URL.createObjectURL(blob)\n const a = document.createElement('a')\n a.href = url\n a.download = `${data.name}.${data.format}`\n document.body.appendChild(a)\n a.click()\n document.body.removeChild(a)\n URL.revokeObjectURL(url)\n } catch (error: any) {\n toast.error(error.message || 'Error downloading file')\n }\n }\n\n return (\n <React.Fragment>\n {!disableSave && <SaveButton label={label} />}\n {!disableDownload && (\n <Button disabled={!modified} onClick={handleDownload} size=\"medium\" type=\"button\">\n <Translation i18nKey=\"upload:download\" t={t} />\n </Button>\n )}\n </React.Fragment>\n )\n}\n"],"names":["Button","SaveButton","toast","Translation","useConfig","useForm","useFormModified","useTranslation","formatAdminURL","React","ExportSaveButton","t","config","routes","api","getEntityConfig","getData","setModified","modified","exportsCollectionConfig","collectionSlug","disableSave","admin","custom","disableDownload","label","handleDownload","timeoutID","toastID","data","setTimeout","success","response","fetch","apiRoute","path","body","JSON","stringify","credentials","headers","method","clearTimeout","dismiss","ok","errorMsg","errorJson","json","errors","message","Error","fileStream","reader","getReader","decoder","TextDecoder","result","done","value","read","decode","stream","blob","Blob","type","url","URL","createObjectURL","a","document","createElement","href","download","name","format","appendChild","click","removeChild","revokeObjectURL","error","Fragment","disabled","onClick","size","i18nKey"],"mappings":"AAAA;;AAEA,SACEA,MAAM,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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-import-export",
|
|
3
|
-
"version": "3.69.0
|
|
3
|
+
"version": "3.69.0",
|
|
4
4
|
"description": "Import-Export plugin for Payload",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"payload",
|
|
@@ -64,17 +64,17 @@
|
|
|
64
64
|
"csv-parse": "^5.6.0",
|
|
65
65
|
"csv-stringify": "^6.5.2",
|
|
66
66
|
"qs-esm": "7.0.2",
|
|
67
|
-
"@payloadcms/translations": "3.69.0
|
|
68
|
-
"@payloadcms/ui": "3.69.0
|
|
67
|
+
"@payloadcms/translations": "3.69.0",
|
|
68
|
+
"@payloadcms/ui": "3.69.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"
|
|
72
|
-
"@payloadcms/ui": "3.69.0
|
|
73
|
-
"
|
|
71
|
+
"@payloadcms/eslint-config": "3.28.0",
|
|
72
|
+
"@payloadcms/ui": "3.69.0",
|
|
73
|
+
"payload": "3.69.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
|
-
"@payloadcms/ui": "3.69.0
|
|
77
|
-
"payload": "3.69.0
|
|
76
|
+
"@payloadcms/ui": "3.69.0",
|
|
77
|
+
"payload": "3.69.0"
|
|
78
78
|
},
|
|
79
79
|
"homepage:": "https://payloadcms.com",
|
|
80
80
|
"scripts": {
|