Skip to content

Commit aafff1d

Browse files
refactor(dashboard): create slimmed-down fragment for sharedWithMeSandboxes query (#8836)
1 parent 51989be commit aafff1d

File tree

6 files changed

+92
-39
lines changed

6 files changed

+92
-39
lines changed

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

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,6 +5271,33 @@ export type RecentlyAccessedBranchesLegacyQuery = {
52715271
} | null;
52725272
};
52735273

5274+
export type CollaboratorSandboxFragment = {
5275+
__typename?: 'Sandbox';
5276+
id: string;
5277+
alias: string | null;
5278+
title: string | null;
5279+
description: string | null;
5280+
updatedAt: string;
5281+
viewCount: number;
5282+
isV2: boolean;
5283+
draft: boolean;
5284+
restricted: boolean;
5285+
privacy: number;
5286+
screenshotUrl: string | null;
5287+
source: { __typename?: 'Source'; template: string | null };
5288+
customTemplate: {
5289+
__typename?: 'Template';
5290+
id: any | null;
5291+
iconUrl: string | null;
5292+
} | null;
5293+
author: { __typename?: 'User'; username: string } | null;
5294+
collection: {
5295+
__typename?: 'Collection';
5296+
path: string;
5297+
id: any | null;
5298+
} | null;
5299+
};
5300+
52745301
export type SharedWithMeSandboxesQueryVariables = Exact<{
52755302
[key: string]: never;
52765303
}>;
@@ -5286,43 +5313,25 @@ export type SharedWithMeSandboxesQuery = {
52865313
alias: string | null;
52875314
title: string | null;
52885315
description: string | null;
5289-
lastAccessedAt: any;
5290-
insertedAt: string;
52915316
updatedAt: string;
5292-
removedAt: string | null;
5293-
privacy: number;
5294-
isFrozen: boolean;
5295-
screenshotUrl: string | null;
52965317
viewCount: number;
5297-
likeCount: number;
52985318
isV2: boolean;
52995319
draft: boolean;
53005320
restricted: boolean;
5301-
authorId: any | null;
5302-
teamId: any | null;
5321+
privacy: number;
5322+
screenshotUrl: string | null;
53035323
source: { __typename?: 'Source'; template: string | null };
53045324
customTemplate: {
53055325
__typename?: 'Template';
53065326
id: any | null;
53075327
iconUrl: string | null;
53085328
} | null;
5309-
forkedTemplate: {
5310-
__typename?: 'Template';
5311-
id: any | null;
5312-
color: string | null;
5313-
iconUrl: string | null;
5314-
} | null;
5329+
author: { __typename?: 'User'; username: string } | null;
53155330
collection: {
53165331
__typename?: 'Collection';
53175332
path: string;
53185333
id: any | null;
53195334
} | null;
5320-
author: { __typename?: 'User'; username: string } | null;
5321-
permissions: {
5322-
__typename?: 'SandboxProtectionSettings';
5323-
preventSandboxLeaving: boolean;
5324-
preventSandboxExport: boolean;
5325-
} | null;
53265335
}>;
53275336
} | null;
53285337
};

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,40 @@ export const recentlyAccessedBranches: Query<
397397
${branchFragment}
398398
`;
399399

400+
const COLLABORATOR_SANDBOX_FRAGMENT = gql`
401+
fragment collaboratorSandbox on Sandbox {
402+
id
403+
alias
404+
title
405+
description
406+
updatedAt
407+
viewCount
408+
isV2
409+
draft
410+
restricted
411+
privacy
412+
screenshotUrl
413+
414+
source {
415+
template
416+
}
417+
418+
customTemplate {
419+
id
420+
iconUrl
421+
}
422+
423+
author {
424+
username
425+
}
426+
427+
collection {
428+
path
429+
id
430+
}
431+
}
432+
`;
433+
400434
export const sharedWithmeSandboxes: Query<
401435
SharedWithMeSandboxesQuery,
402436
SharedWithMeSandboxesQueryVariables
@@ -406,11 +440,11 @@ export const sharedWithmeSandboxes: Query<
406440
id
407441
408442
collaboratorSandboxes {
409-
...sandboxFragmentDashboard
443+
...collaboratorSandbox
410444
}
411445
}
412446
}
413-
${sandboxFragmentDashboard}
447+
${COLLABORATOR_SANDBOX_FRAGMENT}
414448
`;
415449

416450
export const getTeam: Query<GetTeamQuery, GetTeamQueryVariables> = gql`

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ import {
2828
sortByLastAccessed,
2929
} from './utils';
3030

31-
import { OrderBy, PageTypes, sandboxesTypes } from './types';
31+
import { OrderBy, PageTypes, sandboxesTypes, DashboardSandboxFragment } from './types';
3232
import * as internalActions from './internalActions';
3333

3434
// Type guards to check if sandbox has specific properties
3535
function hasIsFrozen(
36-
sandbox: SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment | SearchTeamSandboxFragment
36+
sandbox: DashboardSandboxFragment
3737
): sandbox is SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment {
3838
return 'isFrozen' in sandbox;
3939
}
4040

4141
function hasPermissions(
42-
sandbox: SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment | SearchTeamSandboxFragment
42+
sandbox: DashboardSandboxFragment
4343
): sandbox is SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment {
4444
return 'permissions' in sandbox;
4545
}

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { Context } from 'app/overmind';
2-
import {
3-
SandboxFragmentDashboardFragment,
4-
SandboxByPathFragment,
5-
DraftSandboxFragment,
6-
SearchTeamSandboxFragment,
7-
} from 'app/graphql/types';
2+
import { DashboardSandboxFragment } from './types';
83

94
/**
105
* Change sandbox frozen in state and returns the sandboxes that have changed in their old state
@@ -20,14 +15,14 @@ export const changeSandboxesInState = (
2015
* The mutation that happens on the sandbox, make sure to return a *new* sandbox here, to make sure
2116
* that we can still rollback easily in the future.
2217
*/
23-
sandboxMutation: <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment | SearchTeamSandboxFragment>(
18+
sandboxMutation: <T extends DashboardSandboxFragment>(
2419
sandbox: T
2520
) => T;
2621
}
2722
) => {
2823
const changedSandboxes: Set<ReturnType<typeof sandboxMutation>> = new Set();
2924

30-
const doMutateSandbox = <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment | SearchTeamSandboxFragment>(
25+
const doMutateSandbox = <T extends DashboardSandboxFragment>(
3126
sandbox: T
3227
): T => {
3328
changedSandboxes.add(sandbox);
@@ -111,7 +106,7 @@ export const deleteSandboxesFromState = (
111106
ids: string[];
112107
}
113108
) => {
114-
const sandboxFilter = <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment | SearchTeamSandboxFragment>(
109+
const sandboxFilter = <T extends DashboardSandboxFragment>(
115110
sandbox: T
116111
): boolean => !ids.includes(sandbox.id);
117112

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
ProjectWithBranchesFragment as RepositoryWithBranches,
1111
RecentlyDeletedTeamSandboxesFragment,
1212
SearchTeamSandboxFragment,
13+
CollaboratorSandboxFragment,
1314
} from 'app/graphql/types';
1415
import isSameWeek from 'date-fns/isSameWeek';
1516
import { sortBy } from 'lodash-es';
@@ -26,7 +27,7 @@ export type DashboardSandboxStructure = {
2627
RECENT_BRANCHES: Branch[] | null;
2728
SEARCH: (Sandbox | DraftSandboxFragment | SearchTeamSandboxFragment)[] | null;
2829
TEMPLATE_HOME: Template[] | null;
29-
SHARED: (Sandbox | DraftSandboxFragment)[] | null;
30+
SHARED: (Sandbox | DraftSandboxFragment | CollaboratorSandboxFragment)[] | null;
3031
ALL: {
3132
[path: string]: (Sandbox | SandboxByPathFragment | DraftSandboxFragment)[];
3233
} | null;
@@ -51,7 +52,7 @@ export type State = {
5152
viewMode: 'grid' | 'list';
5253
orderBy: OrderBy;
5354
getFilteredSandboxes: (
54-
sandboxes: Array<Sandbox | SandboxByPathFragment | RecentlyDeletedTeamSandboxesFragment | Repo | Template['sandbox'] | SearchTeamSandboxFragment>
55+
sandboxes: Array<Sandbox | SandboxByPathFragment | RecentlyDeletedTeamSandboxesFragment | Repo | Template['sandbox'] | SearchTeamSandboxFragment | CollaboratorSandboxFragment>
5556
) => Sandbox[];
5657
deletedSandboxesByTime: {
5758
week: RecentlyDeletedTeamSandboxesFragment[];
@@ -140,7 +141,7 @@ export const state: State = {
140141
},
141142
getFilteredSandboxes: derived(
142143
({ orderBy }: State) => (
143-
sandboxes: Array<Sandbox | SandboxByPathFragment | DraftSandboxFragment | RecentlyDeletedTeamSandboxesFragment | Template['sandbox'] | SearchTeamSandboxFragment>
144+
sandboxes: Array<Sandbox | SandboxByPathFragment | DraftSandboxFragment | RecentlyDeletedTeamSandboxesFragment | Template['sandbox'] | SearchTeamSandboxFragment | CollaboratorSandboxFragment>
144145
) => {
145146
const orderField = orderBy.field;
146147
const orderOrder = orderBy.order;

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
import { SidebarCollectionDashboardFragment as Collection } from 'app/graphql/types';
1+
import {
2+
SidebarCollectionDashboardFragment as Collection,
3+
SandboxFragmentDashboardFragment,
4+
SandboxByPathFragment,
5+
DraftSandboxFragment,
6+
SearchTeamSandboxFragment,
7+
CollaboratorSandboxFragment,
8+
} from 'app/graphql/types';
9+
10+
export type DashboardSandboxFragment =
11+
| SandboxFragmentDashboardFragment
12+
| SandboxByPathFragment
13+
| DraftSandboxFragment
14+
| SearchTeamSandboxFragment
15+
| CollaboratorSandboxFragment;
216

317
export type PageTypes =
418
| 'search'

0 commit comments

Comments
 (0)