Skip to content

Commit c6c45a2

Browse files
christianalfoniCompuIves
authored andcommitted
Fix drag and drop in dashboard (codesandbox#2433)
* Fix drag and drop in dashboard * Actually fix drag
1 parent 51f5507 commit c6c45a2

File tree

4 files changed

+79
-69
lines changed

4 files changed

+79
-69
lines changed

packages/app/src/app/pages/Dashboard/Sidebar/SandboxesItem/FolderEntry/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import RenameIcon from 'react-icons/lib/md/mode-edit';
66
import TrashIcon from 'react-icons/lib/md/delete';
77
import { Mutation } from 'react-apollo';
88
import { DropTarget, DragSource } from 'react-dnd';
9-
import { inject, observer } from 'app/componentConnectors';
109
import track from '@codesandbox/common/lib/utils/analytics';
1110
import { client } from 'app/graphql/client';
1211

@@ -390,10 +389,8 @@ const collectSource = (connect, monitor) => ({
390389
isDragging: monitor.isDragging(),
391390
});
392391

393-
DropFolderEntry = inject('store', 'signals')(
394-
DropTarget(['SANDBOX', 'FOLDER'], entryTarget, collectTarget)(
395-
DragSource('FOLDER', entrySource, collectSource)(observer(FolderEntry))
396-
)
392+
DropFolderEntry = DropTarget(['SANDBOX', 'FOLDER'], entryTarget, collectTarget)(
393+
DragSource('FOLDER', entrySource, collectSource)(FolderEntry)
397394
) as any;
398395

399396
export { DropFolderEntry };

packages/app/src/app/pages/Dashboard/Sidebar/SandboxesItem/folder-drop-target.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import {
88
} from '../../queries';
99

1010
function addSandboxesToCollection(props, item) {
11-
const { path, teamId, store } = props;
12-
13-
const selectedSandboxes = store.dashboard.selectedSandboxes;
11+
const { path, teamId, selectedSandboxes } = props;
1412

1513
client.mutate({
1614
mutation: ADD_SANDBOXES_TO_FOLDER_MUTATION,

packages/app/src/app/pages/Dashboard/Sidebar/SandboxesItem/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import React from 'react';
22
import { withRouter } from 'react-router-dom';
33
import { DropTarget } from 'react-dnd';
44
import AddFolderIcon from 'react-icons/lib/md/create-new-folder';
5-
import { inject, observer } from 'app/componentConnectors';
65
import { Query } from 'react-apollo';
76
import InfoIcon from '-!svg-react-loader!@codesandbox/common/lib/icons/sandbox.svg';
87
import { DelayedAnimation } from 'app/components/DelayedAnimation';
@@ -40,6 +39,7 @@ class SandboxesItemComponent extends React.Component {
4039
onSelect,
4140
currentPath,
4241
currentTeamId,
42+
selectedSandboxes,
4343
} = this.props;
4444

4545
const basePath = teamId
@@ -104,6 +104,7 @@ class SandboxesItemComponent extends React.Component {
104104
return (
105105
<DropFolderEntry
106106
key={path}
107+
selectedSandboxes={selectedSandboxes}
107108
basePath={basePath}
108109
teamId={teamId}
109110
path={path}
@@ -141,8 +142,8 @@ class SandboxesItemComponent extends React.Component {
141142
}
142143
}
143144

144-
export const SandboxesItem = inject('store', 'signals')(
145-
DropTarget(['SANDBOX', 'FOLDER'], entryTarget, collectTarget)(
146-
withRouter(observer(SandboxesItemComponent))
147-
)
148-
);
145+
export const SandboxesItem = DropTarget(
146+
['SANDBOX', 'FOLDER'],
147+
entryTarget,
148+
collectTarget
149+
)(withRouter(SandboxesItemComponent));

packages/app/src/app/pages/Dashboard/Sidebar/index.js

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import history from 'app/utils/history';
3-
import { inject, observer } from 'app/componentConnectors';
3+
import { inject, observer, Observer } from 'app/componentConnectors';
44
import { Route, withRouter } from 'react-router-dom';
55
import { Query } from 'react-apollo';
66
import Input from '@codesandbox/common/lib/components/Input';
@@ -59,60 +59,74 @@ class Sidebar extends React.Component {
5959
: undefined;
6060

6161
return (
62-
<React.Fragment>
63-
<Items style={{ marginBottom: '1rem' }}>
64-
<Item
65-
Icon={DashboardIcon}
66-
path="/dashboard/recent"
67-
name="Overview"
68-
/>
69-
70-
<SandboxesItem
71-
currentPath={path}
72-
currentTeamId={currentTeamId}
73-
openByDefault
74-
/>
75-
76-
<TemplateItem currentPath={path} />
77-
78-
<TrashItem currentPath={path} />
79-
</Items>
80-
81-
<Query query={TEAMS_QUERY}>
82-
{({ loading, data, error }) => {
83-
if (loading) {
84-
return null;
85-
}
86-
87-
if (error) {
88-
return null;
89-
}
90-
91-
const teams = data.me.teams;
92-
93-
return teams.map(team => (
94-
<div key={team.id}>
95-
<Items>
96-
<CategoryHeader>{team.name}</CategoryHeader>
97-
<Item
98-
Icon={PeopleIcon}
99-
path={teamOverviewUrl(team.id)}
100-
name="Team Overview"
101-
/>
102-
103-
<SandboxesItem
104-
currentPath={path}
105-
currentTeamId={currentTeamId}
106-
teamId={team.id}
107-
/>
108-
109-
<TemplateItem currentPath={path} teamId={team.id} />
110-
</Items>
111-
</div>
112-
));
113-
}}
114-
</Query>
115-
</React.Fragment>
62+
<Observer>
63+
{({ store: innerStore }) => (
64+
<React.Fragment>
65+
<Items style={{ marginBottom: '1rem' }}>
66+
<Item
67+
Icon={DashboardIcon}
68+
path="/dashboard/recent"
69+
name="Overview"
70+
/>
71+
72+
<SandboxesItem
73+
selectedSandboxes={
74+
innerStore.dashboard.selectedSandboxes
75+
}
76+
currentPath={path}
77+
currentTeamId={currentTeamId}
78+
openByDefault
79+
/>
80+
81+
<TemplateItem currentPath={path} />
82+
83+
<TrashItem currentPath={path} />
84+
</Items>
85+
86+
<Query query={TEAMS_QUERY}>
87+
{({ loading, data, error }) => {
88+
if (loading) {
89+
return null;
90+
}
91+
92+
if (error) {
93+
return null;
94+
}
95+
96+
const teams = data.me.teams;
97+
98+
return teams.map(team => (
99+
<div key={team.id}>
100+
<Items>
101+
<CategoryHeader>{team.name}</CategoryHeader>
102+
<Item
103+
Icon={PeopleIcon}
104+
path={teamOverviewUrl(team.id)}
105+
name="Team Overview"
106+
/>
107+
108+
<SandboxesItem
109+
whatTheFuck
110+
selectedSandboxes={
111+
store.dashboard.selectedSandboxes
112+
}
113+
currentPath={path}
114+
currentTeamId={currentTeamId}
115+
teamId={team.id}
116+
/>
117+
118+
<TemplateItem
119+
currentPath={path}
120+
teamId={team.id}
121+
/>
122+
</Items>
123+
</div>
124+
));
125+
}}
126+
</Query>
127+
</React.Fragment>
128+
)}
129+
</Observer>
116130
);
117131
}}
118132
</Route>

0 commit comments

Comments
 (0)