Fix PR feedback

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2021-05-12 15:33:02 +02:00
parent 416ac87bde
commit fc71d2839d
6 changed files with 36 additions and 49 deletions

View File

@ -5,7 +5,7 @@ import { QueryClientProvider, QueryClient } from 'react-query';
import { ThemeProvider } from 'styled-components'; import { ThemeProvider } from 'styled-components';
import { LibraryProvider, StrapiProvider } from '@strapi/helper-plugin'; import { LibraryProvider, StrapiProvider } from '@strapi/helper-plugin';
import configureStore from './core/store/configureStore'; import configureStore from './core/store/configureStore';
import { Library, Middlewares, Plugin, Reducers } from './core/apis'; import { Plugin } from './core/apis';
import basename from './utils/basename'; import basename from './utils/basename';
import App from './pages/App'; import App from './pages/App';
import LanguageProvider from './components/LanguageProvider'; import LanguageProvider from './components/LanguageProvider';
@ -16,8 +16,6 @@ import GlobalStyle from './components/GlobalStyle';
import Notifications from './components/Notifications'; import Notifications from './components/Notifications';
import themes from './themes'; import themes from './themes';
import reducers from './reducers';
// TODO // TODO
import translations from './translations'; import translations from './translations';
@ -36,33 +34,29 @@ const queryClient = new QueryClient({
const appLocales = Object.keys(translations); const appLocales = Object.keys(translations);
class StrapiApp { class StrapiApp {
constructor({ appPlugins }) { constructor({ appPlugins, library, middlewares, reducers }) {
this.appPlugins = appPlugins || {}; this.appPlugins = appPlugins || {};
this.library = Library(); this.library = library;
this.middlewares = Middlewares(); this.middlewares = middlewares;
this.plugins = {}; this.plugins = {};
this.reducers = Reducers({ appReducers: reducers }); this.reducers = reducers;
this.translations = translations; this.translations = translations;
} }
addComponent = component => {
this.library.components.add(component);
};
addComponents = components => { addComponents = components => {
components.map(compo => this.library.components.add(compo)); if (Array.isArray(components)) {
}; components.map(compo => this.library.components.add(compo));
} else {
addField = field => { this.library.components.add(components);
this.library.fields.add(field); }
}; };
addFields = fields => { addFields = fields => {
fields.map(field => this.library.fields.add(field)); if (Array.isArray(fields)) {
}; fields.map(field => this.library.fields.add(field));
} else {
addMiddleware = middleware => { this.library.fields.add(fields);
this.middlewares.add(middleware); }
}; };
addMiddlewares = middlewares => { addMiddlewares = middlewares => {
@ -71,10 +65,6 @@ class StrapiApp {
}); });
}; };
addReducer = reducer => {
this.reducers.add(reducer);
};
addReducers = reducers => { addReducers = reducers => {
Object.keys(reducers).forEach(reducerName => { Object.keys(reducers).forEach(reducerName => {
this.reducers.add(reducerName, reducers[reducerName]); this.reducers.add(reducerName, reducers[reducerName]);
@ -84,13 +74,9 @@ class StrapiApp {
async initialize() { async initialize() {
Object.keys(this.appPlugins).forEach(plugin => { Object.keys(this.appPlugins).forEach(plugin => {
this.appPlugins[plugin].register({ this.appPlugins[plugin].register({
addComponent: this.addComponent,
addComponents: this.addComponents, addComponents: this.addComponents,
addField: this.addField,
addFields: this.addFields, addFields: this.addFields,
addMiddleware: this.addMiddleware,
addMiddlewares: this.addMiddlewares, addMiddlewares: this.addMiddlewares,
addReducer: this.addReducer,
addReducers: this.addReducers, addReducers: this.addReducers,
registerPlugin: this.registerPlugin, registerPlugin: this.registerPlugin,
}); });
@ -108,7 +94,7 @@ class StrapiApp {
} }
getPlugin = pluginId => { getPlugin = pluginId => {
return this.plugins[pluginId] || null; return this.plugins[pluginId];
}; };
// FIXME // FIXME
@ -185,4 +171,5 @@ class StrapiApp {
} }
} }
export default ({ appPlugins }) => new StrapiApp({ appPlugins }); export default ({ appPlugins, library, middlewares, reducers }) =>
new StrapiApp({ appPlugins, library, middlewares, reducers });

View File

@ -1,13 +0,0 @@
// @HichamELBSI, @mfrachet if you have a better naming for our components and fields
// store I will be happy to change the current name
import Components from './Components';
import Fields from './Fields';
class Library {
constructor() {
this.components = Components();
this.fields = Fields();
}
}
export default () => new Library();

View File

@ -1,4 +1,5 @@
export { default as Library } from './Library'; export { default as Fields } from './Fields';
export { default as Components } from './Components';
export { default as Middlewares } from './Middlewares'; export { default as Middlewares } from './Middlewares';
export { default as Plugin } from './Plugin'; export { default as Plugin } from './Plugin';
export { default as Reducers } from './Reducers'; export { default as Reducers } from './Reducers';

View File

@ -1,8 +1,16 @@
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import StrapiApp from './StrapiApp'; import StrapiApp from './StrapiApp';
import { Components, Fields, Middlewares, Reducers } from './core/apis';
import plugins from './plugins'; import plugins from './plugins';
import appReducers from './reducers';
const app = StrapiApp({ appPlugins: plugins }); const library = {
components: Components(),
fields: Fields(),
};
const middlewares = Middlewares();
const reducers = Reducers({ appReducers });
const app = StrapiApp({ appPlugins: plugins, library, middlewares, reducers });
const MOUNT_NODE = document.getElementById('app'); const MOUNT_NODE = document.getElementById('app');

View File

@ -1,9 +1,13 @@
import { render } from '@testing-library/react'; import { render } from '@testing-library/react';
import StrapiApp from '../StrapiApp'; import StrapiApp from '../StrapiApp';
import appReducers from '../reducers';
describe('ADMIN | StrapiApp', () => { describe('ADMIN | StrapiApp', () => {
it('should render the app without plugins', () => { it('should render the app without plugins', () => {
const app = StrapiApp({}); const library = { fields: {}, components: {} };
const middlewares = { middlewares: [] };
const reducers = { reducers: appReducers };
const app = StrapiApp({ middlewares, reducers, library });
expect(render(app.render())).toMatchInlineSnapshot(` expect(render(app.render())).toMatchInlineSnapshot(`
Object { Object {

View File

@ -26,9 +26,9 @@ const name = pluginPkg.strapi.name;
export default { export default {
register(app) { register(app) {
// TODO update doc and guides // TODO update doc and guides
app.addComponent({ name: 'media-library', Component: InputModalStepper }); app.addComponents({ name: 'media-library', Component: InputModalStepper });
// TODO update guide // TODO update guide
app.addField({ type: 'media', Component: InputMedia }); app.addFields({ type: 'media', Component: InputMedia });
app.addReducers(reducers); app.addReducers(reducers);