Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions packages/bruno-app/src/components/ManageWorkspace/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { showHomePage } from 'providers/ReduxStore/slices/app';
import { createWorkspaceWithUniqueName, switchWorkspace } from 'providers/ReduxStore/slices/workspaces/actions';
import { showInFolder } from 'providers/ReduxStore/slices/collections/actions';
import { sortWorkspaces } from 'utils/workspaces';
import { updateWorkspace } from 'providers/ReduxStore/slices/workspaces';

import CreateWorkspace from 'components/WorkspaceSidebar/CreateWorkspace';
import RenameWorkspace from './RenameWorkspace';
Expand Down Expand Up @@ -61,6 +62,28 @@ const ManageWorkspace = () => {
setDeleteWorkspaceModal({ open: true, workspace });
};

const handleSetAsDefault = async (workspace) => {
if (workspace.type === 'default' || !workspace.pathname) return;
const currentDefault = workspaces.find((w) => w.type === 'default');
try {
const result = await window.ipcRenderer.invoke('renderer:set-default-workspace-path', workspace.pathname);
if (!result?.success) {
throw new Error('Failed to set default workspace');
}
if (currentDefault && !result.previousDefaultUid) {
toast.error('Failed to resolve previous default workspace');
return;
}
if (currentDefault) {
dispatch(updateWorkspace({ uid: currentDefault.uid, newUid: result.previousDefaultUid, type: 'workspace' }));
}
dispatch(updateWorkspace({ uid: workspace.uid, newUid: 'default', type: 'default' }));
toast.success(`${workspace.name} set as default workspace`);
} catch (err) {
toast.error('Failed to set default workspace');
}
};

const handleCreateWorkspace = async () => {
const defaultLocation = get(preferences, 'general.defaultLocation', '');
if (!defaultLocation) {
Expand Down Expand Up @@ -158,8 +181,9 @@ const ManageWorkspace = () => {
placement="bottom-end"
items={[
{ id: 'rename', label: 'Rename', onClick: () => handleRenameClick(workspace) },
{ id: 'remove', label: 'Remove', onClick: () => handleCloseClick(workspace) }
]}
{ id: 'remove', label: 'Remove', onClick: () => handleCloseClick(workspace) },
workspace.pathname && { id: 'set_as_default', label: 'Set as default', onClick: () => handleSetAsDefault(workspace) }
].filter(Boolean)}
>
<button className="more-actions-btn">
<IconDots size={14} strokeWidth={1.5} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ export const workspacesSlice = createSlice({
},

updateWorkspace: (state, action) => {
const { uid, ...updates } = action.payload;
const { uid, newUid, ...updates } = action.payload;
const workspace = state.workspaces.find((w) => w.uid === uid);
if (workspace) {
Object.assign(workspace, updates);
if (newUid) {
if (state.activeWorkspaceUid === uid) {
state.activeWorkspaceUid = newUid;
}
workspace.uid = newUid;
}
}
},

Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-electron/src/app/apiSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const prepareWorkspaceConfigForClient = (workspaceConfig, isDefault) => {
if (isDefault) {
return {
...workspaceConfig,
name: DEFAULT_WORKSPACE_NAME,
name: workspaceConfig.name || DEFAULT_WORKSPACE_NAME,
type: 'default'
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bruno-electron/src/app/workspace-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const handleWorkspaceFileChange = (win, workspacePath) => {

win.webContents.send('main:workspace-config-updated', workspacePath, workspaceUid, {
...workspaceConfig,
name: isDefault ? DEFAULT_WORKSPACE_NAME : workspaceConfig.name,
name: isDefault ? (workspaceConfig.name || DEFAULT_WORKSPACE_NAME) : workspaceConfig.name,
type: isDefault ? 'default' : workspaceConfig.type
});
} catch (error) {
Expand Down
20 changes: 19 additions & 1 deletion packages/bruno-electron/src/ipc/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const prepareWorkspaceConfigForClient = (workspaceConfig, workspacePath, isDefau
if (isDefault) {
return {
...config,
name: DEFAULT_WORKSPACE_NAME,
name: config.name || DEFAULT_WORKSPACE_NAME,
type: 'default'
};
}
Expand Down Expand Up @@ -622,6 +622,22 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
}
});

ipcMain.handle('renderer:set-default-workspace-path', async (event, workspacePath) => {
try {
validateWorkspacePath(workspacePath);
const workspaceConfig = readWorkspaceConfig(workspacePath);
validateWorkspaceConfig(workspaceConfig);
const previousDefaultPath = defaultWorkspaceManager.getDefaultWorkspacePath();
await defaultWorkspaceManager.setDefaultWorkspacePath(workspacePath);
return {
success: true,
previousDefaultUid: previousDefaultPath ? getWorkspaceUid(previousDefaultPath) : null
};
} catch (error) {
throw error;
}
});

ipcMain.handle('renderer:get-default-workspace', async (event) => {
try {
const result = await defaultWorkspaceManager.ensureDefaultWorkspaceExists();
Expand Down Expand Up @@ -663,6 +679,8 @@ const registerWorkspaceIpc = (mainWindow, workspaceWatcher) => {
const workspaceConfig = readWorkspaceConfig(workspacePath);
const configForClient = prepareWorkspaceConfigForClient(workspaceConfig, workspacePath, true);

lastOpenedWorkspaces.add(workspacePath);

win.webContents.send('main:workspace-opened', workspacePath, workspaceUid, configForClient);

if (workspaceWatcher) {
Expand Down