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 2 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;
}

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.

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
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