@@ -47,6 +47,22 @@ type CommandBarUiPluginProps = {
47
47
setEditPreviewMode : ( mode : string ) => void ;
48
48
siteNode : CRNode ;
49
49
toggleCommandBar : ( ) => void ;
50
+ changeBaseWorkspaceAction : ( workspace : string ) => void ;
51
+ neos : {
52
+ configuration : {
53
+ allowedTargetWorkspaces : {
54
+ allowedWorkspaces : Record <
55
+ string ,
56
+ {
57
+ name : string ;
58
+ title : string ;
59
+ readonly : boolean ;
60
+ description : string ;
61
+ }
62
+ > ;
63
+ } ;
64
+ } ;
65
+ } ;
50
66
} ;
51
67
52
68
type CommandBarUiPluginState = {
@@ -85,9 +101,10 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
85
101
setEditPreviewMode : PropTypes . func . isRequired ,
86
102
siteNode : PropTypes . object ,
87
103
toggleCommandBar : PropTypes . func . isRequired ,
104
+ neos : PropTypes . object . isRequired ,
88
105
} ;
89
106
90
- constructor ( props ) {
107
+ constructor ( props : CommandBarUiPluginProps ) {
91
108
super ( props ) ;
92
109
this . state = {
93
110
loaded : false ,
@@ -113,6 +130,15 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
113
130
action : this . handleSearchNode . bind ( this ) ,
114
131
canHandleQueries : true ,
115
132
} ,
133
+ switchWorkspace : {
134
+ name : this . translate ( 'CommandBarUiPlugin.command.switchWorkspace' , 'Switch workspace' ) ,
135
+ icon : 'exchange-alt' ,
136
+ description : this . translate (
137
+ 'CommandBarUiPlugin.command.switchWorkspace.description' ,
138
+ 'Switch to another workspace'
139
+ ) ,
140
+ subCommands : this . buildCommandsFromWorkspaces ( ) ,
141
+ } ,
116
142
publishDiscard : {
117
143
name : this . translate ( 'CommandBarUiPlugin.command.publishDiscard' , 'Publish / discard' ) ,
118
144
description : this . translate (
@@ -328,6 +354,26 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
328
354
} , { } as HierarchicalCommandList ) ;
329
355
} ;
330
356
357
+ buildCommandsFromWorkspaces = ( ) : HierarchicalCommandList => {
358
+ const { allowedTargetWorkspaces } = this . props . neos . configuration ;
359
+ return Object . keys ( allowedTargetWorkspaces ) . reduce ( ( carry , workspaceName ) => {
360
+ const workspace = allowedTargetWorkspaces [ workspaceName ] ;
361
+ if ( workspace . readonly ) {
362
+ return carry ;
363
+ }
364
+ carry [ workspaceName ] = {
365
+ name : workspace . title ,
366
+ description : workspace . description ,
367
+ icon : 'cube' ,
368
+ action : async ( ) => {
369
+ this . props . changeBaseWorkspaceAction ( workspace . name ) ;
370
+ } ,
371
+ closeOnExecute : true ,
372
+ } ;
373
+ return carry ;
374
+ } , { } as HierarchicalCommandList ) ;
375
+ } ;
376
+
331
377
buildCommandsFromEditPreviewModes = ( ) : HierarchicalCommandList => {
332
378
const { setEditPreviewMode, editPreviewModes, i18nRegistry } = this . props ;
333
379
@@ -641,4 +687,5 @@ export default connect(() => ({}), {
641
687
discardAction : actions . CR . Workspaces . commenceDiscard ,
642
688
setActiveContentCanvasSrc : actions . UI . ContentCanvas . setSrc ,
643
689
setActiveContentCanvasContextPath : actions . CR . Nodes . setDocumentNode ,
690
+ changeBaseWorkspaceAction : actions . CR . Workspaces . changeBaseWorkspace ,
644
691
} ) ( connect ( mapStateToProps , mapDispatchToProps ) ( mapGlobalRegistryToProps ( CommandBarUiPlugin ) ) ) ;
0 commit comments