diff --git a/admin/src/components/CoreStore/ExportCoreStoreFile.js b/admin/src/components/CoreStore/ExportCoreStoreFile.js index c57693e..8d65ce0 100644 --- a/admin/src/components/CoreStore/ExportCoreStoreFile.js +++ b/admin/src/components/CoreStore/ExportCoreStoreFile.js @@ -1,7 +1,7 @@ import styled from 'styled-components'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { request } from 'strapi-helper-plugin'; -import { Button } from '@buffetjs/core'; +import { Button, Padded } from '@buffetjs/core'; import CardWidget from '../data-display/CardWidget'; import ShowMoreCollapse from '../data-display/ShowMoreCollapse'; @@ -15,11 +15,38 @@ export const StyledCardWidgetFile = styled(CardWidget)` } `; -export const ExportCoreStoreButton = ({ fileName, label }) => { - const handleExport = async () => { +export const ExportCoreStoreButton = ({ fileName, label, showOptions }) => { + const [models, setModels] = useState(); + const [selectedModel, setSelectedModel] = useState(''); + + useEffect(() => { + async function fetchData() { + const { data } = await request('/content-type-builder/content-types'); + setModels( + data + .map((model) => ({ + value: model.uid, + name: model.schema.name, + })) + .sort((a, b) => a.name.localeCompare(b.name)) + ); + } + + if (showOptions) fetchData(); + }, [models && models.length]); + + const handleExport = async (model) => { try { - const userRoles = await request(`/migrate/getCoreStoreJSON`); - downloadNamedJson(userRoles, fileName || 'settings-layouts-strapi-migrate'); + const path = model + ? `/migrate/getCoreStoreJSON/${model}` + : '/migrate/getCoreStoreJSON'; + const data = await request(path); + + const defaultFilename = model + ? `settings-layouts-strapi-migrate-${model}` + : 'settings-layouts-strapi-migrate'; + downloadNamedJson(data, fileName || defaultFilename); + strapi.notification.toggle({ message: 'Settings and layouts exported successfully.', timeout: 3500, @@ -36,13 +63,30 @@ export const ExportCoreStoreButton = ({ fileName, label }) => { } }; + const handleChange = (e) => { + setSelectedModel(e.currentTarget.value); + }; + return (
-
); }; @@ -55,7 +99,7 @@ const ExportCoreStoreFile = () => { Clicking the button will download a JSON file with your Strapi Settings and layouts data.

- +
@@ -69,4 +113,4 @@ const ExportCoreStoreFile = () => { ); }; -export default ExportCoreStoreFile; +export default ExportCoreStoreFile; \ No newline at end of file diff --git a/config/routes.json b/config/routes.json index c1cb9a7..8c9e5f0 100644 --- a/config/routes.json +++ b/config/routes.json @@ -34,7 +34,7 @@ }, { "method": "GET", - "path": "/getCoreStoreJSON", + "path": "/getCoreStoreJSON/:model?", "handler": "spm-file-export-core-store.getCoreStoreJSON", "config": { "policies": [] @@ -97,4 +97,4 @@ } } ] -} +} \ No newline at end of file diff --git a/controllers/spm-file-export-core-store.js b/controllers/spm-file-export-core-store.js index f506a24..cc270f6 100644 --- a/controllers/spm-file-export-core-store.js +++ b/controllers/spm-file-export-core-store.js @@ -23,14 +23,22 @@ module.exports = { }, getCoreStoreJSON: async ctx => { const { user } = ctx.state; + const { model } = ctx.params; + if (user.roles[0].code !== 'strapi-super-admin') { - return ctx.unauthorized('You must be an admin to export permissions.'); + return ctx.unauthorized('You must be an admin to export settings and layouts.'); + } + + const queryOptions = { _limit: -1 }; + if (model) { + const prefix = 'plugin_content_manager_configuration_content_types::'; + queryOptions.key = prefix + model; } const coreStoreAPI = strapi.query('core_store'); - const coreStore = await coreStoreAPI.find({ _limit: -1 }); + const coreStore = await coreStoreAPI.find(queryOptions); const withoutIds = coreStore.map(({id, ...coreStoreNoIds}) => coreStoreNoIds) return withoutIds; } -}; +}; \ No newline at end of file