Skip to content

Commit d4c664d

Browse files
committed
Show author instead of environment in the template list
1 parent a23bc2b commit d4c664d

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

packages/app/src/app/components/CreateNewSandbox/CreateSandbox/SandboxCard/SandboxCard.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
import React from 'react';
22
import { Icons } from '@codesandbox/template-icons';
33
import getColorIcons from '@codesandbox/common/lib/templates/icons';
4-
import getEnvironment, {
5-
TemplateType,
6-
} from '@codesandbox/common/lib/templates';
4+
import { TemplateType } from '@codesandbox/common/lib/templates';
75

86
import {
97
Container,
108
Icon,
119
Details,
1210
Row,
1311
Title,
14-
Environment,
15-
Author as Detail,
12+
Owner,
13+
Detail,
1614
} from './elements';
1715

1816
interface ISandboxCardProps {
1917
title: string;
2018
iconUrl: string;
2119
environment: TemplateType;
2220
color: string;
21+
owner?: string;
2322
official?: boolean;
2423
focused?: boolean;
2524
detailText?: string;
@@ -43,11 +42,11 @@ export const SandboxCard: React.FC<ISandboxCardProps> = ({
4342
onKeyPress,
4443
onMouseOver,
4544
DetailComponent,
45+
owner,
4646
}) => {
4747
const UserIcon: React.FunctionComponent =
4848
iconUrl && Icons[iconUrl] ? Icons[iconUrl] : getColorIcons(environment);
4949
const OfficialIcon: React.FunctionComponent = getColorIcons(environment);
50-
const parsedEnvironment = getEnvironment(environment);
5150

5251
const elRef = React.useRef<HTMLButtonElement>();
5352

@@ -79,7 +78,7 @@ export const SandboxCard: React.FC<ISandboxCardProps> = ({
7978
{focused && DetailComponent && <DetailComponent />}
8079
</Row>
8180
<Row>
82-
<Environment>{parsedEnvironment.name}</Environment>
81+
<Owner>{owner ? `by ${owner}` : ''}</Owner>
8382

8483
{detailText && <Detail>{detailText}</Detail>}
8584
</Row>

packages/app/src/app/components/CreateNewSandbox/CreateSandbox/SandboxCard/elements.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ export const Title = styled.span`
6767
text-overflow: ellipsis;
6868
`;
6969

70-
export const Environment = styled.span`
71-
color: #fff;
70+
export const Owner = styled.span`
71+
color: #e6e6e6;
7272
font-size: 11px;
7373
line-height: 13px;
7474
`;
7575

76-
export const Author = styled.span`
76+
export const Detail = styled.span`
7777
color: #757575;
7878
font-size: 11px;
7979
line-height: 13px;

packages/app/src/app/components/CreateNewSandbox/CreateSandbox/TemplateList/TemplateList.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import history from 'app/utils/history';
1212
import MdEditIcon from 'react-icons/lib/md/edit';
1313

1414
import Tooltip from '@codesandbox/common/lib/components/Tooltip';
15+
import track from '@codesandbox/common/lib/utils/analytics';
1516
import { SandboxCard } from '../SandboxCard';
1617
import { SubHeader, Grid } from '../elements';
1718
import { EditIcon, TemplateInfoContainer } from './elements';
@@ -285,6 +286,8 @@ export const TemplateList = ({
285286
const num = getNumber(e);
286287

287288
const template = getTemplateByIndex(num - 1);
289+
290+
track('Template Modal - Open Sandbox', { source: 'num-keys' });
288291
openSandbox(template.sandbox);
289292
}
290293
},
@@ -305,6 +308,8 @@ export const TemplateList = ({
305308
) {
306309
e.preventDefault();
307310
const currentTemplate = getTemplateByIndex(focusedTemplateIndex);
311+
312+
track('Template Modal - Open Sandbox', { source: 'enter' });
308313
openSandbox(currentTemplate.sandbox, isMac ? e.metaKey : e.ctrlKey);
309314
}
310315
},
@@ -332,6 +337,9 @@ export const TemplateList = ({
332337
{templates.map((template: TemplateFragment, i) => {
333338
const index = offset + i;
334339
const focused = focusedTemplateIndex === offset + i;
340+
const owner =
341+
template.sandbox.collection?.team?.name ||
342+
template.sandbox.author?.username;
335343

336344
const shortKey = showSecondaryShortcuts
337345
? index < 9
@@ -347,6 +355,7 @@ export const TemplateList = ({
347355
iconUrl={template.iconUrl}
348356
// @ts-ignore
349357
environment={template.sandbox.source.template}
358+
owner={owner}
350359
color={template.color}
351360
onFocus={() => {
352361
safeSetFocusedTemplate(() => index);
@@ -360,6 +369,10 @@ export const TemplateList = ({
360369
onKeyPress={e => {
361370
if (e.key === 'Enter') {
362371
e.preventDefault();
372+
373+
track('Template Modal - Open Sandbox', {
374+
source: 'enter',
375+
});
363376
openSandbox(
364377
template.sandbox,
365378
isMac ? e.metaKey : e.ctrlKey
@@ -369,6 +382,9 @@ export const TemplateList = ({
369382
onClick={e => {
370383
e.preventDefault();
371384

385+
track('Template Modal - Open Sandbox', {
386+
source: 'click',
387+
});
372388
openSandbox(
373389
template.sandbox,
374390
isMac ? e.metaKey : e.ctrlKey

packages/app/src/app/components/CreateNewSandbox/queries.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ const TEMPLATE_FRAGMENT = gql`
3131
insertedAt
3232
updatedAt
3333
34+
collection {
35+
team {
36+
name
37+
}
38+
}
39+
3440
author {
3541
username
3642
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# source: https://codesandbox.stream/api/graphql
2-
# timestamp: Thu Dec 12 2019 17:24:06 GMT+0100 (Central European Standard Time)
2+
# timestamp: Fri Jan 31 2020 13:46:04 GMT+0000 (Greenwich Mean Time)
33

44
schema {
55
query: RootQuery
@@ -20,6 +20,7 @@ type Collection {
2020
id: ID
2121
path: String
2222
sandboxes: [Sandbox]
23+
team: Team
2324
teamId: ID
2425
user: User
2526
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type Collection = {
2222
id: Maybe<Scalars['ID']>;
2323
path: Maybe<Scalars['String']>;
2424
sandboxes: Maybe<Array<Maybe<Sandbox>>>;
25+
team: Maybe<Team>;
2526
teamId: Maybe<Scalars['ID']>;
2627
user: Maybe<User>;
2728
};
@@ -329,6 +330,11 @@ export type TemplateFragment = { __typename?: 'Template' } & Pick<
329330
Sandbox,
330331
'id' | 'alias' | 'title' | 'description' | 'insertedAt' | 'updatedAt'
331332
> & {
333+
collection: Maybe<
334+
{ __typename?: 'Collection' } & {
335+
team: Maybe<{ __typename?: 'Team' } & Pick<Team, 'name'>>;
336+
}
337+
>;
332338
author: Maybe<{ __typename?: 'User' } & Pick<User, 'username'>>;
333339
source: Maybe<{ __typename?: 'Source' } & Pick<Source, 'template'>>;
334340
}

0 commit comments

Comments
 (0)