mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-30 17:37:26 +00:00 
			
		
		
		
	Delay admin load and handle relation between plugin and main models
This commit is contained in:
		
							parent
							
								
									9409a39fc8
								
							
						
					
					
						commit
						f9cc9b504c
					
				| @ -43,9 +43,6 @@ import { translationMessages, languages } from './i18n'; | |||||||
| import { findIndex } from 'lodash'; | import { findIndex } from 'lodash'; | ||||||
| /* eslint-enable */ | /* eslint-enable */ | ||||||
| 
 | 
 | ||||||
| // Retrieve plugins from config.
 |  | ||||||
| let appPlugins = plugins; |  | ||||||
| 
 |  | ||||||
| // Create redux store with history
 | // Create redux store with history
 | ||||||
| const initialState = {}; | const initialState = {}; | ||||||
| const history = createHistory({ | const history = createHistory({ | ||||||
| @ -95,7 +92,9 @@ if (window.location.port !== '4000') { | |||||||
|       return response.json(); |       return response.json(); | ||||||
|     }) |     }) | ||||||
|     .then(plugins => { |     .then(plugins => { | ||||||
|       appPlugins = plugins || []; |       if (findIndex(plugins, ['id', 'users-permissions']) === -1) { | ||||||
|  |         store.dispatch(setHasUserPlugin()); | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
|       (plugins || []).forEach(plugin => { |       (plugins || []).forEach(plugin => { | ||||||
|         const script = document.createElement('script'); |         const script = document.createElement('script'); | ||||||
| @ -125,15 +124,13 @@ if (window.location.port !== '4000') { | |||||||
|     .catch(err => { |     .catch(err => { | ||||||
|       console.log(err); |       console.log(err); | ||||||
|     }); |     }); | ||||||
|  | } else if (findIndex(plugins, ['id', 'users-permissions']) === -1) { | ||||||
|  |   store.dispatch(setHasUserPlugin()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // const isPluginAllowedToRegister = (plugin) => true;
 | // const isPluginAllowedToRegister = (plugin) => true;
 | ||||||
| const isPluginAllowedToRegister = (plugin) => plugin.id === 'users-permissions' || plugin.id === 'email' || auth.getToken(); | const isPluginAllowedToRegister = (plugin) => plugin.id === 'users-permissions' || plugin.id === 'email' || auth.getToken(); | ||||||
| 
 | 
 | ||||||
| /** |  | ||||||
|  * Public Strapi object exposed to the `window` object |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * Register a plugin |  * Register a plugin | ||||||
|  * |  * | ||||||
| @ -178,9 +175,10 @@ const displayNotification = (message, status) => { | |||||||
|   store.dispatch(showNotification(message, status)); |   store.dispatch(showNotification(message, status)); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| if (findIndex(appPlugins, ['id', 'users-permissions']) === -1) { | 
 | ||||||
|   store.dispatch(setHasUserPlugin()); | /** | ||||||
| } |  * Public Strapi object exposed to the `window` object | ||||||
|  |  */ | ||||||
| 
 | 
 | ||||||
| window.strapi = Object.assign(window.strapi || {}, { | window.strapi = Object.assign(window.strapi || {}, { | ||||||
|   remoteURL: devFrontURL || remoteURL, |   remoteURL: devFrontURL || remoteURL, | ||||||
|  | |||||||
| @ -15,14 +15,6 @@ | |||||||
|       "test": "http://localhost:1337/admin/content-type-builder/main.js" |       "test": "http://localhost:1337/admin/content-type-builder/main.js" | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   { |  | ||||||
|     "id": "email", |  | ||||||
|     "source": { |  | ||||||
|       "development": "http://localhost:1337/admin/email/main.js", |  | ||||||
|       "production": "http://localhost:1337/admin/email/main.js", |  | ||||||
|       "test": "http://localhost:1337/admin/email/main.js" |  | ||||||
|     } |  | ||||||
|   }, |  | ||||||
|   { |   { | ||||||
|     "id": "settings-manager", |     "id": "settings-manager", | ||||||
|     "source": { |     "source": { | ||||||
| @ -30,13 +22,5 @@ | |||||||
|       "production": "http://localhost:1337/admin/settings-manager/main.js", |       "production": "http://localhost:1337/admin/settings-manager/main.js", | ||||||
|       "test": "http://localhost:1337/admin/settings-manager/main.js" |       "test": "http://localhost:1337/admin/settings-manager/main.js" | ||||||
|     } |     } | ||||||
|   }, |  | ||||||
|   { |  | ||||||
|     "id": "users-permissions", |  | ||||||
|     "source": { |  | ||||||
|       "development": "http://localhost:1337/admin/users-permissions/main.js", |  | ||||||
|       "production": "http://localhost:1337/admin/users-permissions/main.js", |  | ||||||
|       "test": "http://localhost:1337/admin/users-permissions/main.js" |  | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| ] | ] | ||||||
| @ -42,10 +42,9 @@ export const generateMenu = function () { | |||||||
| 
 | 
 | ||||||
| export function* getModels() { | export function* getModels() { | ||||||
|   try { |   try { | ||||||
|     const response = yield call(request, |     const response = yield call(request, `/content-manager/models`, { | ||||||
|       `${strapi.backendURL}/content-manager/models`, { |       method: 'GET', | ||||||
|         method: 'GET', |     }); | ||||||
|       }); |  | ||||||
| 
 | 
 | ||||||
|     yield put(loadedModels(response)); |     yield put(loadedModels(response)); | ||||||
|   } catch (err) { |   } catch (err) { | ||||||
|  | |||||||
| @ -36,12 +36,18 @@ const generateSchema = (responses) => { | |||||||
|     if (model.associations) { |     if (model.associations) { | ||||||
|       // Model relations
 |       // Model relations
 | ||||||
|       schemaModel.relations = model.associations.reduce((acc, current) => { |       schemaModel.relations = model.associations.reduce((acc, current) => { | ||||||
|  |         const displayedAttribute = current.plugin ? | ||||||
|  |           get(responses.plugins, [current.plugin, 'models', current.model || current.collection, 'info', 'mainField']) || | ||||||
|  |           findKey(get(responses.plugins, [current.plugin, 'models', current.model || current.collection, 'attributes']), { type : 'string'}) || | ||||||
|  |           'id' : | ||||||
|  |           get(responses.models, [current.model || current.collection, 'info', 'mainField']) || | ||||||
|  |           findKey(get(responses.models, [current.model || current.collection, 'attributes']), { type : 'string'}) || | ||||||
|  |           'id'; | ||||||
|  | 
 | ||||||
|         acc[current.alias] = { |         acc[current.alias] = { | ||||||
|           ...current, |           ...current, | ||||||
|           description: '', |           description: '', | ||||||
|           displayedAttribute: get(models[current.model || current.collection], 'info.mainField') || |           displayedAttribute, | ||||||
|             findKey(models[current.model || current.collection].attributes, { type : 'string'}) || |  | ||||||
|             'id', |  | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         return acc; |         return acc; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Aurelsicoko
						Aurelsicoko