Skip to content

Commit 46f9d7c

Browse files
authored
add fork to context menu (codesandbox#2586)
* add fork to context menu * simplify code
1 parent aed84f4 commit 46f9d7c

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ export const createZipClicked: Action = ({ state, effects }) => {
219219
effects.zip.download(state.editor.currentSandbox);
220220
};
221221

222+
export const forkExternalSandbox: AsyncAction<string> = async (
223+
{ actions },
224+
sandboxId
225+
) => {
226+
await actions.editor.internal.forkSandbox({
227+
sandboxId,
228+
});
229+
};
230+
222231
export const forkSandboxClicked: AsyncAction = async ({
223232
state,
224233
effects,

packages/app/src/app/pages/Dashboard/Content/SandboxCard/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import theme from '@codesandbox/common/lib/theme';
1717
import track from '@codesandbox/common/lib/utils/analytics';
1818

1919
import { ESC, ENTER } from '@codesandbox/common/lib/utils/keycodes';
20+
import { Sandbox } from '@codesandbox/common/lib/types';
2021
import { RENAME_SANDBOX_MUTATION } from '../../queries';
2122

2223
import {
@@ -48,7 +49,7 @@ type Props = {
4849
selectedCount: number;
4950
collectionPath: string; // eslint-disable-line react/no-unused-prop-types
5051
collectionTeamId: string | undefined;
51-
sandbox: Object;
52+
sandbox: Sandbox;
5253
page: string | undefined;
5354
privacy: number;
5455
isPatron: boolean;
@@ -63,6 +64,7 @@ type Props = {
6364
permanentlyDeleteSandboxes: () => void;
6465
undeleteSandboxes: () => void;
6566
makeTemplates: (teamId?: string) => void;
67+
forkSandbox: (id: string) => void;
6668

6769
// React-DnD, lazy typings
6870
connectDragSource: any;
@@ -280,6 +282,13 @@ class SandboxItemComponent extends React.PureComponent<Props, State> {
280282
return true;
281283
},
282284
},
285+
{
286+
title: 'Fork Sandbox',
287+
action: () => {
288+
this.props.forkSandbox(this.props.sandbox.id);
289+
return true;
290+
},
291+
},
283292
{
284293
title: 'Export Sandbox',
285294
action: () => {

packages/app/src/app/pages/Dashboard/Content/SandboxGrid/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import { uniq } from 'lodash-es';
66
import { basename } from 'path';
77
import { camelizeKeys } from 'humps';
88

9-
import track from '@codesandbox/common/lib/utils/analytics';
109
import { protocolAndHost } from '@codesandbox/common/lib/utils/url-generator';
10+
import track from '@codesandbox/common/lib/utils/analytics';
11+
1112
import Grid from 'react-virtualized/dist/commonjs/Grid';
1213
import Column from 'react-virtualized/dist/commonjs/Table/Column';
1314
import Table from 'react-virtualized/dist/commonjs/Table';
@@ -170,6 +171,10 @@ class SandboxGridComponent extends React.Component<*, State> {
170171
);
171172
};
172173

174+
forkSandbox = id => {
175+
this.props.signals.editor.forkExternalSandbox(id);
176+
};
177+
173178
onMouseDown = (event: MouseEvent) => {
174179
this.setState({
175180
selection: {
@@ -317,6 +322,7 @@ class SandboxGridComponent extends React.Component<*, State> {
317322
}
318323
collectionPath={item.collection.path}
319324
collectionTeamId={item.collection.teamId}
325+
forkSandbox={this.forkSandbox}
320326
deleteSandboxes={this.deleteSandboxes}
321327
undeleteSandboxes={this.undeleteSandboxes}
322328
permanentlyDeleteSandboxes={this.permanentlyDeleteSandboxes}

0 commit comments

Comments
 (0)