Skip to content

Commit

Permalink
API Standardise endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jul 18, 2024
1 parent 94193a5 commit af828ad
Show file tree
Hide file tree
Showing 45 changed files with 992 additions and 1,459 deletions.
10 changes: 0 additions & 10 deletions _config/graphql.yml

This file was deleted.

5 changes: 0 additions & 5 deletions _graphql/config.yml

This file was deleted.

41 changes: 0 additions & 41 deletions _graphql/models.yml

This file was deleted.

9 changes: 0 additions & 9 deletions _graphql/mutations.yml

This file was deleted.

4 changes: 0 additions & 4 deletions _graphql/scalars.yml

This file was deleted.

80 changes: 2 additions & 78 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

34 changes: 4 additions & 30 deletions client/src/boot/registerTransforms.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Injector from 'lib/Injector';
import readOneBlockQuery from 'state/history/readOneBlockQuery';
import HistoricElementViewFactory from 'components/HistoricElementView/HistoricElementView';
import revertToBlockVersionMutation from 'state/history/revertToBlockVersionMutation';
import readBlocksForAreaQuery from 'state/editor/readBlocksForAreaQuery';
import addElementToArea from 'state/editor/addElementMutation';
import revertToBlockVersionRequest from 'state/history/revertToBlockVersionRequest';
import ArchiveAction from 'components/ElementActions/ArchiveAction';
import DuplicateAction from 'components/ElementActions/DuplicateAction';
import SaveAction from 'components/ElementActions/SaveAction';
Expand Down Expand Up @@ -40,35 +38,11 @@ export default () => {
Injector.transform(
'blocks-history-revert',
(updater) => {
// Add block element revert GraphQL mutation to the HistoryViewerToolbar
// Add revertToVersion() to props.actions on HistoryViewerToolbar
updater.component(
'HistoryViewerToolbar.VersionedAdmin.HistoryViewer.Element.HistoryViewerVersionDetail',
revertToBlockVersionMutation,
'BlockRevertMutation'
);
}
);

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'
revertToBlockVersionRequest,
'BlockRevertRequest'
);
}
);
Expand Down
32 changes: 16 additions & 16 deletions client/src/components/ElementActions/ArchiveAction.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
/* global window */
import React from 'react';
import { compose } from 'redux';
import React, { useContext } from 'react';
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';
import { getConfig } from 'state/editor/elementConfig';

/**
* Adds the elemental menu action to archive a block of any state
*/
const ArchiveAction = (MenuComponent) => (props) => {
const { fetchElements } = 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');
if (preview && typeof preview.entwine === 'function') {
preview.entwine('ss.preview')._loadUrl(preview.find('iframe').attr('src'));
}
});
if (!window.confirm(archiveMessage)) {
return;
}
const id = props.element.id;
const url = `${getConfig().controllerLink.replace(/\/$/, '')}/archive`;
backend.post(url, {
ID: id,
})
.then(() => fetchElements());
};

const disabled = props.element.canDelete !== undefined && !props.element.canDelete;
Expand All @@ -61,4 +61,4 @@ const ArchiveAction = (MenuComponent) => (props) => {

export { ArchiveAction as Component };

export default compose(archiveBlockMutation, ArchiveAction);
export default ArchiveAction;
26 changes: 13 additions & 13 deletions client/src/components/ElementActions/DuplicateAction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/* global window */
import React from 'react';
import { compose } from 'redux';
import React, { useContext } from 'react';
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';
import { getConfig } from 'state/editor/elementConfig';

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

if (props.type.broken) {
// Don't allow this action for a broken element.
return (
Expand All @@ -18,15 +21,12 @@ 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 id = props.element.id;
const url = `${getConfig().controllerLink.replace(/\/$/, '')}/duplicate`;
backend.post(url, {
ID: id,
})
.then(() => fetchElements());
};

const disabled = props.element.canCreate !== undefined && !props.element.canCreate;
Expand All @@ -53,4 +53,4 @@ const DuplicateAction = (MenuComponent) => (props) => {

export { DuplicateAction as Component };

export default compose(duplicateBlockMutation, DuplicateAction);
export default DuplicateAction;
84 changes: 39 additions & 45 deletions client/src/components/ElementActions/UnpublishAction.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,60 @@
/* global window */
import React from 'react';
import { compose } from 'redux';
import React, { useContext } from 'react';
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';
import { getConfig } from 'state/editor/elementConfig';

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

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',
});
};

const unpublishElement = () => {
const id = props.element.id;
const url = `${getConfig().controllerLink.replace(/\/$/, '')}/unpublish`;
return backend.post(url, {
ID: id,
})
.then(() => fetchElements());
};

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

$.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'
});
});
}
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;
Expand All @@ -87,4 +81,4 @@ const UnpublishAction = (MenuComponent) => (props) => {

export { UnpublishAction as Component };

export default compose(unpublishBlockMutation, UnpublishAction);
export default UnpublishAction;
Loading

0 comments on commit af828ad

Please sign in to comment.