Skip to content

Commit 2cd9de1

Browse files
committed
Move quota fetching to be used close to where it is used
1 parent 964c3d2 commit 2cd9de1

File tree

4 files changed

+6
-16
lines changed

4 files changed

+6
-16
lines changed

site/src/pages/WorkspacePage/Workspace.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
102102
buildInfo,
103103
sshPrefix,
104104
template,
105-
quotaBudget,
106105
handleBuildRetry,
107106
buildLogs,
108107
onLoadMoreBuilds,
@@ -185,7 +184,6 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
185184

186185
<WorkspaceStats
187186
workspace={workspace}
188-
quotaBudget={quotaBudget}
189187
handleUpdate={handleUpdate}
190188
canUpdateWorkspace={canUpdateWorkspace}
191189
maxDeadlineDecrease={scheduleProps.maxDeadlineDecrease}

site/src/pages/WorkspacePage/WorkspacePage.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ErrorAlert } from "components/Alert/ErrorAlert";
99
import { useOrganizationId } from "hooks";
1010
import { isAxiosError } from "axios";
1111
import { Margins } from "components/Margins/Margins";
12-
import { workspaceQuota } from "api/queries/workspaceQuota";
1312
import { useInfiniteQuery, useQuery } from "react-query";
1413
import { infiniteWorkspaceBuilds } from "api/queries/workspaceBuilds";
1514
import { templateByName } from "api/queries/templates";
@@ -57,19 +56,14 @@ export const WorkspacePage: FC = () => {
5756
});
5857
const permissions = permissionsQuery.data as WorkspacePermissions | undefined;
5958

60-
const quotaQuery = useQuery(workspaceQuota(username));
61-
6259
const buildsQuery = useInfiniteQuery({
6360
...infiniteWorkspaceBuilds(workspace?.id ?? ""),
6461
enabled: workspace !== undefined,
6562
});
6663

6764
const pageError =
68-
workspaceQuery.error ??
69-
templateQuery.error ??
70-
quotaQuery.error ??
71-
permissionsQuery.error;
72-
const isLoading = !workspace || !template || !permissions || !quotaQuery.data;
65+
workspaceQuery.error ?? templateQuery.error ?? permissionsQuery.error;
66+
const isLoading = !workspace || !template || !permissions;
7367

7468
if (pageError) {
7569
return (
@@ -94,7 +88,6 @@ export const WorkspacePage: FC = () => {
9488
template={template}
9589
permissions={permissions}
9690
workspaceState={workspaceState}
97-
quota={quotaQuery.data}
9891
workspaceSend={workspaceSend}
9992
builds={buildsQuery.data?.pages.flat()}
10093
buildsError={buildsQuery.error}

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ interface WorkspaceReadyPageProps {
4848
"template" | "workspace" | "permissions"
4949
>;
5050
workspaceSend: (event: WorkspaceEvent) => void;
51-
quota?: TypesGen.WorkspaceQuota;
5251
builds: TypesGen.WorkspaceBuild[] | undefined;
5352
buildsError: unknown;
5453
onLoadMoreBuilds: () => void;
@@ -62,7 +61,6 @@ export const WorkspaceReadyPage = ({
6261
permissions,
6362
workspaceState,
6463
workspaceSend,
65-
quota,
6664
builds,
6765
buildsError,
6866
onLoadMoreBuilds,
@@ -212,7 +210,6 @@ export const WorkspaceReadyPage = ({
212210
buildInfo={buildInfo}
213211
sshPrefix={sshPrefix}
214212
template={template}
215-
quotaBudget={quota?.budget}
216213
buildLogs={
217214
shouldDisplayBuildLogs && (
218215
<WorkspaceBuildLogsSection logs={buildLogs} />

site/src/pages/WorkspacePage/WorkspaceStats.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import {
2424
PopoverTrigger,
2525
usePopover,
2626
} from "components/Popover/Popover";
27+
import { workspaceQuota } from "api/queries/workspaceQuota";
28+
import { useQuery } from "react-query";
2729

2830
const Language = {
2931
workspaceDetails: "Workspace Details",
@@ -37,15 +39,13 @@ export interface WorkspaceStatsProps {
3739
maxDeadlineIncrease: number;
3840
maxDeadlineDecrease: number;
3941
canUpdateWorkspace: boolean;
40-
quotaBudget?: number;
4142
onDeadlinePlus: (hours: number) => void;
4243
onDeadlineMinus: (hours: number) => void;
4344
handleUpdate: () => void;
4445
}
4546

4647
export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
4748
workspace,
48-
quotaBudget,
4949
maxDeadlineDecrease,
5050
maxDeadlineIncrease,
5151
canUpdateWorkspace,
@@ -56,6 +56,8 @@ export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
5656
const displayTemplateName = getDisplayWorkspaceTemplateName(workspace);
5757
const deadlinePlusEnabled = maxDeadlineIncrease >= 1;
5858
const deadlineMinusEnabled = maxDeadlineDecrease >= 1;
59+
const quotaQuery = useQuery(workspaceQuota(workspace.owner_name));
60+
const quotaBudget = quotaQuery.data?.budget;
5961

6062
const paperStyles = css`
6163
padding: 24px;

0 commit comments

Comments
 (0)