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

View File

@ -1,8 +1,16 @@
import ReactDOM from 'react-dom';
import StrapiApp from './StrapiApp';
import { Components, Fields, Middlewares, Reducers } from './core/apis';
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');

View File

@ -1,9 +1,13 @@
import { render } from '@testing-library/react';
import StrapiApp from '../StrapiApp';
import appReducers from '../reducers';
describe('ADMIN | StrapiApp', () => {
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(`
Object {

View File

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