From 3619a23899b364b2b58ca7dc05a13306ccd8d1ce Mon Sep 17 00:00:00 2001
From: Mat Gadd
Date: Thu, 1 Apr 2021 17:26:39 +0100
Subject: [PATCH 1/3] Update core store export to allow an optional model to be
specified
---
config/routes.json | 4 ++--
controllers/spm-file-export-core-store.js | 14 +++++++++++---
2 files changed, 13 insertions(+), 5 deletions(-)
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
From ae4f91331d95e86a006e7b18917d5296d3b6c94f Mon Sep 17 00:00:00 2001
From: Mat Gadd
Date: Thu, 1 Apr 2021 17:27:12 +0100
Subject: [PATCH 2/3] Add an optional dropdown to core store export, show
models in it
---
.../CoreStore/ExportCoreStoreFile.js | 68 +++++++++++++++----
1 file changed, 55 insertions(+), 13 deletions(-)
diff --git a/admin/src/components/CoreStore/ExportCoreStoreFile.js b/admin/src/components/CoreStore/ExportCoreStoreFile.js
index c57693e..9631da5 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,36 @@ 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,
+ }))
+ );
+ }
+
+ 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 +61,30 @@ export const ExportCoreStoreButton = ({ fileName, label }) => {
}
};
+ const handleChange = (e) => {
+ setSelectedModel(e.currentTarget.value);
+ };
+
return (
-
+ {showOptions && (
+
+
+
+ )}
+
+
);
};
@@ -55,7 +97,7 @@ const ExportCoreStoreFile = () => {
Clicking the button will download a JSON file with your Strapi Settings and layouts data.
-
+
@@ -69,4 +111,4 @@ const ExportCoreStoreFile = () => {
);
};
-export default ExportCoreStoreFile;
+export default ExportCoreStoreFile;
\ No newline at end of file
From 400eb6f7764abc5335ead33d1012f5407ef0eeb5 Mon Sep 17 00:00:00 2001
From: Mat Gadd
Date: Tue, 6 Apr 2021 15:23:31 +0100
Subject: [PATCH 3/3] Sort models, change "all" option name
---
.../src/components/CoreStore/ExportCoreStoreFile.js | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/admin/src/components/CoreStore/ExportCoreStoreFile.js b/admin/src/components/CoreStore/ExportCoreStoreFile.js
index 9631da5..8d65ce0 100644
--- a/admin/src/components/CoreStore/ExportCoreStoreFile.js
+++ b/admin/src/components/CoreStore/ExportCoreStoreFile.js
@@ -23,10 +23,12 @@ export const ExportCoreStoreButton = ({ fileName, label, showOptions }) => {
async function fetchData() {
const { data } = await request('/content-type-builder/content-types');
setModels(
- data.map((model) => ({
- value: model.uid,
- name: model.schema.name,
- }))
+ data
+ .map((model) => ({
+ value: model.uid,
+ name: model.schema.name,
+ }))
+ .sort((a, b) => a.name.localeCompare(b.name))
);
}
@@ -70,7 +72,7 @@ export const ExportCoreStoreButton = ({ fileName, label, showOptions }) => {
{showOptions && (