mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 07:10:11 +00:00
Created Providers component
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
912f2695a0
commit
4dc122664f
@ -1,21 +1,14 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Provider } from 'react-redux';
|
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { QueryClientProvider, QueryClient } from 'react-query';
|
|
||||||
import { ThemeProvider } from 'styled-components';
|
|
||||||
import { LibraryProvider, StrapiAppProvider } from '@strapi/helper-plugin';
|
|
||||||
import pick from 'lodash/pick';
|
import pick from 'lodash/pick';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
import { basename, createHook } from './core/utils';
|
import { basename, createHook } from './core/utils';
|
||||||
import configureStore from './core/store/configureStore';
|
import configureStore from './core/store/configureStore';
|
||||||
import { Plugin } from './core/apis';
|
import { Plugin } from './core/apis';
|
||||||
import App from './pages/App';
|
import App from './pages/App';
|
||||||
import LanguageProvider from './components/LanguageProvider';
|
import Providers from './components/Providers';
|
||||||
import AutoReloadOverlayBlockerProvider from './components/AutoReloadOverlayBlockerProvider';
|
|
||||||
import OverlayBlocker from './components/OverlayBlocker';
|
import Theme from './components/Theme';
|
||||||
import Fonts from './components/Fonts';
|
|
||||||
import GlobalStyle from './components/GlobalStyle';
|
|
||||||
import Notifications from './components/Notifications';
|
|
||||||
import languageNativeNames from './translations/languageNativeNames';
|
import languageNativeNames from './translations/languageNativeNames';
|
||||||
import {
|
import {
|
||||||
INJECT_COLUMN_IN_TABLE,
|
INJECT_COLUMN_IN_TABLE,
|
||||||
@ -31,14 +24,6 @@ window.strapi = {
|
|||||||
backendURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
backendURL: process.env.STRAPI_ADMIN_BACKEND_URL,
|
||||||
};
|
};
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
|
||||||
defaultOptions: {
|
|
||||||
queries: {
|
|
||||||
refetchOnWindowFocus: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
class StrapiApp {
|
class StrapiApp {
|
||||||
constructor({ appPlugins, library, locales, middlewares, reducers }) {
|
constructor({ appPlugins, library, locales, middlewares, reducers }) {
|
||||||
this.appLocales = ['en', ...locales.filter(loc => loc !== 'en')];
|
this.appLocales = ['en', ...locales.filter(loc => loc !== 'en')];
|
||||||
@ -366,40 +351,29 @@ class StrapiApp {
|
|||||||
} = this.library;
|
} = this.library;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<Theme theme={themes}>
|
||||||
<ThemeProvider theme={themes}>
|
<Providers
|
||||||
<GlobalStyle />
|
components={components}
|
||||||
<Fonts />
|
fields={fields}
|
||||||
<Provider store={store}>
|
localeNames={localeNames}
|
||||||
<StrapiAppProvider
|
getAdminInjectedComponents={this.admin.getInjectedComponents}
|
||||||
getAdminInjectedComponents={this.admin.getInjectedComponents}
|
getPlugin={this.getPlugin}
|
||||||
getPlugin={this.getPlugin}
|
messages={this.translations}
|
||||||
menu={this.menu}
|
menu={this.menu}
|
||||||
plugins={this.plugins}
|
plugins={this.plugins}
|
||||||
runHookParallel={this.runHookParallel}
|
runHookParallel={this.runHookParallel}
|
||||||
runHookWaterfall={(name, initialValue, async = false) => {
|
runHookWaterfall={(name, initialValue, async = false) => {
|
||||||
return this.runHookWaterfall(name, initialValue, async, store);
|
return this.runHookWaterfall(name, initialValue, async, store);
|
||||||
}}
|
}}
|
||||||
runHookSeries={this.runHookSeries}
|
runHookSeries={this.runHookSeries}
|
||||||
settings={this.settings}
|
settings={this.settings}
|
||||||
>
|
store={store}
|
||||||
<LibraryProvider components={components} fields={fields}>
|
>
|
||||||
<LanguageProvider messages={this.translations} localeNames={localeNames}>
|
<BrowserRouter basename={basename}>
|
||||||
<AutoReloadOverlayBlockerProvider>
|
<App store={store} />
|
||||||
<OverlayBlocker>
|
</BrowserRouter>
|
||||||
<Notifications>
|
</Providers>
|
||||||
<BrowserRouter basename={basename}>
|
</Theme>
|
||||||
<App store={store} />
|
|
||||||
</BrowserRouter>
|
|
||||||
</Notifications>
|
|
||||||
</OverlayBlocker>
|
|
||||||
</AutoReloadOverlayBlockerProvider>
|
|
||||||
</LanguageProvider>
|
|
||||||
</LibraryProvider>
|
|
||||||
</StrapiAppProvider>
|
|
||||||
</Provider>
|
|
||||||
</ThemeProvider>
|
|
||||||
</QueryClientProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
91
packages/core/admin/admin/src/components/Providers/index.js
Normal file
91
packages/core/admin/admin/src/components/Providers/index.js
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import { QueryClientProvider, QueryClient } from 'react-query';
|
||||||
|
import { LibraryProvider, StrapiAppProvider } from '@strapi/helper-plugin';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
|
import LanguageProvider from '../LanguageProvider';
|
||||||
|
import AutoReloadOverlayBlockerProvider from '../AutoReloadOverlayBlockerProvider';
|
||||||
|
import Notifications from '../Notifications';
|
||||||
|
import OverlayBlocker from '../OverlayBlocker';
|
||||||
|
|
||||||
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
refetchOnWindowFocus: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const Providers = ({
|
||||||
|
children,
|
||||||
|
components,
|
||||||
|
fields,
|
||||||
|
getAdminInjectedComponents,
|
||||||
|
getPlugin,
|
||||||
|
localeNames,
|
||||||
|
menu,
|
||||||
|
messages,
|
||||||
|
plugins,
|
||||||
|
runHookParallel,
|
||||||
|
runHookSeries,
|
||||||
|
runHookWaterfall,
|
||||||
|
settings,
|
||||||
|
store,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<Provider store={store}>
|
||||||
|
<StrapiAppProvider
|
||||||
|
getAdminInjectedComponents={getAdminInjectedComponents}
|
||||||
|
getPlugin={getPlugin}
|
||||||
|
menu={menu}
|
||||||
|
plugins={plugins}
|
||||||
|
runHookParallel={runHookParallel}
|
||||||
|
runHookWaterfall={runHookWaterfall}
|
||||||
|
runHookSeries={runHookSeries}
|
||||||
|
settings={settings}
|
||||||
|
>
|
||||||
|
<LibraryProvider components={components} fields={fields}>
|
||||||
|
<LanguageProvider messages={messages} localeNames={localeNames}>
|
||||||
|
<AutoReloadOverlayBlockerProvider>
|
||||||
|
<OverlayBlocker>
|
||||||
|
<Notifications>{children}</Notifications>
|
||||||
|
</OverlayBlocker>
|
||||||
|
</AutoReloadOverlayBlockerProvider>
|
||||||
|
</LanguageProvider>
|
||||||
|
</LibraryProvider>
|
||||||
|
</StrapiAppProvider>
|
||||||
|
</Provider>
|
||||||
|
</QueryClientProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Providers.propTypes = {
|
||||||
|
children: PropTypes.element.isRequired,
|
||||||
|
components: PropTypes.object.isRequired,
|
||||||
|
fields: PropTypes.object.isRequired,
|
||||||
|
getAdminInjectedComponents: PropTypes.func.isRequired,
|
||||||
|
getPlugin: PropTypes.func.isRequired,
|
||||||
|
localeNames: PropTypes.objectOf(PropTypes.string).isRequired,
|
||||||
|
menu: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({
|
||||||
|
to: PropTypes.string.isRequired,
|
||||||
|
icon: PropTypes.string,
|
||||||
|
intlLabel: PropTypes.shape({
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
defaultMessage: PropTypes.string.isRequired,
|
||||||
|
}).isRequired,
|
||||||
|
permissions: PropTypes.array,
|
||||||
|
Component: PropTypes.func,
|
||||||
|
})
|
||||||
|
).isRequired,
|
||||||
|
messages: PropTypes.object.isRequired,
|
||||||
|
plugins: PropTypes.object.isRequired,
|
||||||
|
runHookParallel: PropTypes.func.isRequired,
|
||||||
|
runHookWaterfall: PropTypes.func.isRequired,
|
||||||
|
runHookSeries: PropTypes.func.isRequired,
|
||||||
|
settings: PropTypes.object.isRequired,
|
||||||
|
store: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Providers;
|
||||||
20
packages/core/admin/admin/src/components/Theme/index.js
Normal file
20
packages/core/admin/admin/src/components/Theme/index.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { ThemeProvider } from 'styled-components';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import GlobalStyle from '../GlobalStyle';
|
||||||
|
import Fonts from '../Fonts';
|
||||||
|
|
||||||
|
const Theme = ({ children, theme }) => (
|
||||||
|
<ThemeProvider theme={theme}>
|
||||||
|
<GlobalStyle />
|
||||||
|
<Fonts />
|
||||||
|
{children}
|
||||||
|
</ThemeProvider>
|
||||||
|
);
|
||||||
|
|
||||||
|
Theme.propTypes = {
|
||||||
|
children: PropTypes.element.isRequired,
|
||||||
|
theme: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Theme;
|
||||||
@ -43,7 +43,7 @@ StrapiAppProvider.propTypes = {
|
|||||||
menu: PropTypes.arrayOf(
|
menu: PropTypes.arrayOf(
|
||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
to: PropTypes.string.isRequired,
|
to: PropTypes.string.isRequired,
|
||||||
icon: PropTypes.array,
|
icon: PropTypes.string,
|
||||||
intlLabel: PropTypes.shape({
|
intlLabel: PropTypes.shape({
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
defaultMessage: PropTypes.string.isRequired,
|
defaultMessage: PropTypes.string.isRequired,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user