Fix injected compos from ctb in ctm

This commit is contained in:
soupette 2019-12-11 10:57:10 +01:00
parent 92ecb3eccd
commit 87c4de9183
5 changed files with 37 additions and 13 deletions

View File

@ -401,7 +401,8 @@ const EditSettingsView = ({
currentEnvironment,
slug,
emitEvent,
push
push,
{ componentSlug, type }
)}
</div>
</div>

View File

@ -13,11 +13,11 @@ const getInjectedComponents = (
currentEnvironment,
slug,
emitEvent,
push
push,
...rest
) => {
const componentsToInject = Object.keys(plugins).reduce((acc, current) => {
// Retrieve injected compos from plugin
// if compo can be injected in left.links area push the compo in the array
const currentPlugin = plugins[current];
const injectedComponents = get(currentPlugin, 'injectedComponents', []);
@ -32,16 +32,14 @@ const getInjectedComponents = (
return (
<Component
viewProps={rest}
currentEnvironment={currentEnvironment}
getModelName={() => slug}
getContentTypeBuilderBaseUrl={() =>
'/plugins/content-type-builder/content-types/'
}
push={push}
{...compo.props}
key={compo.key}
onClick={() => {
emitEvent('willEditEditLayout');
emitEvent('willEditLayout');
}}
/>
);

View File

@ -7,17 +7,40 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useGlobalContext } from 'strapi-helper-plugin';
import { get } from 'lodash';
import { Button } from '@buffetjs/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import getTrad from '../../utils/getTrad';
// Create link from content-type-builder to content-manager
function EditViewButton(props) {
const { formatMessage } = useGlobalContext();
// Retrieve URL from props
const url = `${props.getContentTypeBuilderBaseUrl()}${props.getModelName()}`;
const { componentSlug, type } = get(
props,
['viewProps', '0'],
{
componentSlug: '',
}
);
const baseUrl = `/plugins/content-type-builder/${
type === 'content-types' ? type : 'component-categories'
}`;
let splitted = [];
if (componentSlug) {
splitted = componentSlug.split('.');
}
const suffixUrl =
type === 'content-types'
? props.getModelName()
: `${splitted[0]}/${componentSlug}`;
const handleClick = () => {
props.push(url);
props.push(`${baseUrl}/${suffixUrl}`);
};
if (props.getModelName() === 'strapi::administrator') {
@ -30,7 +53,9 @@ function EditViewButton(props) {
onClick={handleClick}
icon={<FontAwesomeIcon icon="cog" style={{ fontSize: 13 }} />}
label={formatMessage({
id: 'content-manager.containers.Edit.Link.Model',
id: getTrad(
`injected-components.content-manager.edit-settings-view.link.${type}`
),
})}
style={{
paddingLeft: 15,
@ -44,7 +69,6 @@ function EditViewButton(props) {
EditViewButton.propTypes = {
currentEnvironment: PropTypes.string.isRequired,
getContentTypeBuilderBaseUrl: PropTypes.func.isRequired,
getModelName: PropTypes.func.isRequired,
push: PropTypes.func.isRequired,
};

View File

@ -11,7 +11,7 @@ import { LiLink } from 'strapi-helper-plugin';
// Create link from content-type-builder to content-manager
function EditViewLink(props) {
// Retrieve URL from props
const url = `${props.getContentTypeBuilderBaseUrl()}${props.getModelName()}`;
const url = `/plugins/content-type-builder/content-types/${props.getModelName()}`;
if (props.getModelName() === 'strapi::administrator') {
return null;
@ -22,7 +22,6 @@ function EditViewLink(props) {
EditViewLink.propTypes = {
currentEnvironment: PropTypes.string.isRequired,
getContentTypeBuilderBaseUrl: PropTypes.func.isRequired,
getModelName: PropTypes.func.isRequired,
};

View File

@ -96,6 +96,8 @@
"form.button.save": "Save",
"form.button.select-component": "Select a component",
"from": "from",
"injected-components.content-manager.edit-settings-view.link.content-types": "Edit the content type",
"injected-components.content-manager.edit-settings-view.link.components": "Edit the component",
"menu.section.components.name.plural": "Components",
"menu.section.components.name.singular": "Component",
"menu.section.models.name.plural": "Content Types",