Skip to content

Commit 51d7c71

Browse files
committed
FEATURE: Introduce switch workspace commands
1 parent 604abd7 commit 51d7c71

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

packages/ui-plugin/src/CommandBarUiPlugin.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ type CommandBarUiPluginProps = {
4747
setEditPreviewMode: (mode: string) => void;
4848
siteNode: CRNode;
4949
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+
};
5066
};
5167

5268
type CommandBarUiPluginState = {
@@ -85,9 +101,10 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
85101
setEditPreviewMode: PropTypes.func.isRequired,
86102
siteNode: PropTypes.object,
87103
toggleCommandBar: PropTypes.func.isRequired,
104+
neos: PropTypes.object.isRequired,
88105
};
89106

90-
constructor(props) {
107+
constructor(props: CommandBarUiPluginProps) {
91108
super(props);
92109
this.state = {
93110
loaded: false,
@@ -113,6 +130,15 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
113130
action: this.handleSearchNode.bind(this),
114131
canHandleQueries: true,
115132
},
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+
},
116142
publishDiscard: {
117143
name: this.translate('CommandBarUiPlugin.command.publishDiscard', 'Publish / discard'),
118144
description: this.translate(
@@ -328,6 +354,26 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
328354
}, {} as HierarchicalCommandList);
329355
};
330356

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+
331377
buildCommandsFromEditPreviewModes = (): HierarchicalCommandList => {
332378
const { setEditPreviewMode, editPreviewModes, i18nRegistry } = this.props;
333379

@@ -641,4 +687,5 @@ export default connect(() => ({}), {
641687
discardAction: actions.CR.Workspaces.commenceDiscard,
642688
setActiveContentCanvasSrc: actions.UI.ContentCanvas.setSrc,
643689
setActiveContentCanvasContextPath: actions.CR.Nodes.setDocumentNode,
690+
changeBaseWorkspaceAction: actions.CR.Workspaces.changeBaseWorkspace,
644691
})(connect(mapStateToProps, mapDispatchToProps)(mapGlobalRegistryToProps(CommandBarUiPlugin)));

0 commit comments

Comments
 (0)