Skip to content

Commit 91267cf

Browse files
jyash97CompuIves
authored andcommitted
fix: renaming folder in sidebar doesnt update Route (codesandbox#2956)
* fix: renaming route in sidebar * fix: types * Fix typings * Add an ignore
1 parent d8ecbbf commit 91267cf

File tree

1 file changed

+19
-3
lines changed
  • packages/app/src/app/pages/Dashboard/Sidebar/SandboxesItem/FolderEntry

1 file changed

+19
-3
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import TrashIcon from 'react-icons/lib/md/delete';
77
import { Mutation } from 'react-apollo';
88
import { DropTarget, DragSource } from 'react-dnd';
99
import track from '@codesandbox/common/lib/utils/analytics';
10+
import { withRouter } from 'react-router-dom';
11+
import { History } from 'history';
1012
import { client } from 'app/graphql/client';
1113

1214
import { Animate as ReactShow } from 'react-show';
@@ -60,6 +62,8 @@ type Props = {
6062
isDragging?: boolean;
6163
connectDropTarget?: any;
6264
connectDragSource?: any;
65+
66+
history?: History;
6367
};
6468

6569
type State = {
@@ -138,6 +142,7 @@ class FolderEntry extends React.Component<Props, State> {
138142
onSelect,
139143
currentPath,
140144
currentTeamId,
145+
history,
141146
} = this.props;
142147

143148
const children = getDirectChildren(path, folders);
@@ -283,6 +288,14 @@ class FolderEntry extends React.Component<Props, State> {
283288
},
284289
variables,
285290
});
291+
const modifiedPath = path
292+
.split('/')
293+
.slice(0, -1)
294+
.join('/');
295+
296+
history.replace(
297+
`${basePath}${modifiedPath}/${input.value}`
298+
);
286299
},
287300
});
288301

@@ -392,8 +405,11 @@ const collectSource = (connect, monitor) => ({
392405
isDragging: monitor.isDragging(),
393406
});
394407

395-
DropFolderEntry = DropTarget(['SANDBOX', 'FOLDER'], entryTarget, collectTarget)(
396-
DragSource('FOLDER', entrySource, collectSource)(FolderEntry)
397-
) as any;
408+
DropFolderEntry = (withRouter(
409+
// @ts-ignore Don't know how to mix dnd and react-router with right typings
410+
DropTarget(['SANDBOX', 'FOLDER'], entryTarget, collectTarget)(
411+
DragSource('FOLDER', entrySource, collectSource)(FolderEntry)
412+
)
413+
) as unknown) as React.ComponentClass<Props, State>;
398414

399415
export { DropFolderEntry };

0 commit comments

Comments
 (0)