feat: initial v5 migration

pull/126/head
Boaz Poolman 2024-04-03 20:55:53 +02:00
parent 0f527048cc
commit c2ab9288c1
18 changed files with 272 additions and 554 deletions

View File

@ -4,7 +4,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { isEmpty } from 'lodash'; import { isEmpty } from 'lodash';
import { Button } from '@strapi/design-system'; import { Button } from '@strapi/design-system';
import { Map } from 'immutable'; import { Map } from 'immutable';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/strapi/admin';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import ConfirmModal from '../ConfirmModal'; import ConfirmModal from '../ConfirmModal';

View File

@ -1,8 +1,8 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
import { useDispatch } from 'react-redux'; import { useDispatch } from 'react-redux';
import { NoContent, useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/strapi/admin';
import { Button } from '@strapi/design-system'; import { Button, EmptyStateLayout } from '@strapi/design-system';
import { exportAllConfig } from '../../state/actions/Config'; import { exportAllConfig } from '../../state/actions/Config';
import ConfirmModal from '../ConfirmModal'; import ConfirmModal from '../ConfirmModal';
@ -21,7 +21,7 @@ const FirstExport = () => {
type="export" type="export"
onSubmit={() => dispatch(exportAllConfig([], toggleNotification))} onSubmit={() => dispatch(exportAllConfig([], toggleNotification))}
/> />
<NoContent <EmptyStateLayout
content={{ content={{
id: 'emptyState', id: 'emptyState',
defaultMessage: defaultMessage:

View File

@ -1,11 +1,11 @@
import React from 'react'; import React from 'react';
import { NoContent } from '@strapi/helper-plugin'; import { EmptyStateLayout } from '@strapi/design-system';
import { useIntl } from 'react-intl'; import { useIntl } from 'react-intl';
const NoChanges = () => { const NoChanges = () => {
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
return ( return (
<NoContent <EmptyStateLayout
content={{ content={{
id: 'emptyState', id: 'emptyState',
defaultMessage: defaultMessage:

View File

@ -7,7 +7,7 @@
import React from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { CheckPagePermissions } from '@strapi/helper-plugin'; import { Page } from '@strapi/strapi/admin';
import pluginPermissions from '../../permissions'; import pluginPermissions from '../../permissions';
import Header from '../../components/Header'; import Header from '../../components/Header';
@ -16,12 +16,12 @@ import ConfigPage from '../ConfigPage';
const App = () => { const App = () => {
return ( return (
<CheckPagePermissions permissions={pluginPermissions.settings}> <Page.Protect permissions={pluginPermissions.settings}>
<Provider store={store}> <Provider store={store}>
<Header /> <Header />
<ConfigPage /> <ConfigPage />
</Provider> </Provider>
</CheckPagePermissions> </Page.Protect>
); );
}; };

View File

@ -7,7 +7,7 @@ import {
Alert, Alert,
Typography, Typography,
} from '@strapi/design-system'; } from '@strapi/design-system';
import { useNotification } from '@strapi/helper-plugin'; import { useNotification } from '@strapi/strapi/admin';
import { getAllConfigDiff, getAppEnv } from '../../state/actions/Config'; import { getAllConfigDiff, getAppEnv } from '../../state/actions/Config';
import ConfigList from '../../components/ConfigList'; import ConfigList from '../../components/ConfigList';

View File

@ -1,8 +1,8 @@
const pluginPkg = require('../../../package.json'); import pluginPkg from '../../../package.json';
const pluginId = pluginPkg.name.replace( const pluginId = pluginPkg.name.replace(
/^strapi-plugin-/i, /^strapi-plugin-/i,
'', '',
); );
module.exports = pluginId; export default pluginId;

View File

@ -0,0 +1,11 @@
const prefixPluginTranslations = (trad, pluginId) => {
if (!pluginId) {
throw new TypeError("pluginId can't be empty");
}
return Object.keys(trad).reduce((acc, current) => {
acc[`${pluginId}.${current}`] = trad[current];
return acc;
}, {});
};
export { prefixPluginTranslations };

View File

@ -1,6 +1,6 @@
import { prefixPluginTranslations } from '@strapi/helper-plugin';
import pluginPkg from '../../package.json'; import pluginPkg from '../../package.json';
import pluginId from './helpers/pluginId'; import pluginId from './helpers/pluginId';
import { prefixPluginTranslations } from './helpers/prefixPluginTranslations';
import pluginPermissions from './permissions'; import pluginPermissions from './permissions';
// import pluginIcon from './components/PluginIcon'; // import pluginIcon from './components/PluginIcon';
// import getTrad from './helpers/getTrad'; // import getTrad from './helpers/getTrad';

View File

@ -4,13 +4,14 @@
* *
*/ */
import { request } from '@strapi/helper-plugin'; import { useFetchClient } from '@strapi/admin/strapi-admin';
export function getAllConfigDiff(toggleNotification) { export function getAllConfigDiff(toggleNotification) {
return async function(dispatch) { return async function(dispatch) {
const { get } = useFetchClient();
dispatch(setLoadingState(true)); dispatch(setLoadingState(true));
try { try {
const configDiff = await request('/config-sync/diff', { method: 'GET' }); const configDiff = await get('/config-sync/diff');
dispatch(setConfigPartialDiffInState([])); dispatch(setConfigPartialDiffInState([]));
dispatch(setConfigDiffInState(configDiff)); dispatch(setConfigDiffInState(configDiff));
dispatch(setLoadingState(false)); dispatch(setLoadingState(false));
@ -39,13 +40,11 @@ export function setConfigPartialDiffInState(config) {
export function exportAllConfig(partialDiff, toggleNotification) { export function exportAllConfig(partialDiff, toggleNotification) {
return async function(dispatch) { return async function(dispatch) {
const { post } = useFetchClient();
dispatch(setLoadingState(true)); dispatch(setLoadingState(true));
try { try {
const { message } = await request('/config-sync/export', { const response = await post('/config-sync/export', partialDiff);
method: 'POST', toggleNotification({ type: 'success', response });
body: partialDiff,
});
toggleNotification({ type: 'success', message });
dispatch(getAllConfigDiff(toggleNotification)); dispatch(getAllConfigDiff(toggleNotification));
dispatch(setLoadingState(false)); dispatch(setLoadingState(false));
} catch (err) { } catch (err) {
@ -57,16 +56,14 @@ export function exportAllConfig(partialDiff, toggleNotification) {
export function importAllConfig(partialDiff, force, toggleNotification) { export function importAllConfig(partialDiff, force, toggleNotification) {
return async function(dispatch) { return async function(dispatch) {
const { post } = useFetchClient();
dispatch(setLoadingState(true)); dispatch(setLoadingState(true));
try { try {
const { message } = await request('/config-sync/import', { const response = await post('/config-sync/import', {
method: 'POST', force,
body: { config: partialDiff,
force,
config: partialDiff,
},
}); });
toggleNotification({ type: 'success', message }); toggleNotification({ type: 'success', response });
dispatch(getAllConfigDiff(toggleNotification)); dispatch(getAllConfigDiff(toggleNotification));
dispatch(setLoadingState(false)); dispatch(setLoadingState(false));
} catch (err) { } catch (err) {
@ -86,10 +83,9 @@ export function setLoadingState(value) {
export function getAppEnv(toggleNotification) { export function getAppEnv(toggleNotification) {
return async function(dispatch) { return async function(dispatch) {
const { get } = useFetchClient();
try { try {
const envVars = await request('/config-sync/app-env', { const envVars = await get('/config-sync/app-env');
method: 'GET',
});
dispatch(setAppEnvInState(envVars)); dispatch(setAppEnvInState(envVars));
} catch (err) { } catch (err) {
toggleNotification({ type: 'warning', message: { id: 'notification.error' } }); toggleNotification({ type: 'warning', message: { id: 'notification.error' } });

View File

@ -57,10 +57,9 @@
"@strapi/strapi": "^4.0.0" "@strapi/strapi": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@strapi/design-system": "^1.14.1", "@strapi/design-system": "^1.16.0",
"@strapi/helper-plugin": "^4.19.0", "@strapi/icons": "^1.16.0",
"@strapi/icons": "^1.14.1", "@strapi/utils": "5.0.0-beta.0",
"@strapi/utils": "^4.19.0",
"babel-eslint": "9.0.0", "babel-eslint": "9.0.0",
"eslint": "^7.32.0", "eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1", "eslint-config-airbnb": "^18.2.1",
@ -78,7 +77,7 @@
"jest-styled-components": "^7.0.2", "jest-styled-components": "^7.0.2",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"react": "^17.0.2", "react": "^17.0.2",
"react-intl": "^5.20.12", "react-intl": "6.6.2",
"react-redux": "^7.2.2", "react-redux": "^7.2.2",
"redux": "^4.0.5", "redux": "^4.0.5",
"styled-components": "^5.2.3" "styled-components": "^5.2.3"

View File

@ -1,3 +1,3 @@
'use strict'; import admin from './admin/src';
module.exports = require('./admin/src').default; export default admin;

746
yarn.lock

File diff suppressed because it is too large Load Diff