Skip to content

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

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 27 additions & 6 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -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`,
);
Expand Down Expand Up @@ -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`,
);
Expand Down Expand Up @@ -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;
Expand Down
40 changes: 0 additions & 40 deletions site/src/api/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/DeploySettingsLayout/OptionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ 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,
OptionValue,
} from "components/DeploySettingsLayout/Option";
import { FC } from "react";
import { optionValue } from "./optionValue";
import { DeploymentOption } from "api/api";

const OptionsTable: FC<{
options: DeploymentOption[];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeploymentOption } from "api/api";
import { optionValue } from "./optionValue";
import { DeploymentOption } from "api/types";

const defaultOption: DeploymentOption = {
name: "",
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/DeploySettingsLayout/optionValue.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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[];
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import {
Badges,
EnabledBadge,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import {
Badges,
DisabledBadge,
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DeploymentOption } from "api/types";
import { DeploymentOption } from "api/api";
import {
Badges,
DisabledBadge,
Expand Down
6 changes: 1 addition & 5 deletions site/src/pages/TerminalPage/TerminalPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
MockWorkspaceAgent,
} from "testHelpers/entities";
import { TextDecoder, TextEncoder } from "util";
import { ReconnectingPTYRequest } from "../../api/types";
import {
renderWithAuth,
waitForLoaderToBeRemoved,
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 7 additions & 4 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
},
Expand Down
3 changes: 1 addition & 2 deletions site/src/testHelpers/handlers.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion site/src/utils/deployOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeploymentOption, DeploymentGroup } from "api/api";
import { useMemo } from "react";
import { DeploymentGroup, DeploymentOption } from "../api/types";

const deploymentOptions = (
options: DeploymentOption[],
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
{
Expand Down
4 changes: 2 additions & 2 deletions site/src/xServices/template/templateVariablesXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -57,7 +57,7 @@ export const templateVariablesMachine = createMachine(
data: TemplateVersion;
};
updateTemplate: {
data: Message;
data: Response;
};
},
},
Expand Down
13 changes: 9 additions & 4 deletions site/src/xServices/terminal/terminalXService.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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" };

Expand Down
16 changes: 6 additions & 10 deletions site/src/xServices/workspace/workspaceXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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;
Expand Down