Skip to content

Commit

Permalink
TASK: Remove plow-js from @neos-project/neos-ui-sagas
Browse files Browse the repository at this point in the history
  • Loading branch information
grebaldi committed Dec 22, 2022
1 parent 1f4766c commit 8603b0c
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 86 deletions.
1 change: 0 additions & 1 deletion packages/neos-ui-sagas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@neos-project/neos-ui-redux-store": "workspace:*",
"lodash.escaperegexp": "^4.1.2",
"mousetrap": "^1.6.3",
"plow-js": "^2.2.0",
"redux-saga": "^0.15.0"
},
"license": "GNU GPLv3",
Expand Down
7 changes: 4 additions & 3 deletions packages/neos-ui-sagas/src/CR/ContentDimensions/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {put, select, race, take, takeLatest, takeEvery, call} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actions, actionTypes, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
Expand All @@ -22,7 +21,7 @@ export function * watchSelectPreset() {
yield take(actionTypes.CR.ContentDimensions.SELECT_PRESET);
const targetDimensions = yield select(selectors.CR.ContentDimensions.active);
const currentContentCanvasNode = yield select(selectors.CR.Nodes.documentNodeSelector);
const currentContentCanvasNodeIdentifier = $get('identifier', currentContentCanvasNode);
const currentContentCanvasNodeIdentifier = currentContentCanvasNode?.identifier;

const informationAboutNodeInTargetDimension = yield call(ensureNodeInSelectedDimension, {
nodeIdentifier: currentContentCanvasNodeIdentifier,
Expand Down Expand Up @@ -67,7 +66,9 @@ function * ensureNodeInSelectedDimension({nodeIdentifier, sourceDimensions, targ
getSingleNode,
adoptNodeToOtherDimension
} = backend.get().endpoints;
const currentWorkspaceName = yield select($get('cr.workspaces.personalWorkspace.name'));
const currentWorkspaceName = yield select(
state => state?.cr?.workspaces?.personalWorkspace?.name
);

const {
nodeFound,
Expand Down
9 changes: 5 additions & 4 deletions packages/neos-ui-sagas/src/CR/NodeOperations/addNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {takeLatest, take, put, race, call, select} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actions, actionTypes, selectors} from '@neos-project/neos-ui-redux-store';

Expand Down Expand Up @@ -54,8 +53,8 @@ function * nodeCreationWorkflow(context, step = STEP_SELECT_NODETYPE, workflowDa
}
case STEP_NODE_CREATION_DIALOG: {
const nodeType = nodeTypesRegistry.get(workflowData.nodeType);
const label = $get('label', nodeType);
const configuration = $get('ui.creationDialog', nodeType);
const label = nodeType?.label;
const configuration = nodeType?.ui?.creationDialog;
if (configuration) {
//
// This node type has a creationDialog configuration,
Expand Down Expand Up @@ -97,7 +96,9 @@ function * nodeCreationWorkflow(context, step = STEP_SELECT_NODETYPE, workflowDa

const referenceNodeSelector = selectors.CR.Nodes.makeGetNodeByContextPathSelector(referenceNodeContextPath);
const referenceNode = yield select(referenceNodeSelector);
const baseNodeType = yield select($get('ui.pageTree.filterNodeType'));
const baseNodeType = yield select(
state => state?.ui?.pageTree?.filterNodeType
);
const data = yield * applySaveHooksForTransientValuesMap(transientValues, saveHooksRegistry);

return yield put(actions.Changes.persistChanges([{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {takeEvery, put, select} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actions, actionTypes, selectors} from '@neos-project/neos-ui-redux-store';

Expand All @@ -11,7 +10,9 @@ export default function * moveDroppedNode() {

const referenceNodeSelector = selectors.CR.Nodes.makeGetNodeByContextPathSelector(reference);
const referenceNode = yield select(referenceNodeSelector);
const baseNodeType = yield select($get('ui.pageTree.filterNodeType'));
const baseNodeType = yield select(
state => state?.ui?.pageTree?.filterNodeType
);

yield put(actions.Changes.persistChanges([{
type: calculateChangeTypeFromMode(position, 'Move'),
Expand Down
9 changes: 6 additions & 3 deletions packages/neos-ui-sagas/src/CR/NodeOperations/pasteNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {takeEvery, put, select, call} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {selectors, actions, actionTypes} from '@neos-project/neos-ui-redux-store';

Expand All @@ -13,7 +12,9 @@ export default function * pasteNode({globalRegistry}) {

yield takeEvery(actionTypes.CR.Nodes.PASTE, function * waitForPaste(action) {
const subject = yield select(selectors.CR.Nodes.clipboardNodesContextPathsSelector);
const clipboardMode = yield select($get('cr.nodes.clipboardMode'));
const clipboardMode = yield select(
state => state?.cr?.nodes?.clipboardMode
);

const {contextPath: reference, fusionPath} = action.payload;
const state = yield select();
Expand All @@ -38,7 +39,9 @@ export default function * pasteNode({globalRegistry}) {
if (mode) {
const referenceNodeSelector = selectors.CR.Nodes.makeGetNodeByContextPathSelector(reference);
const referenceNode = yield select(referenceNodeSelector);
const baseNodeType = yield select($get('ui.pageTree.filterNodeType'));
const baseNodeType = yield select(
state => state?.ui?.pageTree?.filterNodeType
);

yield put(actions.CR.Nodes.commitPaste(clipboardMode));
const changes = subject.map(contextPath => ({
Expand Down
18 changes: 11 additions & 7 deletions packages/neos-ui-sagas/src/CR/NodeOperations/reloadState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {takeLatest, put, select} from 'redux-saga/effects';
import {$get} from 'plow-js';

import backend from '@neos-project/neos-ui-backend-connector';

import {selectors, actions, actionTypes} from '@neos-project/neos-ui-redux-store';
Expand All @@ -8,11 +8,15 @@ export default function * watchReloadState({configuration}) {
yield takeLatest(actionTypes.CR.Nodes.RELOAD_STATE, function * reloadState(action) {
const {q} = backend.get();

const currentSiteNodeContextPath = yield select($get('cr.nodes.siteNode'));
const currentSiteNodeContextPath = yield select(
state => state?.cr?.nodes?.siteNode
);
const clipboardNodesContextPaths = yield select(selectors.CR.Nodes.clipboardNodesContextPathsSelector);
const toggledNodes = yield select($get('ui.pageTree.toggled'));
const siteNodeContextPath = $get('payload.siteNodeContextPath', action) || currentSiteNodeContextPath;
const documentNodeContextPath = yield $get('payload.documentNodeContextPath', action) || select($get('cr.nodes.documentNode'));
const toggledNodes = yield select(
state => state?.ui?.pageTree?.toggled
);
const siteNodeContextPath = action?.payload?.siteNodeContextPath || currentSiteNodeContextPath;
const documentNodeContextPath = yield action?.payload?.documentNodeContextPath || select(state => state?.cr?.nodes?.documentNode);
yield put(actions.CR.Nodes.setDocumentNode(documentNodeContextPath, currentSiteNodeContextPath));
yield put(actions.UI.PageTree.setAsLoading(currentSiteNodeContextPath));
const nodes = yield q([siteNodeContextPath, documentNodeContextPath]).neosUiDefaultNodes(
Expand All @@ -22,14 +26,14 @@ export default function * watchReloadState({configuration}) {
clipboardNodesContextPaths
).getForTree();
const nodeMap = nodes.reduce((nodeMap, node) => {
nodeMap[$get('contextPath', node)] = node;
nodeMap[node?.contextPath] = node;
return nodeMap;
}, {});
yield put(actions.CR.Nodes.setState({
siteNodeContextPath,
documentNodeContextPath,
nodes: nodeMap,
merge: $get('payload.merge', action)
merge: action?.payload?.merge
}));
yield put(actions.UI.PageTree.setAsLoaded(currentSiteNodeContextPath));
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {takeLatest, take, put, race, select} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actions, actionTypes} from '@neos-project/neos-ui-redux-store';

Expand All @@ -17,7 +16,7 @@ export default function * removeNodeIfConfirmed() {
}

if (nextAction.type === actionTypes.CR.Nodes.REMOVAL_CONFIRMED) {
const nodesToBeRemovedContextPath = $get('cr.nodes.toBeRemoved', state);
const nodesToBeRemovedContextPath = state?.cr?.nodes?.toBeRemoved;
const changes = nodesToBeRemovedContextPath.map(nodeToBeRemovedContextPath => ({
type: 'Neos.Neos.Ui:RemoveNode',
subject: nodeToBeRemovedContextPath
Expand Down
6 changes: 3 additions & 3 deletions packages/neos-ui-sagas/src/CR/Policies/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {select, take, put, fork} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actions, actionTypes, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';

Expand Down Expand Up @@ -30,11 +30,11 @@ export function * watchNodeInformationChanges() {
const nodesWithoutAdditionalMetadata = Object.keys(nodeMap).filter(contextPath => {
const node = selectors.CR.Nodes.nodeByContextPath(state)(contextPath);

if ($get('properties._removed', node)) {
if (node?.properties?._removed) {
return false;
}

const policyInfo = $get('policy', node);
const policyInfo = node?.policy;
return (!policyInfo);
});

Expand Down
7 changes: 3 additions & 4 deletions packages/neos-ui-sagas/src/Changes/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {takeEvery, put, call, select} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actionTypes, actions, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
Expand All @@ -16,12 +15,12 @@ function * persistChanges(changes) {
yield put(actions.ServerFeedback.handleServerFeedback(feedback));

const state = yield select();
const isAutoPublishingEnabled = $get('user.settings.isAutoPublishingEnabled', state);
const isAutoPublishingEnabled = state?.user?.settings?.isAutoPublishingEnabled ?? false;

if (isAutoPublishingEnabled) {
const baseWorkspace = baseWorkspaceSelector(state);
const publishableNodesInDocument = publishableNodesInDocumentSelector(state);
yield put(actions.CR.Workspaces.publish(publishableNodesInDocument.map($get('contextPath')), baseWorkspace));
yield put(actions.CR.Workspaces.publish(publishableNodesInDocument.map(node => node?.contextPath), baseWorkspace));
}
} catch (error) {
console.error('Failed to persist changes', error);
Expand Down Expand Up @@ -54,7 +53,7 @@ export function * watchPersist() {
// If there's already a pending request, don't start the new one;
// the data will be stored in `changes` closure and when the current request finishes saving
// it will be re-triggered by FINISH_SAVING
if (changes.length > 0 && !$get('ui.remote.isSaving', state)) {
if (changes.length > 0 && !state?.ui?.remote?.isSaving) {
// we need to clear out the changes array before yield, so the best I could think of is this
const clonedChanges = changes.slice(0);
changes = [];
Expand Down
11 changes: 6 additions & 5 deletions packages/neos-ui-sagas/src/Publish/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {put, call, select, takeEvery, takeLatest, take, race} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {actionTypes, actions, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
Expand Down Expand Up @@ -30,11 +29,11 @@ export function * watchPublish() {
export function * watchToggleAutoPublish() {
yield takeEvery(actionTypes.User.Settings.TOGGLE_AUTO_PUBLISHING, function * publishInitially() {
const state = yield select();
const isAutoPublishingEnabled = $get('user.settings.isAutoPublishingEnabled', state);
const isAutoPublishingEnabled = state?.user?.settings?.isAutoPublishingEnabled;

if (isAutoPublishingEnabled) {
const publishableNodesInDocument = publishableNodesInDocumentSelector(state);
yield put(actions.CR.Workspaces.publish(publishableNodesInDocument.map($get('contextPath')), 'live'));
yield put(actions.CR.Workspaces.publish(publishableNodesInDocument.map(node => node?.contextPath), 'live'));
}
});
}
Expand All @@ -43,7 +42,9 @@ export function * watchChangeBaseWorkspace() {
const {changeBaseWorkspace} = backend.get().endpoints;
yield takeEvery(actionTypes.CR.Workspaces.CHANGE_BASE_WORKSPACE, function * change(action) {
try {
const documentNode = yield select($get('cr.nodes.documentNode'));
const documentNode = yield select(
state => state?.cr?.nodes?.documentNode
);
const feedback = yield call(changeBaseWorkspace, action.payload, documentNode);
yield put(actions.ServerFeedback.handleServerFeedback(feedback));

Expand Down Expand Up @@ -71,7 +72,7 @@ export function * discardIfConfirmed() {

if (nextAction.type === actionTypes.CR.Workspaces.DISCARD_CONFIRMED) {
yield put(actions.UI.Remote.startDiscarding());
const nodesToBeDiscarded = $get('cr.workspaces.toBeDiscarded', state);
const nodesToBeDiscarded = state?.cr?.workspaces?.toBeDiscarded;

try {
const currentContentCanvasContextPath = yield select(selectors.CR.Nodes.documentNodeContextPathSelector);
Expand Down
16 changes: 11 additions & 5 deletions packages/neos-ui-sagas/src/UI/ContentCanvas/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {delay} from 'redux-saga';
import {takeLatest, put, select, take, race} from 'redux-saga/effects';
import {$get} from 'plow-js';

import {getGuestFrameDocument} from '@neos-project/neos-ui-guest-frame/src/dom';

import {actionTypes, actions} from '@neos-project/neos-ui-redux-store';
Expand All @@ -11,9 +11,11 @@ import {actionTypes, actions} from '@neos-project/neos-ui-redux-store';
export function * watchNodeCreated() {
yield takeLatest(actionTypes.UI.Remote.DOCUMENT_NODE_CREATED, function * nodeCreated(action) {
const {contextPath} = action.payload;
const node = yield select($get(['cr', 'nodes', 'byContextPath', contextPath]));
const node = yield select(
state => state?.cr?.nodes?.byContextPath?.[contextPath]
);
yield put(actions.CR.Nodes.setDocumentNode(contextPath));
yield put(actions.UI.ContentCanvas.setSrc($get('uri', node)));
yield put(actions.UI.ContentCanvas.setSrc(node?.uri));
});
}
/**
Expand Down Expand Up @@ -44,7 +46,9 @@ export function * watchStopLoading({globalRegistry, store}) {
export function * watchReload() {
yield takeLatest(actionTypes.UI.ContentCanvas.RELOAD, function * (action) {
const {uri} = action.payload;
const currentIframeUrl = yield select($get('ui.contentCanvas.src'));
const currentIframeUrl = yield select(
state => state?.ui?.contentCanvas?.src
);

[].slice.call(document.querySelectorAll(`iframe[name=neos-content-main]`)).forEach(iframe => {
const iframeWindow = iframe.contentWindow || iframe;
Expand All @@ -65,7 +69,9 @@ export function * watchControlOverIFrame() {
yield take(actionTypes.System.READY);

while (true) { //eslint-disable-line
const src = yield select($get('ui.contentCanvas.src'));
const src = yield select(
state => state?.ui?.contentCanvas?.src
);
const waitForNextAction = yield race([
take(actionTypes.UI.ContentCanvas.SET_SRC),
take(actionTypes.UI.ContentCanvas.REQUEST_REGAIN_CONTROL),
Expand Down
Loading

0 comments on commit 8603b0c

Please sign in to comment.