Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit bf615e1

Browse files
committed
Add UI to clone workspace
1 parent 5bc46a3 commit bf615e1

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

src/common/redux/workspaces/actions.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ export const deleteWorkspace = function(name) {
8282
};
8383
};
8484

85+
export const CLONE_WORKSPACE = `${prefix}/CLONE_WORKSPACE`;
86+
export const cloneWorkspace = function(name, cloneName) {
87+
return function(dispatch) {
88+
dispatch({ type: CLONE_WORKSPACE, name, cloneName });
89+
90+
ipcRenderer.send(CLONE_WORKSPACE, name, cloneName);
91+
};
92+
};
93+
8594
export const SET_CURRENT_WORKSPACE = `${prefix}/SET_CURRENT_WORKSPACE`;
8695
export const setCurrentWorkspace = function(workspace, contractCache) {
8796
return { type: SET_CURRENT_WORKSPACE, workspace, contractCache };

src/main/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
GET_CONTRACT_DETAILS,
4141
OPEN_NEW_WORKSPACE_CONFIG,
4242
PROJECT_UPDATED,
43+
CLONE_WORKSPACE,
4344
} from "../common/redux/workspaces/actions";
4445

4546
import {
@@ -481,6 +482,20 @@ app.on('ready', () => {
481482
);
482483
});
483484

485+
ipcMain.on(CLONE_WORKSPACE, async (event, name, cloneName) => {
486+
const sourceWorkspace = workspaceManager.get(name);
487+
if (sourceWorkspace) {
488+
sourceWorkspace.clone(cloneName);
489+
490+
workspaceManager.bootstrap();
491+
492+
mainWindow.webContents.send(
493+
SET_WORKSPACES,
494+
workspaceManager.getNonDefaultNames(),
495+
);
496+
}
497+
});
498+
484499
ipcMain.on(DELETE_WORKSPACE, async (event, name) => {
485500
const tempWorkspace = workspaceManager.get(name);
486501
if (tempWorkspace) {

src/renderer/icons/clone-regular.svg

Lines changed: 1 addition & 0 deletions
Loading

src/renderer/screens/startup/HomeScreen.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
openDefaultWorkspace,
1010
openNewWorkspaceConfig,
1111
deleteWorkspace,
12+
cloneWorkspace,
1213
} from "../../../common/redux/workspaces/actions";
1314
import UpdateNotification from "../auto-update/UpdateNotification";
1415
import ErrorModal from "../../components/modal/ErrorModal";
@@ -22,6 +23,7 @@ import Logo from "../../icons/logo.svg";
2223
import ChainIcon from "../../icons/chain.svg";
2324
import MenuIcon from "../../icons/list.svg";
2425
import TrashIcon from "../../icons/trash-icon.svg";
26+
import CloneIcon from "../../icons/clone-regular.svg";
2527

2628
class HomeScreen extends Component {
2729
constructor(props) {
@@ -33,8 +35,21 @@ class HomeScreen extends Component {
3335
this.props.dispatch(openWorkspace(workspaceName));
3436
}
3537

38+
handleCloneWorkspace(e) {
39+
const workspaceName = e.currentTarget.parentElement.querySelector("span").innerText;
40+
e.stopPropagation();
41+
e.preventDefault();
42+
43+
document.activeElement.blur();
44+
45+
// Future improvement: Create modal dialog asking for new name
46+
// For now, just go with hardcoded extension
47+
const cloneName = workspaceName + "-clone";
48+
this.props.dispatch(cloneWorkspace(workspaceName, cloneName));
49+
}
50+
3651
handleDeleteWorkspace(e) {
37-
const workspaceName = e.currentTarget.previousSibling.innerText;
52+
const workspaceName = e.currentTarget.parentElement.querySelector("span").innerText;
3853
e.stopPropagation();
3954
e.preventDefault();
4055

@@ -79,8 +94,16 @@ class HomeScreen extends Component {
7994
<li key={workspaceName}>
8095
<button onClick={this.selectWorkspace.bind(this)}>
8196
<span>{workspaceName}</span>
97+
<div
98+
className="CloneWorkspace"
99+
title="Clone workspace"
100+
onClick={this.handleCloneWorkspace.bind(this)}
101+
>
102+
<CloneIcon/>
103+
</div>
82104
<div
83105
className="DeleteWorkspace"
106+
title="Remove workspace"
84107
onClick={this.handleDeleteWorkspace.bind(this)}
85108
>
86109
<TrashIcon />

src/renderer/screens/startup/HomeScreen.scss

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,16 @@
133133
&:last-child {
134134
margin-bottom: 0;
135135
}
136-
136+
137+
.CloneWorkspace {
138+
opacity: 0;
139+
width: 1.3rem;
140+
vertical-align: middle;
141+
transition: all .3s;
142+
position: absolute;
143+
right: 3rem;
144+
}
145+
137146
.DeleteWorkspace {
138147
opacity: 0;
139148
width: 1.3rem;
@@ -146,8 +155,8 @@
146155
&:hover, &:focus, &:active {
147156
color: #fbf1ec;
148157
background: #5f474e;
149-
150-
.DeleteWorkspace {
158+
159+
.DeleteWorkspace, .CloneWorkspace {
151160
opacity: 1;
152161

153162
&:hover, &:focus {

0 commit comments

Comments
 (0)