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

Commit ce8ddca

Browse files
committed
Add UI to clone workspace
1 parent 9ccbd0f commit ce8ddca

File tree

6 files changed

+62
-5
lines changed

6 files changed

+62
-5
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/main.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
GET_CONTRACT_DETAILS,
4646
OPEN_NEW_WORKSPACE_CONFIG,
4747
PROJECT_UPDATED,
48+
CLONE_WORKSPACE,
4849
} from "../common/redux/workspaces/actions";
4950

5051
import {
@@ -447,6 +448,20 @@ app.on("ready", () => {
447448
);
448449
});
449450

451+
ipcMain.on(CLONE_WORKSPACE, async (event, name, cloneName) => {
452+
const sourceWorkspace = workspaceManager.get(name);
453+
if (sourceWorkspace) {
454+
sourceWorkspace.clone(cloneName);
455+
456+
workspaceManager.bootstrap();
457+
458+
mainWindow.webContents.send(
459+
SET_WORKSPACES,
460+
workspaceManager.getNonDefaultNames(),
461+
);
462+
}
463+
});
464+
450465
ipcMain.on(DELETE_WORKSPACE, async (event, name) => {
451466
const tempWorkspace = workspaceManager.get(name);
452467
if (tempWorkspace) {

src/renderer/icons/clone-regular.svg

Lines changed: 1 addition & 0 deletions
Loading

src/renderer/icons/snapshot.svg

Lines changed: 1 addition & 1 deletion
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 "../../../../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)