2019-04-02 14:06:44 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Initializer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-10 12:14:07 +02:00
|
|
|
import { useEffect, useRef } from 'react';
|
2019-04-02 14:06:44 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2020-02-12 17:54:08 +01:00
|
|
|
import { chain } from 'lodash';
|
2019-09-09 18:44:41 +02:00
|
|
|
import { request } from 'strapi-helper-plugin';
|
2019-04-02 14:06:44 +02:00
|
|
|
import pluginId from '../../pluginId';
|
|
|
|
|
2019-09-09 18:44:41 +02:00
|
|
|
const Initializer = ({ updatePlugin }) => {
|
|
|
|
const ref = useRef();
|
|
|
|
ref.current = updatePlugin;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const getData = async () => {
|
2019-12-04 10:54:57 +01:00
|
|
|
// When updating this we also need to update the content-type-builder/admin/src/containers/DataManager/index.js => updateAppMenu
|
|
|
|
// since it uses the exact same method...
|
2019-09-09 18:44:41 +02:00
|
|
|
const requestURL = `/${pluginId}/content-types`;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const { data } = await request(requestURL, { method: 'GET' });
|
2020-02-12 17:54:08 +01:00
|
|
|
|
|
|
|
ref.current(
|
|
|
|
pluginId,
|
|
|
|
'leftMenuSections',
|
|
|
|
chain(data)
|
|
|
|
.groupBy('schema.kind')
|
|
|
|
.map((value, key) => ({ name: key, links: value }))
|
|
|
|
.value()
|
|
|
|
);
|
2019-09-10 12:14:07 +02:00
|
|
|
ref.current(pluginId, 'isReady', true);
|
2019-09-09 18:44:41 +02:00
|
|
|
} catch (err) {
|
|
|
|
strapi.notification.error('content-manager.error.model.fetch');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
getData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
2019-04-02 14:06:44 +02:00
|
|
|
|
|
|
|
Initializer.propTypes = {
|
|
|
|
updatePlugin: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2019-09-10 12:14:07 +02:00
|
|
|
export default Initializer;
|