Skip to content

Commit ff02cee

Browse files
committed
TASK: get original saga from the registry
1 parent e5697d4 commit ff02cee

4 files changed

Lines changed: 155 additions & 163 deletions

File tree

Resources/Private/RestrictCreation/src/manifest.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import manifest from '@neos-project/neos-ui-extensibility';
22
import RestrictCreationDialog from './RestrictCreationDialog';
33
import {reducer} from './redux';
4-
import {addNode} from './sagas';
4+
import {makeAddNode} from './sagas';
55

66
manifest('Flowpack.RestrictCreation:RestrictCreation', {}, globalRegistry => {
77
const sagasRegistry = globalRegistry.get('sagas');
88

9+
const originalAddNodeSaga = sagasRegistry.get('neos-ui/CR/NodeOperations/addNode');
910
sagasRegistry.set('neos-ui/CR/NodeOperations/addNode', {
10-
saga: addNode
11+
saga: makeAddNode(originalAddNodeSaga.nodeCreationWorkflow)
1112
});
1213

1314
const reducersRegistry = globalRegistry.get('reducers');

Resources/Private/RestrictCreation/src/sagas.js

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,53 @@ import {takeLatest, take, select, call, put, race} from 'redux-saga/effects';
22
import {$get} from 'plow-js';
33
import {actionTypes, selectors} from '@neos-project/neos-ui-redux-store';
44
import {actions as localActions, actionTypes as localActionTypes, selectors as localSelectors} from './redux';
5-
import {crNodeOperations} from '@neos-project/neos-ui-sagas';
65

7-
export function * addNode({globalRegistry}) {
8-
const nodeTypesRegistry = globalRegistry.get('@neos-project/neos-ui-contentrepository');
9-
10-
yield takeLatest(actionTypes.CR.Nodes.COMMENCE_CREATION, function* (action) {
11-
const {referenceNodeContextPath, referenceNodeFusionPath} = action.payload;
12-
13-
const state = yield select();
14-
const restrictCreationPreset = localSelectors.restrictCreationSelector(state);
15-
16-
// Show restrict creation dialog if mode is not null
17-
let showRestrictCreationDialog = Boolean($get('restrictCreation.mode', restrictCreationPreset));
18-
const documentNodesOnly = $get('restrictCreation.documentNodesOnly', restrictCreationPreset);
19-
20-
if (documentNodesOnly) {
21-
const getNodeByContextPathSelector = selectors.CR.Nodes.makeGetNodeByContextPathSelector(referenceNodeContextPath);
22-
const referenceNode = yield select(getNodeByContextPathSelector);
23-
const isDocument = nodeTypesRegistry.hasRole($get('nodeType', referenceNode), 'document');
24-
// Skip the dialog if not document node
25-
showRestrictCreationDialog = isDocument;
26-
}
27-
28-
const context = {
29-
nodeTypesRegistry,
30-
referenceNodeContextPath,
31-
referenceNodeFusionPath
32-
};
33-
if (showRestrictCreationDialog) {
34-
yield put(localActions.openDialog());
35-
const waitForNextAction = yield race([
36-
take(localActionTypes.OPEN_DIALOG),
37-
take(localActionTypes.CLOSE_DIALOG),
38-
take(localActionTypes.CONTINUE_CREATION)
39-
]);
40-
const nextAction = Object.values(waitForNextAction)[0];
41-
42-
if (nextAction.type === localActionTypes.CONTINUE_CREATION) {
43-
yield call(crNodeOperations.addNode.nodeCreationWorkflow, context);
6+
export function makeAddNode(nodeCreationWorkflow) {
7+
function * addNode({globalRegistry}) {
8+
const nodeTypesRegistry = globalRegistry.get('@neos-project/neos-ui-contentrepository');
9+
10+
yield takeLatest(actionTypes.CR.Nodes.COMMENCE_CREATION, function* (action) {
11+
const {referenceNodeContextPath, referenceNodeFusionPath} = action.payload;
12+
13+
const state = yield select();
14+
const restrictCreationPreset = localSelectors.restrictCreationSelector(state);
15+
16+
// Show restrict creation dialog if mode is not null
17+
let showRestrictCreationDialog = Boolean($get('restrictCreation.mode', restrictCreationPreset));
18+
const documentNodesOnly = $get('restrictCreation.documentNodesOnly', restrictCreationPreset);
19+
20+
if (documentNodesOnly) {
21+
const getNodeByContextPathSelector = selectors.CR.Nodes.makeGetNodeByContextPathSelector(referenceNodeContextPath);
22+
const referenceNode = yield select(getNodeByContextPathSelector);
23+
const isDocument = nodeTypesRegistry.hasRole($get('nodeType', referenceNode), 'document');
24+
// Skip the dialog if not document node
25+
showRestrictCreationDialog = isDocument;
26+
}
27+
28+
const context = {
29+
nodeTypesRegistry,
30+
referenceNodeContextPath,
31+
referenceNodeFusionPath
32+
};
33+
if (showRestrictCreationDialog) {
34+
yield put(localActions.openDialog());
35+
const waitForNextAction = yield race([
36+
take(localActionTypes.OPEN_DIALOG),
37+
take(localActionTypes.CLOSE_DIALOG),
38+
take(localActionTypes.CONTINUE_CREATION)
39+
]);
40+
const nextAction = Object.values(waitForNextAction)[0];
41+
42+
if (nextAction.type === localActionTypes.CONTINUE_CREATION) {
43+
yield call(nodeCreationWorkflow, context);
44+
} else {
45+
return;
46+
}
4447
} else {
45-
return;
48+
yield call(nodeCreationWorkflow, context);
4649
}
47-
} else {
48-
yield call(crNodeOperations.addNode.nodeCreationWorkflow, context);
49-
}
50-
});
50+
});
51+
}
52+
return addNode;
5153
}
54+

Resources/Public/JavaScript/RestrictCreation/Plugin.js

Lines changed: 105 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Resources/Public/JavaScript/RestrictCreation/Plugin.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)