Skip to content

Commit c783ede

Browse files
authored
add sandbox count for folder (codesandbox#4012)
1 parent 09e39d4 commit c783ede

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed

packages/app/src/app/graphql/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# source: https://codesandbox.io/api/graphql
2-
# timestamp: Tue Apr 28 2020 12:51:15 GMT+0200 (Central European Summer Time)
2+
# timestamp: Wed Apr 29 2020 14:46:25 GMT+0200 (Central European Summer Time)
33

44
schema {
55
query: RootQuery

packages/app/src/app/graphql/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,9 @@ export type AllCollectionsQuery = { __typename?: 'RootQueryType' } & {
13461346
me: Maybe<
13471347
{ __typename?: 'CurrentUser' } & {
13481348
collections: Array<
1349-
{ __typename?: 'Collection' } & SidebarCollectionDashboardFragment
1349+
{ __typename?: 'Collection' } & {
1350+
sandboxes: Array<{ __typename?: 'Sandbox' } & Pick<Sandbox, 'id'>>;
1351+
} & SidebarCollectionDashboardFragment
13501352
>;
13511353
}
13521354
>;

packages/app/src/app/overmind/effects/gql/dashboard/queries.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export const getCollections: Query<
7474
me {
7575
collections(teamId: $teamId) {
7676
...sidebarCollectionDashboard
77+
sandboxes {
78+
id
79+
}
7780
}
7881
}
7982
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ export const getAllFolders: AsyncAction = withLoadApp(
161161
const split = collection.path.split('/');
162162
return {
163163
...collection,
164+
sandboxes: collection.sandboxes.length,
164165
parent: split.slice(0, split.length - 1).find(a => a) || '',
165166
level: split.length - 2,
166167
name: split[split.length - 1],
@@ -170,12 +171,17 @@ export const getAllFolders: AsyncAction = withLoadApp(
170171
state.dashboard.allCollections = [
171172
{
172173
id: 'drafts-fake-id',
174+
sandboxes: (
175+
data.me.collections.find(folder => folder.path === '/') || {
176+
sandboxes: [],
177+
}
178+
).sandboxes.length,
173179
parent: '',
174180
name: 'Drafts',
175181
level: 0,
176182
path: '/drafts',
177183
},
178-
...collectionsByLevel.filter(c => c.id),
184+
...collectionsByLevel.filter(c => c.id && c.name),
179185
];
180186
} catch {
181187
effects.notificationToast.error(

packages/app/src/app/overmind/namespaces/dashboard/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export type DELETE_ME_COLLECTION = Collection & {
1919
name: string;
2020
level: number;
2121
parent: string;
22+
sandboxes: number;
2223
};
2324

2425
export enum sandboxesTypes {

packages/app/src/app/pages/NewDashboard/Components/Filters/ViewOptions/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const ViewOptions: FunctionComponent = () => {
3535
<Menu.List>
3636
{STATES.map(viewState => (
3737
<Menu.Item
38+
key={viewState.key}
3839
field={viewState.key}
3940
onSelect={() => viewModeChanged({ mode: viewState.key })}
4041
>

packages/app/src/app/pages/NewDashboard/Components/FolderCard/index.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import React, { useState } from 'react';
22
import { Link as LinkBase } from 'react-router-dom';
3-
import { Stack, Text, Input, Link } from '@codesandbox/components';
3+
import { Stack, Text, Input, Link, Element } from '@codesandbox/components';
44
import css from '@styled-system/css';
55
import { useOvermind } from 'app/overmind';
66
import { join, dirname } from 'path';
77
import { MenuOptions } from './Menu';
88

99
type Props = {
1010
name: string;
11+
sandboxes: number;
1112
path: string;
1213
};
1314

14-
export const FolderCard = ({ name, path, ...props }: Props) => {
15+
export const FolderCard = ({ name, path, sandboxes, ...props }: Props) => {
1516
const { actions } = useOvermind();
1617
const [edit, setEdit] = useState(false);
1718
const [newName, setNewName] = useState(name);
@@ -66,18 +67,23 @@ export const FolderCard = ({ name, path, ...props }: Props) => {
6667
</svg>
6768
</Stack>
6869
<Stack justify="space-between" align="center" marginLeft={4}>
69-
{edit ? (
70-
<form onSubmit={editFolderName}>
71-
<Input
72-
value={newName}
73-
onChange={e => setNewName(e.target.value)}
74-
/>
75-
</form>
76-
) : (
77-
<Text size={3} weight="medium" paddingTop={2}>
78-
{name}
70+
<Element>
71+
{edit ? (
72+
<form onSubmit={editFolderName}>
73+
<Input
74+
value={newName}
75+
onChange={e => setNewName(e.target.value)}
76+
/>
77+
</form>
78+
) : (
79+
<Text size={3} weight="medium" paddingTop={2}>
80+
{name}
81+
</Text>
82+
)}
83+
<Text marginTop={2} size={3} block variant="muted">
84+
{sandboxes} {sandboxes === 1 ? 'sandbox' : 'sandboxes'}
7985
</Text>
80-
)}
86+
</Element>
8187
<MenuOptions path={path} setEdit={setEdit} />
8288
</Stack>
8389
</Stack>

0 commit comments

Comments
 (0)