Skip to content

Commit

Permalink
FEATURE: Introduce switch workspace commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Jun 25, 2024
1 parent 604abd7 commit 51d7c71
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion packages/ui-plugin/src/CommandBarUiPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ type CommandBarUiPluginProps = {
setEditPreviewMode: (mode: string) => void;
siteNode: CRNode;
toggleCommandBar: () => void;
changeBaseWorkspaceAction: (workspace: string) => void;
neos: {
configuration: {
allowedTargetWorkspaces: {
allowedWorkspaces: Record<
string,
{
name: string;
title: string;
readonly: boolean;
description: string;
}
>;
};
};
};
};

type CommandBarUiPluginState = {
Expand Down Expand Up @@ -85,9 +101,10 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
setEditPreviewMode: PropTypes.func.isRequired,
siteNode: PropTypes.object,
toggleCommandBar: PropTypes.func.isRequired,
neos: PropTypes.object.isRequired,
};

constructor(props) {
constructor(props: CommandBarUiPluginProps) {
super(props);
this.state = {
loaded: false,
Expand All @@ -113,6 +130,15 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
action: this.handleSearchNode.bind(this),
canHandleQueries: true,
},
switchWorkspace: {
name: this.translate('CommandBarUiPlugin.command.switchWorkspace', 'Switch workspace'),
icon: 'exchange-alt',
description: this.translate(
'CommandBarUiPlugin.command.switchWorkspace.description',
'Switch to another workspace'
),
subCommands: this.buildCommandsFromWorkspaces(),
},
publishDiscard: {
name: this.translate('CommandBarUiPlugin.command.publishDiscard', 'Publish / discard'),
description: this.translate(
Expand Down Expand Up @@ -328,6 +354,26 @@ class CommandBarUiPlugin extends React.PureComponent<CommandBarUiPluginProps, Co
}, {} as HierarchicalCommandList);
};

buildCommandsFromWorkspaces = (): HierarchicalCommandList => {
const { allowedTargetWorkspaces } = this.props.neos.configuration;
return Object.keys(allowedTargetWorkspaces).reduce((carry, workspaceName) => {
const workspace = allowedTargetWorkspaces[workspaceName];
if (workspace.readonly) {
return carry;
}
carry[workspaceName] = {
name: workspace.title,
description: workspace.description,
icon: 'cube',
action: async () => {
this.props.changeBaseWorkspaceAction(workspace.name);
},
closeOnExecute: true,
};
return carry;
}, {} as HierarchicalCommandList);
};

buildCommandsFromEditPreviewModes = (): HierarchicalCommandList => {
const { setEditPreviewMode, editPreviewModes, i18nRegistry } = this.props;

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

0 comments on commit 51d7c71

Please sign in to comment.