Skip to content

Commit 0815717

Browse files
christianalfoniCompuIves
authored andcommitted
fix issues with storage management and Entry bug (codesandbox#2828)
1 parent 43453f2 commit 0815717

File tree

5 files changed

+74
-72
lines changed

5 files changed

+74
-72
lines changed

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

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -242,60 +242,64 @@ export const gotUploadedFiles: AsyncAction<string> = async (
242242
export const addedFileToSandbox: AsyncAction<{
243243
url: string;
244244
name: string;
245-
}> = async ({ actions }, { name, url }) => {
245+
}> = withOwnedSandbox(async ({ actions }, { name, url }) => {
246246
actions.internal.closeModals(false);
247247
await actions.files.moduleCreated({
248248
title: name,
249249
directoryShortid: null,
250250
code: url,
251251
isBinary: true,
252252
});
253-
};
253+
});
254254

255255
export const deletedUploadedFile: AsyncAction<{
256256
id: string;
257-
}> = async ({ state, effects }, { id }) => {
257+
}> = withOwnedSandbox(async ({ state, effects }, { id }) => {
258+
const index = state.uploadedFiles.findIndex(file => file.id === id);
259+
const removedFiles = state.uploadedFiles.splice(index, 1);
260+
258261
try {
259262
await effects.api.deleteUploadedFile(id);
260-
state.uploadedFiles = null;
261-
// Why are we opening it again? And what is the message?
262-
// actions.files.gotUploadedFiles()
263263
} catch (error) {
264+
state.uploadedFiles.splice(index, 0, ...removedFiles);
264265
effects.notificationToast.error('Unable to delete uploaded file');
265266
}
266-
};
267+
});
267268

268269
export const filesUploaded: AsyncAction<{
269270
files: any[];
270271
directoryShortid: string;
271-
}> = async ({ state, effects, actions }, { files, directoryShortid }) => {
272-
const modal = 'uploading';
273-
effects.analytics.track('Open Modal', { modal });
274-
// What message?
275-
// state.currentModalMessage = message;
276-
state.currentModal = modal;
272+
}> = withOwnedSandbox(
273+
async ({ state, effects, actions }, { files, directoryShortid }) => {
274+
const modal = 'uploading';
275+
effects.analytics.track('Open Modal', { modal });
276+
// What message?
277+
// state.currentModalMessage = message;
278+
state.currentModal = modal;
277279

278-
try {
279-
const { modules, directories } = await actions.files.internal.uploadFiles({
280-
files,
281-
directoryShortid,
282-
});
283-
state.uploadedFiles = null;
280+
try {
281+
const { modules, directories } = await actions.files.internal.uploadFiles(
282+
{
283+
files,
284+
directoryShortid,
285+
}
286+
);
284287

285-
actions.files.massCreateModules({
286-
modules,
287-
directories,
288-
directoryShortid,
289-
});
290-
} catch (error) {
291-
if (error.message.indexOf('413') !== -1) {
292-
return;
288+
actions.files.massCreateModules({
289+
modules,
290+
directories,
291+
directoryShortid,
292+
});
293+
} catch (error) {
294+
if (error.message.indexOf('413') !== -1) {
295+
return;
296+
}
297+
effects.notificationToast.error(error.message);
293298
}
294-
effects.notificationToast.error(error.message);
295-
}
296299

297-
actions.internal.closeModals(false);
298-
};
300+
actions.internal.closeModals(false);
301+
}
302+
);
299303

300304
export const massCreateModules: AsyncAction<{
301305
modules: any;

packages/app/src/app/pages/Sandbox/Editor/Workspace/Files/DirectoryEntry/Entry/index.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1+
import theme from '@codesandbox/common/lib/theme';
2+
import { ContextMenu, Item } from 'app/components/ContextMenu';
13
import React, { useState } from 'react';
24
import { DragSource } from 'react-dnd';
3-
import { ContextMenu, Item } from 'app/components/ContextMenu';
4-
5-
import AddFileIcon from 'react-icons/lib/md/insert-drive-file';
6-
import AddDirectoryIcon from 'react-icons/lib/md/create-new-folder';
75
import EditIcon from 'react-icons/lib/go/pencil';
86
import DeleteIcon from 'react-icons/lib/go/trashcan';
7+
import AddDirectoryIcon from 'react-icons/lib/md/create-new-folder';
98
import UploadFileIcon from 'react-icons/lib/md/file-upload';
10-
11-
import theme from '@codesandbox/common/lib/theme';
9+
import AddFileIcon from 'react-icons/lib/md/insert-drive-file';
1210

1311
import { EntryContainer } from '../../../elements';
12+
import EditIcons from './EditIcons';
13+
import { NotSyncedIconWithMargin, Right } from './elements';
14+
import EntryIcons from './EntryIcons';
1415
import EntryTitle from './EntryTitle';
1516
import EntryTitleInput from './EntryTitleInput';
16-
import EntryIcons from './EntryIcons';
17-
import EditIcons from './EditIcons';
18-
19-
import { Right, NotSyncedIconWithMargin } from './elements';
2017

2118
interface IEntryProps {
2219
renameValidator: (id: string, title: string) => boolean;
@@ -97,9 +94,8 @@ const Entry: React.FC<IEntryProps> = ({
9794
const deleteAction = () =>
9895
deleteEntry ? deleteEntry(shortid, title) : false;
9996

100-
const discardModuleChangesAction = discardModuleChanges
101-
? discardModuleChanges(shortid)
102-
: false;
97+
const discardModuleChangesAction = () =>
98+
discardModuleChanges ? discardModuleChanges(shortid) : false;
10399

104100
const handleRename = (newTitle: string, force: boolean) => {
105101
if (newTitle === title) {

packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/elements.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import styled, { css } from 'styled-components';
21
import delayEffect from '@codesandbox/common/lib/utils/animation/delay-effect';
2+
import styled, { css } from 'styled-components';
33

44
export const HeaderTitle = styled.th`
55
font-weight: 400;
@@ -11,10 +11,7 @@ export const HeaderTitle = styled.th`
1111
export const Buttons = styled.div`
1212
margin: 0.5rem 0;
1313
display: flex;
14-
15-
> *:not(:last-child) {
16-
margin-right: 0.5rem;
17-
}
14+
justify-content: space-between;
1815
`;
1916

2017
export const Table = styled.table`

packages/app/src/app/pages/common/Modals/StorageManagementModal/FilesList/index.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
import React, { Component } from 'react';
2-
import { sortBy, isEmpty } from 'lodash-es';
3-
import filesize from 'filesize';
41
import { Button } from '@codesandbox/common/lib/components/Button';
5-
import DeleteFileButton from '../DeleteFileButton';
2+
import filesize from 'filesize';
3+
import { sortBy } from 'lodash-es';
4+
import React, { Component } from 'react';
5+
66
import AddFileToSandboxButton from '../AddFileToSandboxButton';
7+
import DeleteFileButton from '../DeleteFileButton';
78
import {
8-
HeaderTitle,
9-
Table,
10-
StatBody,
119
Body,
12-
FileRow,
13-
CheckBox,
1410
Buttons,
11+
CheckBox,
12+
FileRow,
13+
HeaderTitle,
14+
StatBody,
15+
Table,
1516
} from './elements';
1617

1718
const someSelected = obj =>
18-
Object.keys(obj).filter(key => obj[key] === true) && !isEmpty(obj);
19+
Object.keys(obj).filter(key => obj[key] === true).length;
1920

2021
class FilesList extends Component {
2122
state = {};
2223

2324
toggleCheckbox = (e, id) => {
2425
this.setState(state => ({
26+
...state,
2527
[id]: !state[id],
2628
}));
2729
};
@@ -44,19 +46,22 @@ class FilesList extends Component {
4446
} = this.props;
4547
return (
4648
<div css={{ margin: '0 2rem' }}>
47-
{someSelected(this.state) ? (
48-
<Buttons>
49-
<Button small onClick={() => deleteFiles(Object.keys(this.state))}>
50-
Delete all selected
51-
</Button>
52-
<Button
53-
small
54-
onClick={() => addFilesToSandbox(this.getSelection())}
55-
>
56-
Add all selected to project
57-
</Button>
58-
</Buttons>
59-
) : null}
49+
<Buttons>
50+
<Button
51+
disabled={!someSelected(this.state)}
52+
small
53+
onClick={() => addFilesToSandbox(this.getSelection())}
54+
>
55+
Add all selected to project
56+
</Button>
57+
<Button
58+
disabled={!someSelected(this.state)}
59+
small
60+
onClick={() => deleteFiles(Object.keys(this.state))}
61+
>
62+
Delete all selected
63+
</Button>
64+
</Buttons>
6065
<Table>
6166
<thead>
6267
<tr

packages/app/src/app/pages/common/Modals/StorageManagementModal/elements.js renamed to packages/app/src/app/pages/common/Modals/StorageManagementModal/elements.ts

File renamed without changes.

0 commit comments

Comments
 (0)