chore(site): remove unecessary types and move types to where they are used (#9621)

This commit is contained in:
Bruno Quaresma
2023-09-12 13:54:05 -03:00
committed by GitHub
parent 0e28397c82
commit b7550bfda5
21 changed files with 70 additions and 87 deletions
+27 -6
View File
@@ -1,7 +1,5 @@
import axios from "axios";
import dayjs from "dayjs";
import * as Types from "./types";
import { DeploymentConfig } from "./types";
import * as TypesGen from "./typesGenerated";
import { delay } from "utils/delay";
import userAgentParser from "ua-parser-js";
@@ -365,8 +363,8 @@ export const createTemplate = async (
export const updateActiveTemplateVersion = async (
templateId: string,
data: TypesGen.UpdateActiveTemplateVersion,
): Promise<Types.Message> => {
const response = await axios.patch<Types.Message>(
) => {
const response = await axios.patch<TypesGen.Response>(
`/api/v2/templates/${templateId}/versions`,
data,
);
@@ -547,7 +545,7 @@ export const deleteWorkspace = (
export const cancelWorkspaceBuild = async (
workspaceBuildId: TypesGen.WorkspaceBuild["id"],
): Promise<Types.Message> => {
): Promise<TypesGen.Response> => {
const response = await axios.patch(
`/api/v2/workspacebuilds/${workspaceBuildId}/cancel`,
);
@@ -595,7 +593,7 @@ export const restartWorkspace = async ({
export const cancelTemplateVersionBuild = async (
templateVersionId: TypesGen.TemplateVersion["id"],
): Promise<Types.Message> => {
): Promise<TypesGen.Response> => {
const response = await axios.patch(
`/api/v2/templateversions/${templateVersionId}/cancel`,
);
@@ -985,6 +983,29 @@ export const getDeploymentSSHConfig =
return response.data;
};
// The Deployment types are not generated on from the Go generator yet because
// it does not know how to generate OptionSet
export interface DeploymentGroup {
readonly name: string;
readonly parent?: DeploymentGroup;
readonly description: string;
readonly children: DeploymentGroup[];
}
export interface DeploymentOption {
readonly name: string;
readonly description: string;
readonly flag: string;
readonly flag_shorthand: string;
readonly value: unknown;
readonly hidden: boolean;
readonly group?: DeploymentGroup;
}
export type DeploymentConfig = {
readonly config: TypesGen.DeploymentValues;
readonly options: DeploymentOption[];
};
export const getDeploymentValues = async (): Promise<DeploymentConfig> => {
const response = await axios.get(`/api/v2/deployment/config`);
return response.data;
-40
View File
@@ -1,40 +0,0 @@
import { DeploymentValues } from "./typesGenerated";
export interface UserAgent {
readonly browser: string;
readonly device: string;
readonly ip_address: string;
readonly os: string;
}
export interface ReconnectingPTYRequest {
readonly data?: string;
readonly height?: number;
readonly width?: number;
}
export type WorkspaceBuildTransition = "start" | "stop" | "delete";
export type Message = { message: string };
export interface DeploymentGroup {
readonly name: string;
readonly parent?: DeploymentGroup;
readonly description: string;
readonly children: DeploymentGroup[];
}
export interface DeploymentOption {
readonly name: string;
readonly description: string;
readonly flag: string;
readonly flag_shorthand: string;
readonly value: unknown;
readonly hidden: boolean;
readonly group?: DeploymentGroup;
}
export type DeploymentConfig = {
readonly config: DeploymentValues;
readonly options: DeploymentOption[];
};
@@ -10,7 +10,7 @@ import { deploymentConfigMachine } from "xServices/deploymentConfig/deploymentCo
import { RequirePermission } from "components/RequirePermission/RequirePermission";
import { usePermissions } from "hooks/usePermissions";
import { Outlet } from "react-router-dom";
import { DeploymentConfig } from "api/types";
import { DeploymentConfig } from "api/api";
type DeploySettingsContextValue = {
deploymentValues: DeploymentConfig;
@@ -5,7 +5,6 @@ import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import { DeploymentOption } from "api/types";
import {
OptionDescription,
OptionName,
@@ -13,6 +12,7 @@ import {
} from "components/DeploySettingsLayout/Option";
import { FC } from "react";
import { optionValue } from "./optionValue";
import { DeploymentOption } from "api/api";
const OptionsTable: FC<{
options: DeploymentOption[];
@@ -1,5 +1,5 @@
import { DeploymentOption } from "api/api";
import { optionValue } from "./optionValue";
import { DeploymentOption } from "api/types";
const defaultOption: DeploymentOption = {
name: "",
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import { intervalToDuration, formatDuration } from "date-fns";
// optionValue is a helper function to format the value of a specific deployment options
@@ -1,5 +1,4 @@
import Box from "@mui/material/Box";
import { DeploymentOption } from "api/types";
import { DAUsResponse } from "api/typesGenerated";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { DAUChart, DAUTitle } from "components/DAUChart/DAUChart";
@@ -9,6 +8,7 @@ import { Stack } from "components/Stack/Stack";
import { ChartSection } from "./ChartSection";
import { useDeploymentOptions } from "utils/deployOptions";
import { docs } from "utils/docs";
import { DeploymentOption } from "api/api";
export type GeneralSettingsPageViewProps = {
deploymentOptions: DeploymentOption[];
@@ -1,4 +1,4 @@
import { DeploymentGroup } from "api/types";
import { DeploymentGroup } from "api/api";
import { NetworkSettingsPageView } from "./NetworkSettingsPageView";
import type { Meta, StoryObj } from "@storybook/react";
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import {
Badges,
EnabledBadge,
@@ -1,4 +1,4 @@
import { DeploymentGroup, DeploymentOption } from "api/types";
import { DeploymentGroup, DeploymentOption } from "api/api";
import { SecuritySettingsPageView } from "./SecuritySettingsPageView";
import type { Meta, StoryObj } from "@storybook/react";
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import {
Badges,
DisabledBadge,
@@ -1,4 +1,4 @@
import { DeploymentGroup } from "api/types";
import { DeploymentGroup } from "api/api";
import { UserAuthSettingsPageView } from "./UserAuthSettingsPageView";
import type { Meta, StoryObj } from "@storybook/react";
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import {
Badges,
DisabledBadge,
@@ -8,7 +8,6 @@ import {
MockWorkspaceAgent,
} from "testHelpers/entities";
import { TextDecoder, TextEncoder } from "util";
import { ReconnectingPTYRequest } from "../../api/types";
import {
renderWithAuth,
waitForLoaderToBeRemoved,
@@ -142,10 +141,7 @@ describe("TerminalPage", () => {
// Then
await ws.connected;
const msg = await ws.nextMessage;
const req: ReconnectingPTYRequest = JSON.parse(
new TextDecoder().decode(msg as Uint8Array),
);
const req = JSON.parse(new TextDecoder().decode(msg as Uint8Array));
expect(req.height).toBeGreaterThan(0);
expect(req.width).toBeGreaterThan(0);
ws.close();
+7 -4
View File
@@ -1,7 +1,10 @@
import { withDefaultFeatures, GetLicensesResponse } from "api/api";
import {
withDefaultFeatures,
GetLicensesResponse,
DeploymentConfig,
} from "api/api";
import { FieldError } from "api/errors";
import { everyOneGroup } from "utils/groups";
import * as Types from "api/types";
import * as TypesGen from "api/typesGenerated";
import range from "lodash/range";
import { Permissions } from "xServices/auth/authXService";
@@ -1114,7 +1117,7 @@ export const MockWorkspaceRequest: TypesGen.CreateWorkspaceRequest = {
],
};
export const MockUserAgent: Types.UserAgent = {
export const MockUserAgent = {
browser: "Chrome 99.0.4844",
device: "Other",
ip_address: "11.22.33.44",
@@ -2049,7 +2052,7 @@ export const MockPermissions: Permissions = {
editWorkspaceProxies: true,
};
export const MockDeploymentConfig: Types.DeploymentConfig = {
export const MockDeploymentConfig: DeploymentConfig = {
config: {
enable_terraform_debug_mode: true,
},
+1 -2
View File
@@ -1,5 +1,4 @@
import { rest } from "msw";
import { WorkspaceBuildTransition } from "../api/types";
import { CreateWorkspaceBuildRequest } from "../api/typesGenerated";
import { permissionsToCheck } from "../xServices/auth/authXService";
import * as M from "./entities";
@@ -238,7 +237,7 @@ export const handlers = [
stop: M.MockWorkspaceBuildStop,
delete: M.MockWorkspaceBuildDelete,
};
const result = transitionToBuild[transition as WorkspaceBuildTransition];
const result = transitionToBuild[transition];
return res(ctx.status(200), ctx.json(result));
}),
rest.get("/api/v2/workspaces/:workspaceId/builds", async (req, res, ctx) => {
+1 -1
View File
@@ -1,5 +1,5 @@
import { DeploymentOption, DeploymentGroup } from "api/api";
import { useMemo } from "react";
import { DeploymentGroup, DeploymentOption } from "../api/types";
const deploymentOptions = (
options: DeploymentOption[],
@@ -1,7 +1,10 @@
import { DAUsResponse } from "./../../api/typesGenerated";
import { getDeploymentValues, getDeploymentDAUs } from "api/api";
import {
getDeploymentValues,
getDeploymentDAUs,
DeploymentConfig,
} from "api/api";
import { createMachine, assign } from "xstate";
import { DeploymentConfig } from "api/types";
export const deploymentConfigMachine = createMachine(
{
@@ -6,13 +6,13 @@ import {
} from "api/api";
import {
CreateTemplateVersionRequest,
Response,
Template,
TemplateVersion,
TemplateVersionVariable,
} from "api/typesGenerated";
import { assign, createMachine } from "xstate";
import { delay } from "utils/delay";
import { Message } from "api/types";
type TemplateVariablesContext = {
organizationId: string;
@@ -57,7 +57,7 @@ export const templateVariablesMachine = createMachine(
data: TemplateVersion;
};
updateTemplate: {
data: Message;
data: Response;
};
},
},
@@ -1,7 +1,12 @@
import { assign, createMachine } from "xstate";
import * as API from "../../api/api";
import * as Types from "../../api/types";
import * as TypesGen from "../../api/typesGenerated";
import * as API from "api/api";
import * as TypesGen from "api/typesGenerated";
interface ReconnectingPTYRequest {
readonly data?: string;
readonly height?: number;
readonly width?: number;
}
export interface TerminalContext {
workspaceError?: unknown;
@@ -33,7 +38,7 @@ export type TerminalEvent =
workspaceName?: string;
username?: string;
}
| { type: "WRITE"; request: Types.ReconnectingPTYRequest }
| { type: "WRITE"; request: ReconnectingPTYRequest }
| { type: "READ"; data: ArrayBuffer }
| { type: "DISCONNECT" };
@@ -2,13 +2,9 @@ import { getErrorMessage } from "api/errors";
import dayjs from "dayjs";
import { workspaceScheduleBannerMachine } from "xServices/workspaceSchedule/workspaceScheduleBannerXService";
import { assign, createMachine, send } from "xstate";
import * as API from "../../api/api";
import * as Types from "../../api/types";
import * as TypesGen from "../../api/typesGenerated";
import {
displayError,
displaySuccess,
} from "../../components/GlobalSnackbar/utils";
import * as API from "api/api";
import * as TypesGen from "api/typesGenerated";
import { displayError, displaySuccess } from "components/GlobalSnackbar/utils";
const latestBuild = (builds: TypesGen.WorkspaceBuild[]) => {
// Cloning builds to not change the origin object with the sort()
@@ -65,7 +61,7 @@ export interface WorkspaceContext {
missedParameters?: TypesGen.TemplateVersionParameter[];
// error creating a new WorkspaceBuild
buildError?: unknown;
cancellationMessage?: Types.Message;
cancellationMessage?: TypesGen.Response;
cancellationError?: unknown;
// debug
createBuildLogLevel?: TypesGen.CreateWorkspaceBuildRequest["log_level"];
@@ -171,10 +167,10 @@ export const workspaceMachine = createMachine(
data: TypesGen.WorkspaceBuild;
};
cancelWorkspace: {
data: Types.Message;
data: TypesGen.Response;
};
activateWorkspace: {
data: Types.Message;
data: TypesGen.Response;
};
listening: {
data: TypesGen.ServerSentEvent;