Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add ability to reorder Workspaces using drag and drop #497

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
85 changes: 68 additions & 17 deletions src/features/workspaces/components/WorkspaceDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import injectSheet from 'react-jss';
import { defineMessages, injectIntl } from 'react-intl';
import ReactTooltip from 'react-tooltip';

import { mdiPlusBox, mdiCog } from '@mdi/js';
import { mdiPlusBox, mdiCog, mdiMenuUp, mdiMenuDown } from '@mdi/js';

import { H1 } from '../../../components/ui/headline';
import Icon from '../../../components/ui/icon';
Expand Down Expand Up @@ -64,7 +64,7 @@ const styles = theme => ({
},
workspaces: {
height: 'auto',
overflowY: 'auto',
overflowY: 'visible',
},
addNewWorkspaceLabel: {
height: 'auto',
Expand Down Expand Up @@ -104,6 +104,27 @@ class WorkspaceDrawer extends Component {
}
}

handleClick(e, workspaces, index) {
switch (e) {
case 'goUp':
if (index !== 0) {
const toIndex = index - 1;
const element = workspaces.splice(index, 1)[0];
workspaces.splice(toIndex, 0, element);
}
break;
case 'goDown':
if (index !== workspaces.length - 1) {
const toIndex = index + 1;
const element = workspaces.splice(index, 1)[0];
workspaces.splice(toIndex, 0, element);
}
break;
default:
break;
}
}

render() {
const { classes, getServicesForWorkspace } = this.props;
const { intl } = this.props;
Expand Down Expand Up @@ -144,21 +165,51 @@ class WorkspaceDrawer extends Component {
shortcutIndex={0}
/>
{workspaces.map((workspace, index) => (
<WorkspaceDrawerItem
key={workspace.id}
name={workspace.name}
isActive={actualWorkspace === workspace}
onClick={() => {
if (actualWorkspace === workspace) return;
workspaceActions.activate({ workspace });
workspaceActions.toggleWorkspaceDrawer();
}}
onContextMenuEditClick={() =>
workspaceActions.edit({ workspace })
}
services={getServicesForWorkspace(workspace)}
shortcutIndex={index + 1}
/>
<div className="wrapper-workspaces-drawer-item">
<div className="wrapper-workspaces-drawer-item__workspaces">
<WorkspaceDrawerItem
key={workspace.id}
name={workspace.name}
isActive={actualWorkspace === workspace}
onClick={() => {
if (actualWorkspace === workspace) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would personally place the return within brackets on the next line as this is easier to read.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You and I both... But eslint didn't like it that way 🤣

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eslint config can be modified 🌚

workspaceActions.activate({ workspace });
workspaceActions.toggleWorkspaceDrawer();
}}
onContextMenuEditClick={() =>
workspaceActions.edit({ workspace })
}
services={getServicesForWorkspace(workspace)}
shortcutIndex={index + 1}
workspaces={workspaces}
className="wrapper-workspaces-drawer-item__workspace"
/>
</div>
<div className="wrapper-workspaces-drawer-item__buttons">
{index !== 0 && (
<button
type="button"
onClick={() => {
this.handleClick('goUp', workspaces, index);
}}
className="button-up"
>
<Icon icon={mdiMenuUp} size={1.5} />
</button>
)}
{index !== workspaces.length - 1 && (
<button
type="button"
onClick={() => {
this.handleClick('goDown', workspaces, index);
}}
className="button-down"
>
<Icon icon={mdiMenuDown} size={1.5} />
</button>
)}
</div>
</div>
))}
<div
className={classes.addNewWorkspaceLabel}
Expand Down
25 changes: 25 additions & 0 deletions src/styles/vertical.scss
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ $tabitem-bias: 30px;
}
}

.wrapper-workspaces-drawer-item {
height: fit-content;
display: flex;
align-items: center;
width: 107%;

&__workspaces {
display: flex;
flex-basis: 100%;

& > div {
width: 100%;
overflow: auto;
}
}
&__buttons {
display: flex;
flex-direction: column;
position: relative;
top: 0;
right: 9%;
bottom: 0;
}
}

.theme__dark {
.sidebar .sidebar__button--workspaces.is-active {
background-color: #2d2f31;
Expand Down