Skip to content

Commit 642d51c

Browse files
refactor: create custom draftSandbox fragment to reduce query payload (#8831)
1 parent 1934e34 commit 642d51c

File tree

7 files changed

+113
-26
lines changed

7 files changed

+113
-26
lines changed

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

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4702,7 +4702,6 @@ export type SandboxByPathFragment = {
47024702
forkedTemplate: {
47034703
__typename?: 'Template';
47044704
id: any | null;
4705-
color: string | null;
47064705
iconUrl: string | null;
47074706
} | null;
47084707
collection: {
@@ -4762,7 +4761,6 @@ export type SandboxesByPathQuery = {
47624761
forkedTemplate: {
47634762
__typename?: 'Template';
47644763
id: any | null;
4765-
color: string | null;
47664764
iconUrl: string | null;
47674765
} | null;
47684766
collection: {
@@ -4781,6 +4779,47 @@ export type SandboxesByPathQuery = {
47814779
} | null;
47824780
};
47834781

4782+
export type DraftSandboxFragment = {
4783+
__typename?: 'Sandbox';
4784+
id: string;
4785+
alias: string | null;
4786+
title: string | null;
4787+
insertedAt: string;
4788+
updatedAt: string;
4789+
screenshotUrl: string | null;
4790+
isV2: boolean;
4791+
isFrozen: boolean;
4792+
privacy: number;
4793+
restricted: boolean;
4794+
draft: boolean;
4795+
viewCount: number;
4796+
authorId: any | null;
4797+
lastAccessedAt: any;
4798+
teamId: any | null;
4799+
source: { __typename?: 'Source'; template: string | null };
4800+
customTemplate: {
4801+
__typename?: 'Template';
4802+
id: any | null;
4803+
iconUrl: string | null;
4804+
} | null;
4805+
forkedTemplate: {
4806+
__typename?: 'Template';
4807+
id: any | null;
4808+
iconUrl: string | null;
4809+
} | null;
4810+
collection: {
4811+
__typename?: 'Collection';
4812+
path: string;
4813+
id: any | null;
4814+
} | null;
4815+
author: { __typename?: 'User'; username: string } | null;
4816+
permissions: {
4817+
__typename?: 'SandboxProtectionSettings';
4818+
preventSandboxLeaving: boolean;
4819+
preventSandboxExport: boolean;
4820+
} | null;
4821+
};
4822+
47844823
export type TeamDraftsQueryVariables = Exact<{
47854824
teamId: Scalars['UUID4'];
47864825
authorId: InputMaybe<Scalars['UUID4']>;
@@ -4798,20 +4837,17 @@ export type TeamDraftsQuery = {
47984837
id: string;
47994838
alias: string | null;
48004839
title: string | null;
4801-
description: string | null;
4802-
lastAccessedAt: any;
48034840
insertedAt: string;
48044841
updatedAt: string;
4805-
removedAt: string | null;
4806-
privacy: number;
4807-
isFrozen: boolean;
48084842
screenshotUrl: string | null;
4809-
viewCount: number;
4810-
likeCount: number;
48114843
isV2: boolean;
4812-
draft: boolean;
4844+
isFrozen: boolean;
4845+
privacy: number;
48134846
restricted: boolean;
4847+
draft: boolean;
4848+
viewCount: number;
48144849
authorId: any | null;
4850+
lastAccessedAt: any;
48154851
teamId: any | null;
48164852
source: { __typename?: 'Source'; template: string | null };
48174853
customTemplate: {
@@ -4822,7 +4858,6 @@ export type TeamDraftsQuery = {
48224858
forkedTemplate: {
48234859
__typename?: 'Template';
48244860
id: any | null;
4825-
color: string | null;
48264861
iconUrl: string | null;
48274862
} | null;
48284863
collection: {

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

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ const SANDBOX_BY_PATH_FRAGMENT = gql`
124124
125125
forkedTemplate {
126126
id
127-
color
128127
iconUrl
129128
}
130129
@@ -169,6 +168,54 @@ export const sandboxesByPath: Query<
169168
${sidebarCollectionDashboard}
170169
`;
171170

171+
const DRAFT_SANDBOX_FRAGMENT = gql`
172+
fragment draftSandbox on Sandbox {
173+
id
174+
alias
175+
title
176+
insertedAt
177+
updatedAt
178+
screenshotUrl
179+
isV2
180+
isFrozen
181+
privacy
182+
restricted
183+
draft
184+
viewCount
185+
authorId
186+
lastAccessedAt
187+
188+
source {
189+
template
190+
}
191+
192+
customTemplate {
193+
id
194+
iconUrl
195+
}
196+
197+
forkedTemplate {
198+
id
199+
iconUrl
200+
}
201+
202+
collection {
203+
path
204+
id
205+
}
206+
207+
author {
208+
username
209+
}
210+
teamId
211+
212+
permissions {
213+
preventSandboxLeaving
214+
preventSandboxExport
215+
}
216+
}
217+
`;
218+
172219
export const getTeamDrafts: Query<
173220
TeamDraftsQuery,
174221
TeamDraftsQueryVariables
@@ -179,12 +226,12 @@ export const getTeamDrafts: Query<
179226
180227
team(id: $teamId) {
181228
drafts(authorId: $authorId) {
182-
...sandboxFragmentDashboard
229+
...draftSandbox
183230
}
184231
}
185232
}
186233
}
187-
${sandboxFragmentDashboard}
234+
${DRAFT_SANDBOX_FRAGMENT}
188235
`;
189236

190237
export const getCollections: Query<

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { uniq } from 'lodash-es';
66
import {
77
TemplateFragmentDashboardFragment,
88
SandboxFragmentDashboardFragment,
9+
DraftSandboxFragment,
910
RepoFragmentDashboardFragment,
1011
ProjectFragment,
1112
} from 'app/graphql/types';
@@ -192,7 +193,7 @@ export const createFolder = async (
192193
export const getDrafts = async ({ state, effects }: Context) => {
193194
const { dashboard, activeTeam } = state;
194195
try {
195-
let sandboxes: SandboxFragmentDashboardFragment[] = [];
196+
let sandboxes: (SandboxFragmentDashboardFragment | DraftSandboxFragment)[] = [];
196197

197198
if (activeTeam) {
198199
const data = await effects.gql.queries.getTeamDrafts({

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Context } from 'app/overmind';
22
import {
33
SandboxFragmentDashboardFragment,
44
SandboxByPathFragment,
5+
DraftSandboxFragment,
56
} from 'app/graphql/types';
67

78
/**
@@ -18,14 +19,14 @@ export const changeSandboxesInState = (
1819
* The mutation that happens on the sandbox, make sure to return a *new* sandbox here, to make sure
1920
* that we can still rollback easily in the future.
2021
*/
21-
sandboxMutation: <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment>(
22+
sandboxMutation: <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment>(
2223
sandbox: T
2324
) => T;
2425
}
2526
) => {
2627
const changedSandboxes: Set<ReturnType<typeof sandboxMutation>> = new Set();
2728

28-
const doMutateSandbox = <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment>(
29+
const doMutateSandbox = <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment>(
2930
sandbox: T
3031
): T => {
3132
changedSandboxes.add(sandbox);
@@ -109,7 +110,7 @@ export const deleteSandboxesFromState = (
109110
ids: string[];
110111
}
111112
) => {
112-
const sandboxFilter = <T extends SandboxFragmentDashboardFragment>(
113+
const sandboxFilter = <T extends SandboxFragmentDashboardFragment | SandboxByPathFragment | DraftSandboxFragment>(
113114
sandbox: T
114115
): boolean => !ids.includes(sandbox.id);
115116

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
SandboxFragmentDashboardFragment as Sandbox,
33
SandboxByPathFragment,
4+
DraftSandboxFragment,
45
RepoFragmentDashboardFragment as Repo,
56
TemplateFragmentDashboardFragment as Template,
67
TeamFragmentDashboardFragment,
@@ -17,16 +18,16 @@ import { derived } from 'overmind';
1718
import { DELETE_ME_COLLECTION, OrderBy } from './types';
1819

1920
export type DashboardSandboxStructure = {
20-
DRAFTS: Sandbox[] | null;
21+
DRAFTS: DraftSandboxFragment[] | null;
2122
TEMPLATES: Template[] | null;
2223
DELETED: RecentlyDeletedTeamSandboxesFragment[] | null;
23-
RECENT_SANDBOXES: Sandbox[] | null;
24+
RECENT_SANDBOXES: (Sandbox | DraftSandboxFragment)[] | null;
2425
RECENT_BRANCHES: Branch[] | null;
25-
SEARCH: Sandbox[] | null;
26+
SEARCH: (Sandbox | DraftSandboxFragment)[] | null;
2627
TEMPLATE_HOME: Template[] | null;
27-
SHARED: Sandbox[] | null;
28+
SHARED: (Sandbox | DraftSandboxFragment)[] | null;
2829
ALL: {
29-
[path: string]: (Sandbox | SandboxByPathFragment)[];
30+
[path: string]: (Sandbox | SandboxByPathFragment | DraftSandboxFragment)[];
3031
} | null;
3132
REPOS: {
3233
[path: string]: {
@@ -138,7 +139,7 @@ export const state: State = {
138139
},
139140
getFilteredSandboxes: derived(
140141
({ orderBy }: State) => (
141-
sandboxes: Array<Sandbox | RecentlyDeletedTeamSandboxesFragment | Template['sandbox']>
142+
sandboxes: Array<Sandbox | SandboxByPathFragment | DraftSandboxFragment | RecentlyDeletedTeamSandboxesFragment | Template['sandbox']>
142143
) => {
143144
const orderField = orderBy.field;
144145
const orderOrder = orderBy.order;

packages/app/src/app/pages/Dashboard/Components/Sandbox/SandboxListItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const SandboxListItem = ({
162162
</Stack>
163163
</Column>
164164
<Column span={[0, 3, 3]} as={Stack} align="center">
165-
{sandbox.removedAt ? (
165+
{'removedAt' in sandbox && sandbox.removedAt ? (
166166
<Text
167167
size={3}
168168
variant={selected ? 'body' : 'muted'}

packages/app/src/app/pages/Dashboard/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
BranchFragment as Branch,
66
ProjectFragment as Repository,
77
RecentlyDeletedTeamSandboxesFragment,
8+
DraftSandboxFragment,
89
} from 'app/graphql/types';
910
import { Context } from 'app/overmind';
1011
import {
@@ -27,7 +28,8 @@ export type DashboardSandbox = {
2728
prNumber?: number;
2829
originalGit?: RepoFragmentDashboardFragment['originalGit'];
2930
})
30-
| RecentlyDeletedTeamSandboxesFragment;
31+
| RecentlyDeletedTeamSandboxesFragment
32+
| DraftSandboxFragment;
3133
noDrag?: boolean;
3234
};
3335

0 commit comments

Comments
 (0)