mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +00:00 
			
		
		
		
	Merge branch 'master' into fix/italic-style-is-ignored
This commit is contained in:
		
						commit
						6d99de01a8
					
				
							
								
								
									
										6
									
								
								examples/kitchensink/config/admin.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								examples/kitchensink/config/admin.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,6 @@
 | 
			
		||||
module.exports = ({ env }) => ({
 | 
			
		||||
  // autoOpen: false,
 | 
			
		||||
  auth: {
 | 
			
		||||
    secret: env('ADMIN_JWT_SECRET', 'example-token'),
 | 
			
		||||
  },
 | 
			
		||||
});
 | 
			
		||||
@ -57,4 +57,5 @@ module.exports = {
 | 
			
		||||
  },
 | 
			
		||||
  transformIgnorePatterns: ['node_modules/(?!(react-dnd|dnd-core|react-dnd-html5-backend)/)'],
 | 
			
		||||
  testMatch: ['/**/tests/**/?(*.)+(spec|test).[jt]s?(x)'],
 | 
			
		||||
  testURL: 'http://localhost:1337/admin',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -43,14 +43,20 @@ const App = () => {
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Array of models that are displayed in the content manager
 | 
			
		||||
  const supportedModelsToDisplay = models.filter(({ isDisplayed }) => isDisplayed);
 | 
			
		||||
 | 
			
		||||
  // Redirect the user to the 403 page
 | 
			
		||||
  // FIXME when changing the routing
 | 
			
		||||
  if (authorisedModels.length === 0 && models.length > 0 && pathname !== '/content-manager/403') {
 | 
			
		||||
  if (
 | 
			
		||||
    authorisedModels.length === 0 &&
 | 
			
		||||
    supportedModelsToDisplay.length > 0 &&
 | 
			
		||||
    pathname !== '/content-manager/403'
 | 
			
		||||
  ) {
 | 
			
		||||
    return <Redirect to="/content-manager/403" />;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Redirect the user to the create content type page
 | 
			
		||||
  if (models.length === 0 && pathname !== '/content-manager/no-content-types') {
 | 
			
		||||
  if (supportedModelsToDisplay.length === 0 && pathname !== '/content-manager/no-content-types') {
 | 
			
		||||
    return <Redirect to="/content-manager/no-content-types" />;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -72,9 +72,15 @@ describe('Content manager | App | main', () => {
 | 
			
		||||
        {
 | 
			
		||||
          kind: 'collectionType',
 | 
			
		||||
          uid: 'category',
 | 
			
		||||
          isDisplayed: true,
 | 
			
		||||
          info: { label: 'Categories', name: 'category' },
 | 
			
		||||
        },
 | 
			
		||||
        { kind: 'singleType', uid: 'homepage', info: { label: 'Home page', name: 'homepage' } },
 | 
			
		||||
        {
 | 
			
		||||
          kind: 'singleType',
 | 
			
		||||
          isDisplayed: true,
 | 
			
		||||
          uid: 'homepage',
 | 
			
		||||
          info: { label: 'Home page', name: 'homepage' },
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
      components: [],
 | 
			
		||||
      status: 'resolved',
 | 
			
		||||
@ -751,8 +757,14 @@ describe('Content manager | App | main', () => {
 | 
			
		||||
          kind: 'collectionType',
 | 
			
		||||
          uid: 'category',
 | 
			
		||||
          info: { label: 'Categories', name: 'category' },
 | 
			
		||||
          isDisplayed: true,
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          kind: 'singleType',
 | 
			
		||||
          isDisplayed: true,
 | 
			
		||||
          uid: 'homepage',
 | 
			
		||||
          info: { label: 'Home page', name: 'homepage' },
 | 
			
		||||
        },
 | 
			
		||||
        { kind: 'singleType', uid: 'homepage', info: { label: 'Home page', name: 'homepage' } },
 | 
			
		||||
      ],
 | 
			
		||||
      components: [],
 | 
			
		||||
      status: 'resolved',
 | 
			
		||||
@ -789,6 +801,7 @@ describe('Content manager | App | main', () => {
 | 
			
		||||
        {
 | 
			
		||||
          kind: 'collectionType',
 | 
			
		||||
          uid: 'category',
 | 
			
		||||
          isDisplayed: true,
 | 
			
		||||
          info: { label: 'Categories', name: 'category' },
 | 
			
		||||
        },
 | 
			
		||||
        { kind: 'singleType', uid: 'homepage', info: { label: 'Home page', name: 'homepage' } },
 | 
			
		||||
@ -828,7 +841,14 @@ describe('Content manager | App | main', () => {
 | 
			
		||||
    const contentManagerState = {
 | 
			
		||||
      collectionTypeLinks: [],
 | 
			
		||||
      singleTypeLinks: [],
 | 
			
		||||
      models: [],
 | 
			
		||||
      models: [
 | 
			
		||||
        {
 | 
			
		||||
          kind: 'collectionType',
 | 
			
		||||
          uid: 'category',
 | 
			
		||||
          info: { label: 'Categories', name: 'category' },
 | 
			
		||||
          isDisplayed: false,
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
      components: [],
 | 
			
		||||
      status: 'resolved',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
@ -133,7 +133,6 @@ program
 | 
			
		||||
 | 
			
		||||
program
 | 
			
		||||
  .command('build')
 | 
			
		||||
  .option('--clean', 'Remove the build and .cache folders', false)
 | 
			
		||||
  .option('--no-optimization', 'Build the Administration without assets optimization')
 | 
			
		||||
  .description('Builds the strapi admin app')
 | 
			
		||||
  .action(getLocalScript('build'));
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,7 @@ const getEnabledPlugins = require('../core/loaders/plugins/get-enabled-plugins')
 | 
			
		||||
/**
 | 
			
		||||
 * `$ strapi build`
 | 
			
		||||
 */
 | 
			
		||||
module.exports = async ({ clean, optimization, forceBuild = true }) => {
 | 
			
		||||
module.exports = async ({ optimization, forceBuild = true }) => {
 | 
			
		||||
  const dir = process.cwd();
 | 
			
		||||
 | 
			
		||||
  const strapiInstance = strapi({
 | 
			
		||||
@ -28,9 +28,8 @@ module.exports = async ({ clean, optimization, forceBuild = true }) => {
 | 
			
		||||
 | 
			
		||||
  console.log(`Building your admin UI with ${green(env)} configuration ...`);
 | 
			
		||||
 | 
			
		||||
  if (clean) {
 | 
			
		||||
    await strapiAdmin.clean({ dir });
 | 
			
		||||
  }
 | 
			
		||||
  // Always remove the .cache and build folders
 | 
			
		||||
  await strapiAdmin.clean({ dir });
 | 
			
		||||
 | 
			
		||||
  ee({ dir });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ module.exports = async function({ build, watchAdmin, polling, browser }) {
 | 
			
		||||
      // Don't run the build process if the admin is in watch mode
 | 
			
		||||
      if (build && !watchAdmin && serveAdminPanel && !buildExists) {
 | 
			
		||||
        try {
 | 
			
		||||
          await buildAdmin({ clean: false, optimization: false, forceBuild: false });
 | 
			
		||||
          await buildAdmin({ optimization: false, forceBuild: false });
 | 
			
		||||
        } catch (err) {
 | 
			
		||||
          process.exit(1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -1,25 +0,0 @@
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * This component is the skeleton around the actual pages, and should only
 | 
			
		||||
 * contain code that should be seen on all pages. (e.g. navigation bar)
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import { Switch, Route } from 'react-router-dom';
 | 
			
		||||
import { NotFound } from '@strapi/helper-plugin';
 | 
			
		||||
import pluginId from '../../pluginId';
 | 
			
		||||
import HomePage from '../HomePage';
 | 
			
		||||
 | 
			
		||||
const App = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <div>
 | 
			
		||||
      <Switch>
 | 
			
		||||
        <Route path={`/plugins/${pluginId}`} component={HomePage} exact />
 | 
			
		||||
        <Route component={NotFound} />
 | 
			
		||||
      </Switch>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default App;
 | 
			
		||||
@ -1,20 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 *
 | 
			
		||||
 * HomePage
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import React, { memo } from 'react';
 | 
			
		||||
// import PropTypes from 'prop-types';
 | 
			
		||||
import pluginId from '../../pluginId';
 | 
			
		||||
 | 
			
		||||
const HomePage = () => {
 | 
			
		||||
  return (
 | 
			
		||||
    <div>
 | 
			
		||||
      <h1>{pluginId}'s HomePage</h1>
 | 
			
		||||
      <p>Happy coding</p>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default memo(HomePage);
 | 
			
		||||
@ -1,26 +0,0 @@
 | 
			
		||||
/**
 | 
			
		||||
 *
 | 
			
		||||
 * Initializer
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import { useEffect, useRef } from 'react';
 | 
			
		||||
import PropTypes from 'prop-types';
 | 
			
		||||
import pluginId from '../../pluginId';
 | 
			
		||||
 | 
			
		||||
const Initializer = ({ setPlugin }) => {
 | 
			
		||||
  const ref = useRef();
 | 
			
		||||
  ref.current = setPlugin;
 | 
			
		||||
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    ref.current(pluginId);
 | 
			
		||||
  }, []);
 | 
			
		||||
 | 
			
		||||
  return null;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
Initializer.propTypes = {
 | 
			
		||||
  setPlugin: PropTypes.func.isRequired,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default Initializer;
 | 
			
		||||
@ -0,0 +1,40 @@
 | 
			
		||||
/**
 | 
			
		||||
 * axios with a custom config.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
import axios from 'axios';
 | 
			
		||||
import { auth } from '@strapi/helper-plugin';
 | 
			
		||||
 | 
			
		||||
const instance = axios.create({
 | 
			
		||||
  baseURL: process.env.STRAPI_ADMIN_BACKEND_URL,
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
instance.interceptors.request.use(
 | 
			
		||||
  async config => {
 | 
			
		||||
    config.headers = {
 | 
			
		||||
      Authorization: `Bearer ${auth.getToken()}`,
 | 
			
		||||
      Accept: 'application/json',
 | 
			
		||||
      'Content-Type': 'application/json',
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return config;
 | 
			
		||||
  },
 | 
			
		||||
  error => {
 | 
			
		||||
    Promise.reject(error);
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
instance.interceptors.response.use(
 | 
			
		||||
  response => response,
 | 
			
		||||
  error => {
 | 
			
		||||
    // whatever you want to do with the error
 | 
			
		||||
    if (error.response?.status === 401) {
 | 
			
		||||
      auth.clearAppStorage();
 | 
			
		||||
      window.location.reload();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    throw error;
 | 
			
		||||
  }
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
export default instance;
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user