Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dual API #1128

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,862 changes: 4,861 additions & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion client/dist/styles/bundle.css

Large diffs are not rendered by default.

51 changes: 29 additions & 22 deletions client/src/boot/registerTransforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import SaveAction from 'components/ElementActions/SaveAction';
import UnpublishAction from 'components/ElementActions/UnpublishAction';

export default () => {

const globalUseGraphqQL = false;

Injector.transform(
'elemental-fieldgroup',
(updater) => {
Expand Down Expand Up @@ -49,29 +52,33 @@ export default () => {
}
);

Injector.transform(
'cms-element-editor',
(updater) => {
// Add GraphQL query for reading elements on a page for the ElementEditor
updater.component(
'ElementList',
readBlocksForAreaQuery,
'PageElements'
);
}
);
if (globalUseGraphqQL) {
Injector.transform(
'cms-element-editor',
(updater) => {
// Add GraphQL query for reading elements on a page for the ElementEditor
updater.component(
'ElementList',
readBlocksForAreaQuery,
'PageElements'
);
}
);
}

Injector.transform(
'cms-element-adder',
(updater) => {
// Add GraphQL query for adding elements to an ElementEditor (ElementalArea)
updater.component(
'AddElementPopover',
addElementToArea,
'ElementAddButton'
);
}
);
if (globalUseGraphqQL) {
Injector.transform(
'cms-element-adder',
(updater) => {
// Add GraphQL query for adding elements to an ElementEditor (ElementalArea)
updater.component(
'AddElementPopover',
addElementToArea,
'ElementAddButton'
);
}
);
}

// Add elemental editor actions
Injector.transform('element-actions', (updater) => {
Expand Down
37 changes: 25 additions & 12 deletions client/src/components/ElementActions/ArchiveAction.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
/* global window */
import React from 'react';
import React, { useContext } from 'react';
import { compose } from 'redux';
import AbstractAction from 'components/ElementActions/AbstractAction';
import archiveBlockMutation from 'state/editor/archiveBlockMutation';
import i18n from 'i18n';
import { ElementEditorContext } from 'components/ElementEditor/ElementEditor';
import backend from 'lib/Backend';

/**
* Adds the elemental menu action to archive a block of any state
*/
const ArchiveAction = (MenuComponent) => (props) => {
const { fetchBlocks } = useContext(ElementEditorContext);

const handleClick = (event) => {
event.stopPropagation();

const { element: { id }, isPublished, actions: { handleArchiveBlock } } = props;

const isPublished = props.element.isPublished;
let archiveMessage = i18n._t(
'ElementArchiveAction.CONFIRM_DELETE',
'Are you sure you want to send this block to the archive?'
);

if (isPublished) {
archiveMessage = i18n._t(
'ElementArchiveAction.CONFIRM_DELETE_AND_UNPUBLISH',
'Warning: This block will be unpublished before being sent to the archive. Are you sure you want to proceed?'
);
}

// eslint-disable-next-line no-alert
if (handleArchiveBlock && window.confirm(archiveMessage)) {
handleArchiveBlock(id).then(() => {
const preview = window.jQuery('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
});
if (!window.confirm(archiveMessage)) {
return;
}
const globalUseGraphqQL = false;
if (globalUseGraphqQL) {
const { element: { id }, actions: { handleArchiveBlock } } = props;
// eslint-disable-next-line no-alert
if (handleArchiveBlock) {
handleArchiveBlock(id).then(() => {
const preview = window.jQuery('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
});
}
} else {
const id = props.element.id;
backend.post(`/admin/elemental-area/archive`, {
ID: id,
})
.then(() => fetchBlocks());
}
};

Expand Down
31 changes: 21 additions & 10 deletions client/src/components/ElementActions/DuplicateAction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
/* global window */
import React from 'react';
import React, { useContext } from 'react';
import { compose } from 'redux';
import AbstractAction from 'components/ElementActions/AbstractAction';
import duplicateBlockMutation from 'state/editor/duplicateBlockMutation';
import i18n from 'i18n';
import { ElementEditorContext } from 'components/ElementEditor/ElementEditor';
import backend from 'lib/Backend';

/**
* Adds the elemental menu action to duplicate a block
*/
const DuplicateAction = (MenuComponent) => (props) => {
const { fetchBlocks } = useContext(ElementEditorContext);

if (props.type.broken) {
// Don't allow this action for a broken element.
return (
Expand All @@ -18,16 +22,23 @@ const DuplicateAction = (MenuComponent) => (props) => {

const handleClick = (event) => {
event.stopPropagation();

const { element: { id }, actions: { handleDuplicateBlock } } = props;

if (handleDuplicateBlock) {
handleDuplicateBlock(id).then(() => {
const preview = window.jQuery('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
});
const globalUseGraphqQL = false;
if (globalUseGraphqQL) {
const { element: { id }, actions: { handleDuplicateBlock } } = props;
if (handleDuplicateBlock) {
handleDuplicateBlock(id).then(() => {
const preview = window.jQuery('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
});
}
} else {
const id = props.element.id;
backend.post('/admin/elemental-area/duplicate', {
ID: id,
})
.then(() => fetchBlocks());
}
};
}

const disabled = props.element.canCreate !== undefined && !props.element.canCreate;
const label = i18n._t('ElementArchiveAction.DUPLICATE', 'Duplicate');
Expand Down
25 changes: 21 additions & 4 deletions client/src/components/ElementActions/PublishAction.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global window */
import React from 'react';
import React, { useContext } from 'react';
import { compose } from 'redux';
import AbstractAction from 'components/ElementActions/AbstractAction';
import publishBlockMutation from 'state/editor/publishBlockMutation';
Expand All @@ -9,6 +9,7 @@ import { connect } from 'react-redux';
import { loadElementSchemaValue } from 'state/editor/loadElementSchemaValue';
import { loadElementFormStateName } from 'state/editor/loadElementFormStateName';
import { initialize } from 'redux-form';
import { ElementEditorContext } from 'components/ElementEditor/ElementEditor';

/**
* Show a toast message reporting whether publication of Element was successful
Expand Down Expand Up @@ -76,6 +77,8 @@ const performSaveForElementWithFormData = (id, formData, securityId) => {
* Adds the elemental menu action to publish a draft/modified block
*/
const PublishAction = (MenuComponent) => (props) => {
const { fetchBlocks } = useContext(ElementEditorContext);

if (props.type.broken) {
// Don't allow this action for a broken element.
return (
Expand All @@ -85,6 +88,20 @@ const PublishAction = (MenuComponent) => (props) => {

const { element, formDirty } = props;

const publishElement = () => {
const globalUseGraphqQL = false;
if (globalUseGraphqQL) {
const { element: { id }, actions: { handleArchiveBlock } } = props;
return handleArchiveBlock(id);
} else {
const id = props.element.id;
return backend.post('/admin/elemental-area/publish', {
ID: id,
})
.then(() => fetchBlocks());
}
}

const handleClick = (event) => {
event.stopPropagation();

Expand All @@ -96,7 +113,6 @@ const PublishAction = (MenuComponent) => (props) => {
type,
securityId,
formData,
actions: { handlePublishBlock },
reinitialiseForm,
} = props;

Expand All @@ -113,7 +129,8 @@ const PublishAction = (MenuComponent) => (props) => {

// Perform publish. Data is assumed to be up to date
actionFlow
.then(() => handlePublishBlock(id))
// .then(() => handlePublishBlock(id))
.then(() => publishElement())
.then(() => reportPublicationStatus(type.title, title, true))
.catch(() => reportPublicationStatus(type.title, title, false));
};
Expand Down Expand Up @@ -169,7 +186,7 @@ function mapDispatchToProps(dispatch, ownProps) {
export { PublishAction as Component };

export default compose(
publishBlockMutation,
publishBlockMutation, // todo
connect(mapStateToProps, mapDispatchToProps),
PublishAction
);
82 changes: 43 additions & 39 deletions client/src/components/ElementActions/UnpublishAction.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,71 @@
/* global window */
import React from 'react';
import React, { useContext } from 'react';
import { compose } from 'redux';
import AbstractAction from 'components/ElementActions/AbstractAction';
import unpublishBlockMutation from 'state/editor/unpublishBlockMutation';
import i18n from 'i18n';
import backend from 'lib/Backend';
import { ElementEditorContext } from 'components/ElementEditor/ElementEditor';

/**
* Adds the elemental menu action to unpublish a published block
*/
const UnpublishAction = (MenuComponent) => (props) => {
const { fetchBlocks } = useContext(ElementEditorContext);
const globalUseGraphqQL = false;

if (props.type.broken) {
// Don't allow this action for a broken element.
return (
<MenuComponent {...props} />
);
}

const { element, type, actions: { handleUnpublishBlock } } = props;

const handleClick = (event) => {
event.stopPropagation();
const { jQuery: $ } = window;
const reportUnpublicationStatus = (type, title, success) => {
const noTitle = i18n.inject(
i18n._t(
'ElementHeader.NOTITLE',
'Untitled {type} block'
),
{ type: type.title }
i18n._t('ElementHeader.NOTITLE', 'Untitled {type} block'),
{ type }
);
const successMessage = i18n.inject(
i18n._t('ElementUnpublishAction.SUCCESS_NOTIFICATION', 'Removed \'{title}\' from the published page'),
{ title: title || noTitle }
);
const errorMessage = i18n.inject(
i18n._t('ElementUnpublishAction.ERROR_NOTIFICATION', 'Error unpublishing \'{title}\''),
{ title: title || noTitle }
);
window.jQuery.noticeAdd({
text: success ? successMessage : errorMessage,
stay: false,
type: success ? 'success' : 'error',
});
}

if (handleUnpublishBlock) {
handleUnpublishBlock(element.id)
const unpublishElement = () => {
if (globalUseGraphqQL) {
const { element: { id }, actions: { handleUnpublishBlock } } = props;
return handleUnpublishBlock(id)
.then(() => {
const preview = $('.cms-preview');
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));

$.noticeAdd({
text: i18n.inject(
i18n._t(
'ElementUnpublishAction.SUCCESS_NOTIFICATION',
'Removed \'{title}\' from the published page'
),
{ title: element.title || noTitle }
),
stay: false,
type: 'success'
});
})
.catch(() => {
$.noticeAdd({
text: i18n.inject(
i18n._t(
'ElementUnpublishAction.ERROR_NOTIFICATION',
'Error unpublishing \'{title}\''
),
{ title: element.title || noTitle }
),
stay: false,
type: 'error'
});
});
} else {
const id = props.element.id;
return backend.post('/admin/elemental-area/unpublish', {
ID: id,
})
.then(() => fetchBlocks());
}
};
}

const { element, type } = props;

const handleClick = (event) => {
event.stopPropagation();
unpublishElement()
.then(() => reportUnpublicationStatus(type.title, element.title, true))
.catch(() => reportUnpublicationStatus(type.title, element.title, false));
}

const disabled = props.element.canUnpublish !== undefined && !props.element.canUnpublish;
const label = i18n._t('ElementArchiveAction.UNPUBLISH', 'Unpublish');
Expand Down
Loading
Loading