Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(site): refactor workspace quota to use react-query instead of XState#9626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 7 commits intomainfrombq/refactor-workspace-quota
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -961,9 +961,11 @@ export const deleteGroup = async (groupId: string): Promise<void> => {
};

export const getWorkspaceQuota = async (
userID: string,
username: string,
): Promise<TypesGen.WorkspaceQuota> => {
const response = await axios.get(`/api/v2/workspace-quota/${userID}`);
const response = await axios.get(
`/api/v2/workspace-quota/${encodeURIComponent(username)}`,
);
return response.data;
};

Expand Down
13 changes: 13 additions & 0 deletionssite/src/api/queries/workspaceQuota.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
import * as API from "api/api";

const getWorkspaceQuotaQueryKey = (username: string) => [
username,
"workspaceQuota",
];

export const workspaceQuota = (username: string) => {
return {
queryKey: getWorkspaceQuotaQueryKey(username),
queryFn: () => API.getWorkspaceQuota(username),
};
};
6 changes: 3 additions & 3 deletionssite/src/pages/WorkspacePage/Workspace.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -68,7 +68,7 @@ export interface WorkspaceProps {
buildInfo?: TypesGen.BuildInfoResponse;
sshPrefix?: string;
template?: TypesGen.Template;
quota_budget?: number;
quotaBudget?: number;
handleBuildRetry: () => void;
buildLogs?: React.ReactNode;
}
Expand DownExpand Up@@ -101,7 +101,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
buildInfo,
sshPrefix,
template,
quota_budget,
quotaBudget,
handleBuildRetry,
templateWarnings,
buildLogs,
Expand DownExpand Up@@ -183,7 +183,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({

<WorkspaceStats
workspace={workspace}
quota_budget={quota_budget}
quotaBudget={quotaBudget}
handleUpdate={handleUpdate}
canUpdateWorkspace={canUpdateWorkspace}
maxDeadlineDecrease={scheduleProps.maxDeadlineDecrease}
Expand Down
12 changes: 6 additions & 6 deletionssite/src/pages/WorkspacePage/WorkspacePage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,14 +3,15 @@ import { ChooseOne, Cond } from "components/Conditionals/ChooseOne";
import { Loader } from "components/Loader/Loader";
import { FC } from "react";
import { useParams } from "react-router-dom";
import { quotaMachine } from "xServices/quotas/quotasXService";
import { workspaceMachine } from "xServices/workspace/workspaceXService";
import { WorkspaceReadyPage } from "./WorkspaceReadyPage";
import { RequirePermission } from "components/RequirePermission/RequirePermission";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { useOrganizationId } from "hooks";
import { isAxiosError } from "axios";
import { Margins } from "components/Margins/Margins";
import { workspaceQuota } from "api/queries/workspaceQuota";
import { useQuery } from "@tanstack/react-query";

export const WorkspacePage: FC = () => {
const params = useParams() as {
Expand All@@ -28,9 +29,8 @@ export const WorkspacePage: FC = () => {
},
});
const { workspace, error } = workspaceState.context;
const [quotaState] = useMachine(quotaMachine, { context: { username } });
const { getQuotaError } = quotaState.context;
const pageError = error ?? getQuotaError;
const quotaQuery = useQuery(workspaceQuota(username));
const pageError = error ?? quotaQuery.error;

return (
<RequirePermission
Expand All@@ -48,12 +48,12 @@ export const WorkspacePage: FC = () => {
condition={
Boolean(workspace) &&
workspaceState.matches("ready") &&
quotaState.matches("success")
quotaQuery.isSuccess
}
>
<WorkspaceReadyPage
workspaceState={workspaceState}
quotaState={quotaState}
quota={quotaQuery.data}
workspaceSend={workspaceSend}
/>
</Cond>
Expand Down
7 changes: 3 additions & 4 deletionssite/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,6 @@ import {
getMaxDeadlineChange,
getMinDeadline,
} from "utils/schedule";
import { quotaMachine } from "xServices/quotas/quotasXService";
import { StateFrom } from "xstate";
import { DeleteDialog } from "components/Dialogs/DeleteDialog/DeleteDialog";
import { Workspace, WorkspaceErrors } from "./Workspace";
Expand All@@ -38,14 +37,14 @@ import { WorkspaceBuildLogsSection } from "./WorkspaceBuildLogsSection";

interface WorkspaceReadyPageProps {
workspaceState: StateFrom<typeof workspaceMachine>;
quotaState: StateFrom<typeof quotaMachine>;
workspaceSend: (event: WorkspaceEvent) => void;
quota?: TypesGen.WorkspaceQuota;
}

export const WorkspaceReadyPage = ({
workspaceState,
quotaState,
workspaceSend,
quota,
}: WorkspaceReadyPageProps): JSX.Element => {
const [_, bannerSend] = useActor(
workspaceState.children["scheduleBannerMachine"],
Expand DownExpand Up@@ -186,7 +185,7 @@ export const WorkspaceReadyPage = ({
buildInfo={buildInfo}
sshPrefix={sshPrefix}
template={template}
quota_budget={quotaState.context.quota?.budget}
quotaBudget={quota?.budget}
templateWarnings={templateVersion?.warnings}
buildLogs={
shouldDisplayBuildLogs && (
Expand Down
6 changes: 3 additions & 3 deletionssite/src/pages/WorkspacePage/WorkspaceStats.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,15 +39,15 @@ export interface WorkspaceStatsProps {
maxDeadlineIncrease: number;
maxDeadlineDecrease: number;
canUpdateWorkspace: boolean;
quota_budget?: number;
quotaBudget?: number;
onDeadlinePlus: (hours: number) => void;
onDeadlineMinus: (hours: number) => void;
handleUpdate: () => void;
}

export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
workspace,
quota_budget,
quotaBudget,
maxDeadlineDecrease,
maxDeadlineIncrease,
canUpdateWorkspace,
Expand DownExpand Up@@ -169,7 +169,7 @@ export const WorkspaceStats: FC<WorkspaceStatsProps> = ({
className={styles.statsItem}
label={Language.costLabel}
value={`${workspace.latest_build.daily_cost} ${
quota_budget ? `/ ${quota_budget}` : ""
quotaBudget ? `/ ${quotaBudget}` : ""
}`}
/>
)}
Expand Down
63 changes: 0 additions & 63 deletionssite/src/xServices/quotas/quotasXService.ts
View file
Open in desktop

This file was deleted.


[8]ページ先頭

©2009-2025 Movatter.jp