Skip to content

Commit beac360

Browse files
authored
chore: generate any interface as Deployment Option in TypeScript (#9917)
* chore: handle interfaces as "any" in typescript Use generated Deployment Option
1 parent 885041a commit beac360

File tree

14 files changed

+42
-82
lines changed

14 files changed

+42
-82
lines changed

scripts/apitypings/main.go

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -989,28 +989,13 @@ func (g *Generator) typescriptType(ty types.Type) (TypescriptType, error) {
989989
}, nil
990990
}
991991

992-
// Do support "Stringer" interfaces, they likely can get string
993-
// marshaled.
994-
for i := 0; i < intf.NumMethods(); i++ {
995-
meth := intf.Method(i)
996-
if meth.Name() == "String" {
997-
return TypescriptType{
998-
ValueType: "string",
999-
AboveTypeLine: indentedComment("actual value is an interface that implements 'String()'"),
1000-
Optional: false,
1001-
}, nil
1002-
}
1003-
}
1004-
1005-
// All complex interfaces should be named. So if we get here, that means
1006-
// we are using anonymous interfaces. Which is just weird and not supported.
1007-
// Example:
1008-
// type Foo struct {
1009-
// Bar interface {
1010-
// Baz() string
1011-
// }
1012-
// }
1013-
return TypescriptType{}, xerrors.New("only empty interface types are supported")
992+
// Interfaces are difficult to determine the JSON type, so just return
993+
// an 'any'.
994+
return TypescriptType{
995+
ValueType: "any",
996+
AboveTypeLine: indentedComment("eslint-disable-next-line @typescript-eslint/no-explicit-any -- Golang interface, unable to resolve type."),
997+
Optional: false,
998+
}, nil
1014999
case *types.TypeParam:
10151000
_, ok := ty.Underlying().(*types.Interface)
10161001
if !ok {

site/src/api/api.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,29 +1016,9 @@ export const getDeploymentSSHConfig =
10161016
return response.data;
10171017
};
10181018

1019-
// The Deployment types are not generated on from the Go generator yet because
1020-
// it does not know how to generate OptionSet
1021-
export interface DeploymentGroup {
1022-
readonly name: string;
1023-
readonly parent?: DeploymentGroup;
1024-
readonly description: string;
1025-
readonly children: DeploymentGroup[];
1026-
}
1027-
export interface DeploymentOption {
1028-
readonly name: string;
1029-
readonly description: string;
1030-
readonly flag: string;
1031-
readonly flag_shorthand: string;
1032-
readonly value: unknown;
1033-
readonly hidden: boolean;
1034-
readonly group?: DeploymentGroup;
1035-
readonly env?: string;
1036-
readonly yaml?: string;
1037-
}
1038-
10391019
export type DeploymentConfig = {
10401020
readonly config: TypesGen.DeploymentValues;
1041-
readonly options: DeploymentOption[];
1021+
readonly options: TypesGen.ClibaseOption[];
10421022
};
10431023

10441024
export const getDeploymentConfig = async (): Promise<DeploymentConfig> => {

site/src/api/typesGenerated.ts

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/components/DeploySettingsLayout/OptionsTable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import {
1414
} from "components/DeploySettingsLayout/Option";
1515
import { FC } from "react";
1616
import { optionValue } from "./optionValue";
17-
import { DeploymentOption } from "api/api";
1817
import Box from "@mui/material/Box";
18+
import { ClibaseOption } from "api/typesGenerated";
1919

2020
const OptionsTable: FC<{
21-
options: DeploymentOption[];
21+
options: ClibaseOption[];
2222
}> = ({ options }) => {
2323
const styles = useStyles();
2424

site/src/components/DeploySettingsLayout/optionValue.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { DeploymentOption } from "api/api";
21
import { optionValue } from "./optionValue";
2+
import { ClibaseOption } from "api/typesGenerated";
33

4-
const defaultOption: DeploymentOption = {
4+
const defaultOption: ClibaseOption = {
55
name: "",
66
description: "",
77
flag: "",
@@ -12,7 +12,7 @@ const defaultOption: DeploymentOption = {
1212

1313
describe("optionValue", () => {
1414
it.each<{
15-
option: DeploymentOption;
15+
option: ClibaseOption;
1616
expected: unknown;
1717
}>([
1818
{

site/src/components/DeploySettingsLayout/optionValue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { DeploymentOption } from "api/api";
1+
import { ClibaseOption } from "api/typesGenerated";
22
import { intervalToDuration, formatDuration } from "date-fns";
33

44
// optionValue is a helper function to format the value of a specific deployment options
5-
export function optionValue(option: DeploymentOption) {
5+
export function optionValue(option: ClibaseOption) {
66
switch (option.name) {
77
case "Max Token Lifetime":
88
case "Session Duration":

site/src/pages/DeploySettingsPage/GeneralSettingsPage/GeneralSettingsPageView.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Box from "@mui/material/Box";
2-
import { DAUsResponse } from "api/typesGenerated";
2+
import { ClibaseOption, DAUsResponse } from "api/typesGenerated";
33
import { ErrorAlert } from "components/Alert/ErrorAlert";
44
import { DAUChart, DAUTitle } from "components/DAUChart/DAUChart";
55
import { Header } from "components/DeploySettingsLayout/Header";
@@ -8,10 +8,9 @@ import { Stack } from "components/Stack/Stack";
88
import { ChartSection } from "./ChartSection";
99
import { useDeploymentOptions } from "utils/deployOptions";
1010
import { docs } from "utils/docs";
11-
import { DeploymentOption } from "api/api";
1211

1312
export type GeneralSettingsPageViewProps = {
14-
deploymentOptions: DeploymentOption[];
13+
deploymentOptions: ClibaseOption[];
1514
deploymentDAUs?: DAUsResponse;
1615
deploymentDAUsError: unknown;
1716
};

site/src/pages/DeploySettingsPage/NetworkSettingsPage/NetworkSettingsPageView.stories.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { DeploymentGroup } from "api/api";
1+
import { ClibaseGroup } from "api/typesGenerated";
22
import { NetworkSettingsPageView } from "./NetworkSettingsPageView";
33
import type { Meta, StoryObj } from "@storybook/react";
44

5-
const group: DeploymentGroup = {
5+
const group: ClibaseGroup = {
66
name: "Networking",
77
description: "",
8-
children: [] as DeploymentGroup[],
98
};
109

1110
const meta: Meta<typeof NetworkSettingsPageView> = {

site/src/pages/DeploySettingsPage/NetworkSettingsPage/NetworkSettingsPageView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DeploymentOption } from "api/api";
1+
import { ClibaseOption } from "api/typesGenerated";
22
import {
33
Badges,
44
EnabledBadge,
@@ -14,7 +14,7 @@ import {
1414
import { docs } from "utils/docs";
1515

1616
export type NetworkSettingsPageViewProps = {
17-
options: DeploymentOption[];
17+
options: ClibaseOption[];
1818
};
1919

2020
export const NetworkSettingsPageView = ({

site/src/pages/DeploySettingsPage/SecuritySettingsPage/SecuritySettingsPageView.stories.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { DeploymentGroup, DeploymentOption } from "api/api";
21
import { SecuritySettingsPageView } from "./SecuritySettingsPageView";
32
import type { Meta, StoryObj } from "@storybook/react";
3+
import { ClibaseGroup, ClibaseOption } from "api/typesGenerated";
44

5-
const group: DeploymentGroup = {
5+
const group: ClibaseGroup = {
66
name: "Networking",
77
description: "",
8-
children: [] as DeploymentGroup[],
98
};
109

1110
const meta: Meta<typeof SecuritySettingsPageView> = {
@@ -64,15 +63,15 @@ export const NoTLS = {
6463
{
6564
name: "SSH Keygen Algorithm",
6665
value: "1234",
67-
} as DeploymentOption,
66+
} as ClibaseOption,
6867
{
6968
name: "Disable Owner Workspace Access",
7069
value: false,
71-
} as DeploymentOption,
70+
} as ClibaseOption,
7271
{
7372
name: "Secure Auth Cookie",
7473
value: "1234",
75-
} as DeploymentOption,
74+
} as ClibaseOption,
7675
],
7776
},
7877
};

site/src/pages/DeploySettingsPage/SecuritySettingsPage/SecuritySettingsPageView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DeploymentOption } from "api/api";
1+
import { ClibaseOption } from "api/typesGenerated";
22
import {
33
Badges,
44
DisabledBadge,
@@ -15,7 +15,7 @@ import {
1515
import { docs } from "utils/docs";
1616

1717
export type SecuritySettingsPageViewProps = {
18-
options: DeploymentOption[];
18+
options: ClibaseOption[];
1919
featureAuditLogEnabled: boolean;
2020
featureBrowserOnlyEnabled: boolean;
2121
};

site/src/pages/DeploySettingsPage/UserAuthSettingsPage/UserAuthSettingsPageView.stories.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
import { DeploymentGroup } from "api/api";
1+
import { ClibaseGroup } from "api/typesGenerated";
22
import { UserAuthSettingsPageView } from "./UserAuthSettingsPageView";
33
import type { Meta, StoryObj } from "@storybook/react";
44

5-
const oidcGroup: DeploymentGroup = {
5+
const oidcGroup: ClibaseGroup = {
66
name: "OIDC",
77
description: "",
8-
children: [] as DeploymentGroup[],
98
};
109

11-
const ghGroup: DeploymentGroup = {
10+
const ghGroup: ClibaseGroup = {
1211
name: "GitHub",
1312
description: "",
14-
children: [] as DeploymentGroup[],
1513
};
1614

1715
const meta: Meta<typeof UserAuthSettingsPageView> = {

site/src/pages/DeploySettingsPage/UserAuthSettingsPage/UserAuthSettingsPageView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DeploymentOption } from "api/api";
1+
import { ClibaseOption } from "api/typesGenerated";
22
import {
33
Badges,
44
DisabledBadge,
@@ -14,7 +14,7 @@ import {
1414
import { docs } from "utils/docs";
1515

1616
export type UserAuthSettingsPageViewProps = {
17-
options: DeploymentOption[];
17+
options: ClibaseOption[];
1818
};
1919

2020
export const UserAuthSettingsPageView = ({

site/src/utils/deployOptions.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { DeploymentOption, DeploymentGroup } from "api/api";
1+
import { ClibaseGroup, ClibaseOption } from "api/typesGenerated";
22
import { useMemo } from "react";
33

44
const deploymentOptions = (
5-
options: DeploymentOption[],
5+
options: ClibaseOption[],
66
...names: string[]
7-
): DeploymentOption[] => {
8-
const found: DeploymentOption[] = [];
7+
): ClibaseOption[] => {
8+
const found: ClibaseOption[] = [];
99
for (const name of names) {
1010
const option = options.find((o) => o.name === name);
1111
if (option) {
@@ -18,14 +18,14 @@ const deploymentOptions = (
1818
};
1919

2020
export const useDeploymentOptions = (
21-
options: DeploymentOption[],
21+
options: ClibaseOption[],
2222
...names: string[]
23-
): DeploymentOption[] => {
23+
): ClibaseOption[] => {
2424
return useMemo(() => deploymentOptions(options, ...names), [options, names]);
2525
};
2626

2727
export const deploymentGroupHasParent = (
28-
group: DeploymentGroup | undefined,
28+
group: ClibaseGroup | undefined,
2929
parent: string,
3030
): boolean => {
3131
if (!group) {

0 commit comments

Comments
 (0)