Skip to content

Commit

Permalink
API Remove GraphQL
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Aug 27, 2024
1 parent bc77fd4 commit ac6824a
Show file tree
Hide file tree
Showing 54 changed files with 2,112 additions and 1,802 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.

110 changes: 1 addition & 109 deletions client/dist/js/bundle.js

Large diffs are not rendered by default.

47 changes: 4 additions & 43 deletions client/src/boot/registerTransforms.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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 All @@ -25,50 +22,14 @@ export default () => {
}
);

Injector.transform(
'elements-history',
(updater) => {
// Add content block history to the HistoryViewer
updater.component(
'HistoryViewer.Form_ItemEditForm',
readOneBlockQuery,
'ElementHistoryViewer'
);
}
);

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
53 changes: 37 additions & 16 deletions client/src/components/ElementActions/ArchiveAction.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,51 @@
/* 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 Config from 'lib/Config';
import { getConfig } from 'state/editor/elementConfig';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import * as toastsActions from 'state/toasts/ToastsActions';
import getJsonErrorMessage from 'lib/getJsonErrorMessage';

/**
* 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(/\/$/, '')}/api/delete`;
backend.post(url, {
id
}, {
'X-SecurityID': Config.get('SecurityID')
})
.then(() => fetchElements())
.catch(async (err) => {
const message = await getJsonErrorMessage(err);
props.actions.toasts.error(message);
});
};

const disabled = props.element.canDelete !== undefined && !props.element.canDelete;
Expand All @@ -59,6 +70,16 @@ const ArchiveAction = (MenuComponent) => (props) => {
);
};

function mapDispatchToProps(dispatch) {
return {
actions: {
toasts: bindActionCreators(toastsActions, dispatch),
},
};
}

export { ArchiveAction as Component };

export default compose(archiveBlockMutation, ArchiveAction);
export default compose(
connect(() => {}, mapDispatchToProps),
)(ArchiveAction);
45 changes: 33 additions & 12 deletions client/src/components/ElementActions/DuplicateAction.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
/* 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 Config from 'lib/Config';
import { getConfig } from 'state/editor/elementConfig';
import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux';
import * as toastsActions from 'state/toasts/ToastsActions';
import getJsonErrorMessage from 'lib/getJsonErrorMessage';

/**
* 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 +26,18 @@ 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(/\/$/, '')}/api/duplicate`;
backend.post(url, {
id,
}, {
'X-SecurityID': Config.get('SecurityID')
})
.then(() => fetchElements())
.catch(async (err) => {
const message = await getJsonErrorMessage(err);
props.actions.toasts.error(message);
});
}
};

const disabled = props.element.canCreate !== undefined && !props.element.canCreate;
Expand All @@ -51,6 +62,16 @@ const DuplicateAction = (MenuComponent) => (props) => {
);
};

function mapDispatchToProps(dispatch) {
return {
actions: {
toasts: bindActionCreators(toastsActions, dispatch),
},
};
}

export { DuplicateAction as Component };

export default compose(duplicateBlockMutation, DuplicateAction);
export default compose(
connect(() => {}, mapDispatchToProps),
)(DuplicateAction);
Loading

0 comments on commit ac6824a

Please sign in to comment.