From 25c8bbd60ed9ae5de7bc0b3bacfe6935a95c27d5 Mon Sep 17 00:00:00 2001 From: soupette Date: Thu, 6 May 2021 11:16:49 +0200 Subject: [PATCH] Move react-query conf in StrapiApp Signed-off-by: soupette --- packages/core/admin/admin/src/StrapiApp.js | 17 ++- .../admin/admin/src/containers/App/index.js | 39 ++---- .../admin/admin/src/tests/StrapiApp.test.js | 129 +++++++++++++++++- 3 files changed, 155 insertions(+), 30 deletions(-) diff --git a/packages/core/admin/admin/src/StrapiApp.js b/packages/core/admin/admin/src/StrapiApp.js index 40628b7fb2..bcec6b0abc 100644 --- a/packages/core/admin/admin/src/StrapiApp.js +++ b/packages/core/admin/admin/src/StrapiApp.js @@ -1,6 +1,7 @@ import React from 'react'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; +import { QueryClientProvider, QueryClient } from 'react-query'; import configureStore from './core/store/configureStore'; import basename from './utils/basename'; import App from './containers/App'; @@ -19,6 +20,14 @@ window.strapi = { backendURL: process.env.STRAPI_ADMIN_BACKEND_URL, }; +const queryClient = new QueryClient({ + defaultOptions: { + queries: { + refetchOnWindowFocus: false, + }, + }, +}); + class StrapiApp { plugins = {}; @@ -40,10 +49,10 @@ class StrapiApp { const store = configureStore(this); return ( - <> - - + + + <> @@ -55,7 +64,7 @@ class StrapiApp { - + ); } } diff --git a/packages/core/admin/admin/src/containers/App/index.js b/packages/core/admin/admin/src/containers/App/index.js index c333a76f2e..69d4b8903f 100644 --- a/packages/core/admin/admin/src/containers/App/index.js +++ b/packages/core/admin/admin/src/containers/App/index.js @@ -10,7 +10,6 @@ import { Switch, Route } from 'react-router-dom'; import { connect } from 'react-redux'; import { bindActionCreators, compose } from 'redux'; import { LoadingIndicatorPage, auth, request } from '@strapi/helper-plugin'; -import { QueryClientProvider, QueryClient } from 'react-query'; import Admin from '../Admin'; import AuthPage from '../AuthPage'; @@ -29,14 +28,6 @@ window.strapi = Object.assign(window.strapi || {}, { lockAppWithOverlay: () => console.log('todo unlockAppWithOverlay'), }); -const queryClient = new QueryClient({ - defaultOptions: { - queries: { - refetchOnWindowFocus: false, - }, - }, -}); - function App(props) { const getDataRef = useRef(); const [{ isLoading, hasAdmin }, setState] = useState({ isLoading: true, hasAdmin: false }); @@ -120,22 +111,20 @@ function App(props) { return ( - - - - {authRoutes} - ( - - )} - exact - /> - - - - - + + + {authRoutes} + ( + + )} + exact + /> + + + + ); } diff --git a/packages/core/admin/admin/src/tests/StrapiApp.test.js b/packages/core/admin/admin/src/tests/StrapiApp.test.js index c125200287..ecfdd0a558 100644 --- a/packages/core/admin/admin/src/tests/StrapiApp.test.js +++ b/packages/core/admin/admin/src/tests/StrapiApp.test.js @@ -5,6 +5,133 @@ describe('ADMIN | StrapiApp', () => { it('should render the app without plugins', () => { const app = StrapiApp({}); - render(app.render()); + expect(render(app.render())).toMatchInlineSnapshot(` + Object { + "asFragment": [Function], + "baseElement": .c1 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + -webkit-box-pack: space-around; + -webkit-justify-content: space-around; + -ms-flex-pack: space-around; + justify-content: space-around; + width: 100%; + height: 100vh; + } + + .c1 > div { + margin: auto; + width: 50px; + height: 50px; + border: 6px solid #f3f3f3; + border-top: 6px solid #1c91e7; + border-radius: 50%; + -webkit-animation: fEWCgj 2s linear infinite; + animation: fEWCgj 2s linear infinite; + } + + .c0 { + display: -webkit-box; + display: -webkit-flex; + display: -ms-flexbox; + display: flex; + -webkit-align-items: center; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-flex-direction: column; + -ms-flex-direction: column; + flex-direction: column; + position: fixed; + top: 72px; + left: 0; + right: 0; + z-index: 1100; + list-style: none; + width: 100%; + overflow-y: hidden; + pointer-events: none; + } + + +
+
+
+
+
+
+ , + "container":
+
+
+
+
+
, + "debug": [Function], + "findAllByAltText": [Function], + "findAllByDisplayValue": [Function], + "findAllByLabelText": [Function], + "findAllByPlaceholderText": [Function], + "findAllByRole": [Function], + "findAllByTestId": [Function], + "findAllByText": [Function], + "findAllByTitle": [Function], + "findByAltText": [Function], + "findByDisplayValue": [Function], + "findByLabelText": [Function], + "findByPlaceholderText": [Function], + "findByRole": [Function], + "findByTestId": [Function], + "findByText": [Function], + "findByTitle": [Function], + "getAllByAltText": [Function], + "getAllByDisplayValue": [Function], + "getAllByLabelText": [Function], + "getAllByPlaceholderText": [Function], + "getAllByRole": [Function], + "getAllByTestId": [Function], + "getAllByText": [Function], + "getAllByTitle": [Function], + "getByAltText": [Function], + "getByDisplayValue": [Function], + "getByLabelText": [Function], + "getByPlaceholderText": [Function], + "getByRole": [Function], + "getByTestId": [Function], + "getByText": [Function], + "getByTitle": [Function], + "queryAllByAltText": [Function], + "queryAllByDisplayValue": [Function], + "queryAllByLabelText": [Function], + "queryAllByPlaceholderText": [Function], + "queryAllByRole": [Function], + "queryAllByTestId": [Function], + "queryAllByText": [Function], + "queryAllByTitle": [Function], + "queryByAltText": [Function], + "queryByDisplayValue": [Function], + "queryByLabelText": [Function], + "queryByPlaceholderText": [Function], + "queryByRole": [Function], + "queryByTestId": [Function], + "queryByText": [Function], + "queryByTitle": [Function], + "rerender": [Function], + "unmount": [Function], + } + `); }); });