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

Commit

Permalink
Add UI to clone workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
TripleSpeeder committed Sep 4, 2019
1 parent 9ccbd0f commit ce8ddca
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 5 deletions.
9 changes: 9 additions & 0 deletions src/common/redux/workspaces/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ export const deleteWorkspace = function(name) {
};
};

export const CLONE_WORKSPACE = `${prefix}/CLONE_WORKSPACE`;
export const cloneWorkspace = function(name, cloneName) {
return function(dispatch) {
dispatch({ type: CLONE_WORKSPACE, name, cloneName });

ipcRenderer.send(CLONE_WORKSPACE, name, cloneName);
};
};

export const SET_CURRENT_WORKSPACE = `${prefix}/SET_CURRENT_WORKSPACE`;
export const setCurrentWorkspace = function(workspace, contractCache) {
return { type: SET_CURRENT_WORKSPACE, workspace, contractCache };
Expand Down
15 changes: 15 additions & 0 deletions src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {
GET_CONTRACT_DETAILS,
OPEN_NEW_WORKSPACE_CONFIG,
PROJECT_UPDATED,
CLONE_WORKSPACE,
} from "../common/redux/workspaces/actions";

import {
Expand Down Expand Up @@ -447,6 +448,20 @@ app.on("ready", () => {
);
});

ipcMain.on(CLONE_WORKSPACE, async (event, name, cloneName) => {
const sourceWorkspace = workspaceManager.get(name);
if (sourceWorkspace) {
sourceWorkspace.clone(cloneName);

workspaceManager.bootstrap();

mainWindow.webContents.send(
SET_WORKSPACES,
workspaceManager.getNonDefaultNames(),
);
}
});

ipcMain.on(DELETE_WORKSPACE, async (event, name) => {
const tempWorkspace = workspaceManager.get(name);
if (tempWorkspace) {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/icons/clone-regular.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/renderer/icons/snapshot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion src/renderer/screens/startup/HomeScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
openDefaultWorkspace,
openNewWorkspaceConfig,
deleteWorkspace,
cloneWorkspace,
} from "../../../common/redux/workspaces/actions";
import UpdateNotification from "../auto-update/UpdateNotification";
import ErrorModal from "../../components/modal/ErrorModal";
Expand All @@ -22,6 +23,7 @@ import Logo from "../../../../Logo.svg";
import ChainIcon from "../../icons/chain.svg";
import MenuIcon from "../../icons/list.svg";
import TrashIcon from "../../icons/trash-icon.svg";
import CloneIcon from "../../icons/clone-regular.svg";

class HomeScreen extends Component {
constructor(props) {
Expand All @@ -33,8 +35,21 @@ class HomeScreen extends Component {
this.props.dispatch(openWorkspace(workspaceName));
}

handleCloneWorkspace(e) {
const workspaceName = e.currentTarget.parentElement.querySelector("span").innerText;
e.stopPropagation();
e.preventDefault();

document.activeElement.blur();

// Future improvement: Create modal dialog asking for new name
// For now, just go with hardcoded extension
const cloneName = workspaceName + "-clone";
this.props.dispatch(cloneWorkspace(workspaceName, cloneName));
}

handleDeleteWorkspace(e) {
const workspaceName = e.currentTarget.previousSibling.innerText;
const workspaceName = e.currentTarget.parentElement.querySelector("span").innerText;
e.stopPropagation();
e.preventDefault();

Expand Down Expand Up @@ -79,8 +94,16 @@ class HomeScreen extends Component {
<li key={workspaceName}>
<button onClick={this.selectWorkspace.bind(this)}>
<span>{workspaceName}</span>
<div
className="CloneWorkspace"
title="Clone workspace"
onClick={this.handleCloneWorkspace.bind(this)}
>
<CloneIcon/>
</div>
<div
className="DeleteWorkspace"
title="Remove workspace"
onClick={this.handleDeleteWorkspace.bind(this)}
>
<TrashIcon />
Expand Down
15 changes: 12 additions & 3 deletions src/renderer/screens/startup/HomeScreen.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@
&:last-child {
margin-bottom: 0;
}


.CloneWorkspace {
opacity: 0;
width: 1.3rem;
vertical-align: middle;
transition: all .3s;
position: absolute;
right: 3rem;
}

.DeleteWorkspace {
opacity: 0;
width: 1.3rem;
Expand All @@ -146,8 +155,8 @@
&:hover, &:focus, &:active {
color: #fbf1ec;
background: #5f474e;
.DeleteWorkspace {

.DeleteWorkspace, .CloneWorkspace {
opacity: 1;

&:hover, &:focus {
Expand Down

0 comments on commit ce8ddca

Please sign in to comment.