@@ -2,50 +2,53 @@ import {takeLatest, take, select, call, put, race} from 'redux-saga/effects';
22import { $get } from 'plow-js' ;
33import { actionTypes , selectors } from '@neos-project/neos-ui-redux-store' ;
44import { 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+
0 commit comments