mirror of
https://github.com/strapi/strapi.git
synced 2025-12-16 17:53:53 +00:00
Remove StrapiProvider in favor of StrapiAppProvider
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
be9cc3731c
commit
9cdbfb024a
@ -3,7 +3,7 @@ import { Provider } from 'react-redux';
|
|||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
import { QueryClientProvider, QueryClient } from 'react-query';
|
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, StrapiAppProvider } from '@strapi/helper-plugin';
|
||||||
import configureStore from './core/store/configureStore';
|
import configureStore from './core/store/configureStore';
|
||||||
import { Plugin } from './core/apis';
|
import { Plugin } from './core/apis';
|
||||||
import basename from './utils/basename';
|
import basename from './utils/basename';
|
||||||
@ -149,9 +149,8 @@ class StrapiApp {
|
|||||||
<GlobalStyle />
|
<GlobalStyle />
|
||||||
<Fonts />
|
<Fonts />
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<LibraryProvider components={components} fields={fields}>
|
<StrapiAppProvider getPlugin={this.getPlugin} plugins={this.plugins}>
|
||||||
{/* TODO remove this */}
|
<LibraryProvider components={components} fields={fields}>
|
||||||
<StrapiProvider strapi={this}>
|
|
||||||
<LanguageProvider messages={this.translations}>
|
<LanguageProvider messages={this.translations}>
|
||||||
<>
|
<>
|
||||||
<AutoReloadOverlayBlocker />
|
<AutoReloadOverlayBlocker />
|
||||||
@ -162,8 +161,8 @@ class StrapiApp {
|
|||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
</>
|
</>
|
||||||
</LanguageProvider>
|
</LanguageProvider>
|
||||||
</StrapiProvider>
|
</LibraryProvider>
|
||||||
</LibraryProvider>
|
</StrapiAppProvider>
|
||||||
</Provider>
|
</Provider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
import React, { useReducer, useRef } from 'react';
|
import React, { useReducer, useRef } from 'react';
|
||||||
import { LoadingIndicatorPage, useStrapi } from '@strapi/helper-plugin';
|
import { LoadingIndicatorPage, useStrapiApp } from '@strapi/helper-plugin';
|
||||||
import Admin from '../../pages/Admin';
|
import Admin from '../../pages/Admin';
|
||||||
import init from './init';
|
import init from './init';
|
||||||
import reducer, { initialState } from './reducer';
|
import reducer, { initialState } from './reducer';
|
||||||
|
|
||||||
const PluginsInitializer = () => {
|
const PluginsInitializer = () => {
|
||||||
// TODO rename strapi to avoid mismatch with the window.strapi
|
const { plugins: appPlugins } = useStrapiApp();
|
||||||
const { strapi: app } = useStrapi();
|
|
||||||
const [{ plugins }, dispatch] = useReducer(reducer, initialState, () => init(app.plugins));
|
const [{ plugins }, dispatch] = useReducer(reducer, initialState, () => init(appPlugins));
|
||||||
const setPlugin = useRef(pluginId => {
|
const setPlugin = useRef(pluginId => {
|
||||||
dispatch({ type: 'SET_PLUGIN_READY', pluginId });
|
dispatch({ type: 'SET_PLUGIN_READY', pluginId });
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { StrapiProvider } from '@strapi/helper-plugin';
|
import { StrapiAppProvider } from '@strapi/helper-plugin';
|
||||||
import { render } from '@testing-library/react';
|
import { render } from '@testing-library/react';
|
||||||
import PluginsInitializer from '../index';
|
import PluginsInitializer from '../index';
|
||||||
|
|
||||||
@ -7,11 +7,13 @@ jest.mock('../../../pages/Admin', () => () => <div>ADMIN</div>);
|
|||||||
|
|
||||||
describe('ADMIN | COMPONENTS | PluginsInitializer', () => {
|
describe('ADMIN | COMPONENTS | PluginsInitializer', () => {
|
||||||
it('should not crash', () => {
|
it('should not crash', () => {
|
||||||
|
const getPlugin = jest.fn();
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
render(
|
render(
|
||||||
<StrapiProvider strapi={{ plugins: {} }}>
|
<StrapiAppProvider plugins={{}} getPlugin={getPlugin}>
|
||||||
<PluginsInitializer />
|
<PluginsInitializer />
|
||||||
</StrapiProvider>
|
</StrapiAppProvider>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,7 +10,12 @@
|
|||||||
// IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED
|
// IF THE DOC IS NOT UPDATED THE PULL REQUEST WILL NOT BE MERGED
|
||||||
|
|
||||||
import React, { memo, useMemo, useState } from 'react';
|
import React, { memo, useMemo, useState } from 'react';
|
||||||
import { BackHeader, LeftMenuList, LoadingIndicatorPage, useStrapi } from '@strapi/helper-plugin';
|
import {
|
||||||
|
BackHeader,
|
||||||
|
LeftMenuList,
|
||||||
|
LoadingIndicatorPage,
|
||||||
|
useStrapiApp,
|
||||||
|
} from '@strapi/helper-plugin';
|
||||||
import { Switch, Redirect, Route, useParams, useHistory } from 'react-router-dom';
|
import { Switch, Redirect, Route, useParams, useHistory } from 'react-router-dom';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import HeaderSearch from '../../components/HeaderSearch';
|
import HeaderSearch from '../../components/HeaderSearch';
|
||||||
@ -37,10 +42,7 @@ import {
|
|||||||
function SettingsPage() {
|
function SettingsPage() {
|
||||||
const { settingId } = useParams();
|
const { settingId } = useParams();
|
||||||
const { goBack } = useHistory();
|
const { goBack } = useHistory();
|
||||||
// TODO
|
const { plugins } = useStrapiApp();
|
||||||
const {
|
|
||||||
strapi: { plugins },
|
|
||||||
} = useStrapi();
|
|
||||||
const [headerSearchState, setShowHeaderSearchState] = useState({ show: false, label: '' });
|
const [headerSearchState, setShowHeaderSearchState] = useState({ show: false, label: '' });
|
||||||
const { isLoading, menu } = useSettingsMenu();
|
const { isLoading, menu } = useSettingsMenu();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import {
|
|||||||
LoadingIndicatorPage,
|
LoadingIndicatorPage,
|
||||||
useGlobalContext,
|
useGlobalContext,
|
||||||
PopUpWarning,
|
PopUpWarning,
|
||||||
useStrapi,
|
useStrapiApp,
|
||||||
useUser,
|
useUser,
|
||||||
} from '@strapi/helper-plugin';
|
} from '@strapi/helper-plugin';
|
||||||
import { useHistory, useLocation, useRouteMatch, Redirect } from 'react-router-dom';
|
import { useHistory, useLocation, useRouteMatch, Redirect } from 'react-router-dom';
|
||||||
@ -63,10 +63,8 @@ const DataManagerProvider = ({
|
|||||||
reservedNames,
|
reservedNames,
|
||||||
}) => {
|
}) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
// TODO
|
|
||||||
const {
|
const { getPlugin } = useStrapiApp();
|
||||||
strapi: { getPlugin },
|
|
||||||
} = useStrapi();
|
|
||||||
|
|
||||||
const { apis } = getPlugin(pluginId);
|
const { apis } = getPlugin(pluginId);
|
||||||
const [infoModals, toggleInfoModal] = useState({ cancel: false });
|
const [infoModals, toggleInfoModal] = useState({ cancel: false });
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import {
|
|||||||
getYupInnerErrors,
|
getYupInnerErrors,
|
||||||
useGlobalContext,
|
useGlobalContext,
|
||||||
useQuery,
|
useQuery,
|
||||||
useStrapi,
|
useStrapiApp,
|
||||||
InputsIndex,
|
InputsIndex,
|
||||||
} from '@strapi/helper-plugin';
|
} from '@strapi/helper-plugin';
|
||||||
import { Button, Text, Padded } from '@buffetjs/core';
|
import { Button, Text, Padded } from '@buffetjs/core';
|
||||||
@ -72,9 +72,7 @@ const FormModal = () => {
|
|||||||
const { push } = useHistory();
|
const { push } = useHistory();
|
||||||
const { search } = useLocation();
|
const { search } = useLocation();
|
||||||
const { emitEvent, formatMessage } = useGlobalContext();
|
const { emitEvent, formatMessage } = useGlobalContext();
|
||||||
const {
|
const { getPlugin } = useStrapiApp();
|
||||||
strapi: { getPlugin },
|
|
||||||
} = useStrapi();
|
|
||||||
const ctbPlugin = getPlugin(pluginId);
|
const ctbPlugin = getPlugin(pluginId);
|
||||||
const ctbFormsAPI = ctbPlugin.apis.forms;
|
const ctbFormsAPI = ctbPlugin.apis.forms;
|
||||||
const inputsFromPlugins = ctbFormsAPI.components.inputs;
|
const inputsFromPlugins = ctbFormsAPI.components.inputs;
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import useStrapi from '../../hooks/useStrapi';
|
import useStrapiApp from '../../hooks/useStrapiApp';
|
||||||
|
|
||||||
const useInjectionZone = area => {
|
const useInjectionZone = area => {
|
||||||
const { strapi: globalStrapi } = useStrapi();
|
const { getPlugin } = useStrapiApp();
|
||||||
|
|
||||||
const [pluginName, page, position] = area.split('.');
|
const [pluginName, page, position] = area.split('.');
|
||||||
const plugin = globalStrapi.getPlugin(pluginName);
|
const plugin = getPlugin(pluginName);
|
||||||
|
|
||||||
if (!plugin) {
|
if (!plugin) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@ -0,0 +1,11 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* StrapiAppContext
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createContext } from 'react';
|
||||||
|
|
||||||
|
const StrapiAppContext = createContext();
|
||||||
|
|
||||||
|
export default StrapiAppContext;
|
||||||
@ -1,11 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* StrapiContext
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { createContext } from 'react';
|
|
||||||
|
|
||||||
const StrapiContext = createContext();
|
|
||||||
|
|
||||||
export default StrapiContext;
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* useStrapi
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { useContext } from 'react';
|
|
||||||
import StrapiContext from '../../contexts/StrapiContext';
|
|
||||||
|
|
||||||
const useStrapi = () => useContext(StrapiContext);
|
|
||||||
|
|
||||||
export default useStrapi;
|
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* useStrapiApp
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { useContext } from 'react';
|
||||||
|
import StrapiAppContext from '../../contexts/StrapiAppContext';
|
||||||
|
|
||||||
|
const useStrapiApp = () => useContext(StrapiAppContext);
|
||||||
|
|
||||||
|
export default useStrapiApp;
|
||||||
@ -116,14 +116,14 @@ export { default as ContentManagerEditViewDataManagerContext } from './contexts/
|
|||||||
export { default as useContentManagerEditViewDataManager } from './hooks/useContentManagerEditViewDataManager';
|
export { default as useContentManagerEditViewDataManager } from './hooks/useContentManagerEditViewDataManager';
|
||||||
export { default as useQuery } from './hooks/useQuery';
|
export { default as useQuery } from './hooks/useQuery';
|
||||||
export { default as useLibrary } from './hooks/useLibrary';
|
export { default as useLibrary } from './hooks/useLibrary';
|
||||||
export { default as useStrapi } from './hooks/useStrapi';
|
export { default as useStrapiApp } from './hooks/useStrapiApp';
|
||||||
export { default as useUser } from './hooks/useUser';
|
export { default as useUser } from './hooks/useUser';
|
||||||
export { default as useUserPermissions } from './hooks/useUserPermissions';
|
export { default as useUserPermissions } from './hooks/useUserPermissions';
|
||||||
export { default as useQueryParams } from './hooks/useQueryParams';
|
export { default as useQueryParams } from './hooks/useQueryParams';
|
||||||
|
|
||||||
// Providers
|
// Providers
|
||||||
export { default as StrapiProvider } from './providers/StrapiProvider';
|
|
||||||
export { default as LibraryProvider } from './providers/LibraryProvider';
|
export { default as LibraryProvider } from './providers/LibraryProvider';
|
||||||
|
export { default as StrapiAppProvider } from './providers/StrapiAppProvider';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
export { default as auth } from './utils/auth';
|
export { default as auth } from './utils/auth';
|
||||||
|
|||||||
@ -0,0 +1,22 @@
|
|||||||
|
/**
|
||||||
|
*
|
||||||
|
* StrapiAppProvider
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import React from 'react';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import StrapiAppContext from '../../contexts/StrapiAppContext';
|
||||||
|
|
||||||
|
const StrapiAppProvider = ({ children, getPlugin, plugins }) => {
|
||||||
|
return (
|
||||||
|
<StrapiAppContext.Provider value={{ getPlugin, plugins }}>{children}</StrapiAppContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
StrapiAppProvider.propTypes = {
|
||||||
|
children: PropTypes.node.isRequired,
|
||||||
|
getPlugin: PropTypes.func.isRequired,
|
||||||
|
plugins: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default StrapiAppProvider;
|
||||||
@ -1,20 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* StrapiProvider
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
import React from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import StrapiContext from '../../contexts/StrapiContext';
|
|
||||||
|
|
||||||
const StrapiProvider = ({ children, strapi }) => {
|
|
||||||
return <StrapiContext.Provider value={{ strapi }}>{children}</StrapiContext.Provider>;
|
|
||||||
};
|
|
||||||
|
|
||||||
StrapiProvider.defaultProps = {};
|
|
||||||
StrapiProvider.propTypes = {
|
|
||||||
children: PropTypes.node.isRequired,
|
|
||||||
strapi: PropTypes.object.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default StrapiProvider;
|
|
||||||
Loading…
x
Reference in New Issue
Block a user