mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 19:36:20 +00:00
Fix plugins.toJS in all plugins
This commit is contained in:
parent
0c01ea2121
commit
4a18512122
@ -184,14 +184,16 @@ export class EditPage extends React.Component {
|
||||
* @return {Object}
|
||||
*/
|
||||
getSchema = () =>
|
||||
/* eslint-disable indent */
|
||||
this.getSource() !== pluginId
|
||||
? get(this.props.schema, [
|
||||
'models',
|
||||
'plugins',
|
||||
this.getSource(),
|
||||
this.getModelName(),
|
||||
])
|
||||
'models',
|
||||
'plugins',
|
||||
this.getSource(),
|
||||
this.getModelName(),
|
||||
])
|
||||
: get(this.props.schema, ['models', this.getModelName()]);
|
||||
/* eslint-enable indent */
|
||||
|
||||
getPluginHeaderTitle = () => {
|
||||
if (this.isCreating()) {
|
||||
@ -199,9 +201,15 @@ export class EditPage extends React.Component {
|
||||
}
|
||||
|
||||
const title = get(this.getSchema(), 'editDisplay.displayedField');
|
||||
const valueToDisplay = get(this.props.editPage, ['initialRecord', title], null);
|
||||
const valueToDisplay = get(
|
||||
this.props.editPage,
|
||||
['initialRecord', title],
|
||||
null,
|
||||
);
|
||||
|
||||
return isEmpty(toString(valueToDisplay)) ? null : truncate(valueToDisplay, { length: '24', separator: '.' });
|
||||
return isEmpty(toString(valueToDisplay))
|
||||
? null
|
||||
: truncate(valueToDisplay, { length: '24', separator: '.' });
|
||||
};
|
||||
|
||||
/**
|
||||
@ -436,7 +444,12 @@ export class EditPage extends React.Component {
|
||||
};
|
||||
|
||||
return (
|
||||
<li key={`${pluginId}.link`} onClick={() => this.context.emitEvent('willEditContentTypeLayoutFromEditView')}>
|
||||
<li
|
||||
key={`${pluginId}.link`}
|
||||
onClick={() =>
|
||||
this.context.emitEvent('willEditContentTypeLayoutFromEditView')
|
||||
}
|
||||
>
|
||||
<NavLink {...message} url={url} />
|
||||
</li>
|
||||
);
|
||||
@ -488,7 +501,7 @@ export class EditPage extends React.Component {
|
||||
retrieveLinksContainerComponent = () => {
|
||||
// Should be retrieved from the global props (@soupette)
|
||||
const { plugins } = this.context;
|
||||
const appPlugins = plugins.toJS();
|
||||
const appPlugins = plugins;
|
||||
const componentToInject = Object.keys(appPlugins).reduce((acc, current) => {
|
||||
// Retrieve injected compos from plugin
|
||||
// if compo can be injected in left.links area push the compo in the array
|
||||
@ -506,7 +519,12 @@ export class EditPage extends React.Component {
|
||||
const Component = compo.component;
|
||||
|
||||
return (
|
||||
<li key={compo.key} onClick={() => this.context.emitEvent('willEditContentTypeFromEditView')}>
|
||||
<li
|
||||
key={compo.key}
|
||||
onClick={() =>
|
||||
this.context.emitEvent('willEditContentTypeFromEditView')
|
||||
}
|
||||
>
|
||||
<Component {...this} {...compo.props} />
|
||||
</li>
|
||||
);
|
||||
@ -639,7 +657,7 @@ export class EditPage extends React.Component {
|
||||
actions={this.pluginHeaderActions()}
|
||||
subActions={this.pluginHeaderSubActions()}
|
||||
title={{ id: this.getPluginHeaderTitle() }}
|
||||
titleId="addNewEntry"
|
||||
titleId='addNewEntry'
|
||||
/>
|
||||
<PopUpWarning
|
||||
isOpen={showWarning}
|
||||
@ -650,7 +668,7 @@ export class EditPage extends React.Component {
|
||||
cancel: `${pluginId}.popUpWarning.button.cancel`,
|
||||
confirm: `${pluginId}.popUpWarning.button.confirm`,
|
||||
}}
|
||||
popUpWarningType="danger"
|
||||
popUpWarningType='danger'
|
||||
onConfirm={this.handleConfirm}
|
||||
/>
|
||||
<PopUpWarning
|
||||
@ -662,10 +680,10 @@ export class EditPage extends React.Component {
|
||||
cancel: `${pluginId}.popUpWarning.button.cancel`,
|
||||
confirm: `${pluginId}.popUpWarning.button.confirm`,
|
||||
}}
|
||||
popUpWarningType="danger"
|
||||
popUpWarningType='danger'
|
||||
onConfirm={this.handleConfirm}
|
||||
/>
|
||||
<div className="row">
|
||||
<div className='row'>
|
||||
{this.renderEdit()}
|
||||
{this.shouldDisplayedRightSection() && (
|
||||
<div className={cn('col-lg-3')}>
|
||||
@ -765,7 +783,11 @@ const withConnect = connect(
|
||||
mapDispatchToProps,
|
||||
);
|
||||
|
||||
const withReducer = strapi.injectReducer({ key: 'editPage', reducer, pluginId });
|
||||
const withReducer = strapi.injectReducer({
|
||||
key: 'editPage',
|
||||
reducer,
|
||||
pluginId,
|
||||
});
|
||||
const withSaga = strapi.injectSaga({ key: 'editPage', saga, pluginId });
|
||||
|
||||
export default compose(
|
||||
|
||||
@ -10,7 +10,12 @@ import {
|
||||
submitContentTypeSucceeded,
|
||||
submitTempContentTypeSucceeded,
|
||||
} from './actions';
|
||||
import { GET_DATA, DELETE_MODEL, SUBMIT_CONTENT_TYPE, SUBMIT_TEMP_CONTENT_TYPE } from './constants';
|
||||
import {
|
||||
GET_DATA,
|
||||
DELETE_MODEL,
|
||||
SUBMIT_CONTENT_TYPE,
|
||||
SUBMIT_TEMP_CONTENT_TYPE,
|
||||
} from './constants';
|
||||
|
||||
export function* getData() {
|
||||
try {
|
||||
@ -26,18 +31,34 @@ export function* getData() {
|
||||
}
|
||||
}
|
||||
|
||||
export function* deleteModel({ context: { plugins, updatePlugin }, modelName }) {
|
||||
export function* deleteModel({
|
||||
context: { plugins, updatePlugin },
|
||||
modelName,
|
||||
}) {
|
||||
try {
|
||||
const requestURL = `/${pluginId}/models/${modelName}`;
|
||||
const response = yield call(request, requestURL, { method: 'DELETE' }, true);
|
||||
const response = yield call(
|
||||
request,
|
||||
requestURL,
|
||||
{ method: 'DELETE' },
|
||||
true,
|
||||
);
|
||||
|
||||
if (response.ok === true) {
|
||||
strapi.notification.success(`${pluginId}.notification.success.contentTypeDeleted`);
|
||||
strapi.notification.success(
|
||||
`${pluginId}.notification.success.contentTypeDeleted`,
|
||||
);
|
||||
yield put(deleteModelSucceeded(modelName));
|
||||
|
||||
const appPlugins = plugins.toJS ? plugins.toJS() : plugins;
|
||||
const appMenu = get(appPlugins, ['content-manager', 'leftMenuSections'], []);
|
||||
const updatedMenu = appMenu[0].links.filter(el => el.destination !== modelName);
|
||||
const appPlugins = plugins;
|
||||
const appMenu = get(
|
||||
appPlugins,
|
||||
['content-manager', 'leftMenuSections'],
|
||||
[],
|
||||
);
|
||||
const updatedMenu = appMenu[0].links.filter(
|
||||
el => el.destination !== modelName,
|
||||
);
|
||||
appMenu[0].links = sortBy(updatedMenu, 'label');
|
||||
updatePlugin('content-manager', 'leftMenuSections', appMenu);
|
||||
}
|
||||
@ -71,12 +92,19 @@ export function* submitCT({
|
||||
if (name !== oldContentTypeName) {
|
||||
emitEvent('didEditNameOfContentType');
|
||||
|
||||
const appPlugins = plugins.toJS ? plugins.toJS() : plugins;
|
||||
const appMenu = get(appPlugins, ['content-manager', 'leftMenuSections'], []);
|
||||
const appPlugins = plugins;
|
||||
const appMenu = get(
|
||||
appPlugins,
|
||||
['content-manager', 'leftMenuSections'],
|
||||
[],
|
||||
);
|
||||
const oldContentTypeNameIndex = appMenu[0].links.findIndex(
|
||||
el => el.destination === oldContentTypeName,
|
||||
);
|
||||
const updatedLink = { destination: name.toLowerCase(), label: capitalize(pluralize(name)) };
|
||||
const updatedLink = {
|
||||
destination: name.toLowerCase(),
|
||||
label: capitalize(pluralize(name)),
|
||||
};
|
||||
appMenu[0].links.splice(oldContentTypeNameIndex, 1, updatedLink);
|
||||
appMenu[0].links = sortBy(appMenu[0].links, 'label');
|
||||
updatePlugin('content-manager', 'leftMenuSections', appMenu);
|
||||
@ -92,7 +120,10 @@ export function* submitCT({
|
||||
}
|
||||
|
||||
/* istanbul ignore-next */
|
||||
export function* submitTempCT({ body, context: { emitEvent, plugins, updatePlugin } }) {
|
||||
export function* submitTempCT({
|
||||
body,
|
||||
context: { emitEvent, plugins, updatePlugin },
|
||||
}) {
|
||||
try {
|
||||
emitEvent('willSaveContentType');
|
||||
|
||||
@ -105,9 +136,16 @@ export function* submitTempCT({ body, context: { emitEvent, plugins, updatePlugi
|
||||
yield put(submitTempContentTypeSucceeded());
|
||||
|
||||
const { name } = body;
|
||||
const appPlugins = plugins.toJS ? plugins.toJS() : plugins;
|
||||
const appMenu = get(appPlugins, ['content-manager', 'leftMenuSections'], []);
|
||||
const newLink = { destination: name.toLowerCase(), label: capitalize(pluralize(name)) };
|
||||
const appPlugins = plugins;
|
||||
const appMenu = get(
|
||||
appPlugins,
|
||||
['content-manager', 'leftMenuSections'],
|
||||
[],
|
||||
);
|
||||
const newLink = {
|
||||
destination: name.toLowerCase(),
|
||||
label: capitalize(pluralize(name)),
|
||||
};
|
||||
appMenu[0].links.push(newLink);
|
||||
appMenu[0].links = sortBy(appMenu[0].links, 'label');
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ class AttributesPickerModal extends React.Component {
|
||||
|
||||
getAttributes = () => {
|
||||
const { plugins } = this.context;
|
||||
const appPlugins = plugins.toJS ? plugins.toJS() : plugins;
|
||||
const appPlugins = plugins;
|
||||
|
||||
return attributes.filter(attr => {
|
||||
if (appPlugins.hasOwnProperty('upload')) {
|
||||
@ -71,7 +71,9 @@ class AttributesPickerModal extends React.Component {
|
||||
const { push } = this.props;
|
||||
|
||||
emitEvent('didSelectContentTypeFieldType', { type });
|
||||
push({ search: `modalType=attributeForm&attributeType=${type}&settingType=base&actionType=create` });
|
||||
push({
|
||||
search: `modalType=attributeForm&attributeType=${type}&settingType=base&actionType=create`,
|
||||
});
|
||||
};
|
||||
|
||||
/* istanbul ignore next */
|
||||
@ -117,9 +119,11 @@ class AttributesPickerModal extends React.Component {
|
||||
this.updateNodeToFocus(next);
|
||||
};
|
||||
|
||||
handleOnClosed = () => this.setState(prevState => ({ isDisplayed: !prevState.isDisplayed }));
|
||||
handleOnClosed = () =>
|
||||
this.setState(prevState => ({ isDisplayed: !prevState.isDisplayed }));
|
||||
|
||||
handleOnOpened = () => this.setState(prevState => ({ isDisplayed: !prevState.isDisplayed }));
|
||||
handleOnOpened = () =>
|
||||
this.setState(prevState => ({ isDisplayed: !prevState.isDisplayed }));
|
||||
|
||||
handleToggle = () => {
|
||||
const { push } = this.props;
|
||||
@ -156,9 +160,13 @@ class AttributesPickerModal extends React.Component {
|
||||
onOpened={this.handleOnOpened}
|
||||
>
|
||||
<HeaderModal>
|
||||
<HeaderModalTitle title={`${pluginId}.popUpForm.choose.attributes.header.title`} />
|
||||
<HeaderModalTitle
|
||||
title={`${pluginId}.popUpForm.choose.attributes.header.title`}
|
||||
/>
|
||||
</HeaderModal>
|
||||
<BodyModal style={{ paddingTop: '2.3rem' }}>{attributes.map(this.renderAttribute)}</BodyModal>
|
||||
<BodyModal style={{ paddingTop: '2.3rem' }}>
|
||||
{attributes.map(this.renderAttribute)}
|
||||
</BodyModal>
|
||||
<FooterModal />
|
||||
</WrapperModal>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user