51 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
*
* Initializer
*
*/
2019-09-10 12:14:07 +02:00
import { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { chain } from 'lodash';
import { request } from 'strapi-helper-plugin';
import pluginId from '../../pluginId';
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...
const requestURL = `/${pluginId}/content-types`;
try {
const { data } = await request(requestURL, { method: 'GET' });
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);
} catch (err) {
strapi.notification.error('content-manager.error.model.fetch');
}
};
getData();
}, []);
return null;
};
Initializer.propTypes = {
updatePlugin: PropTypes.func.isRequired,
};
2019-09-10 12:14:07 +02:00
export default Initializer;