11// This executes all actions that are requested by the preview
2+ import resolveModule from 'common/sandbox/resolve-module' ;
23
34import notifActions from '../notifications/actions' ;
45import moduleActions from '../entities/sandboxes/modules/actions' ;
56import sandboxActions from '../entities/sandboxes/actions' ;
7+ import { modulesFromSandboxSelector } from '../entities/sandboxes/modules/selectors' ;
8+ import { directoriesFromSandboxSelector } from '../entities/sandboxes/directories/selectors' ;
9+ import { singleSandboxSelector } from '../entities/sandboxes/selectors' ;
610
711export default {
8- executeAction : action => async ( dispatch : Function ) => {
12+ executeAction : action => async ( dispatch : Function , getState : Function ) => {
913 switch ( action . action ) {
1014 case 'notification' : {
1115 const { title, timeAlive, notificationType } = action ;
@@ -20,10 +24,21 @@ export default {
2024 return dispatch ( moduleActions . addCorrection ( action . moduleId , action ) ) ;
2125 }
2226 case 'source.module.rename' : {
23- const { sandboxId, moduleId, title } = action ;
24- return dispatch (
25- sandboxActions . renameModule ( sandboxId , moduleId , title )
26- ) ;
27+ const { sandboxId, path, title } = action ;
28+
29+ const sandbox = singleSandboxSelector ( getState ( ) , { id : sandboxId } ) ;
30+ const modules = modulesFromSandboxSelector ( getState ( ) , { sandbox } ) ;
31+ const directories = directoriesFromSandboxSelector ( getState ( ) , {
32+ sandbox,
33+ } ) ;
34+
35+ const module = resolveModule ( path , modules , directories ) ;
36+ if ( module ) {
37+ return dispatch (
38+ sandboxActions . renameModule ( sandboxId , module . id , title )
39+ ) ;
40+ }
41+ return null ;
2742 }
2843 case 'source.dependencies.add' : {
2944 const { sandboxId, dependency } = action ;
0 commit comments