Skip to content

Commit 31d5d60

Browse files
committed
Render invalid experiments warning
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent c65406e commit 31d5d60

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

site/src/api/api.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -949,18 +949,19 @@ export const getAvailableExperiments =
949949
}
950950
};
951951

952-
export const getExperimentsDetail =
953-
async (): Promise<TypesGen.ExperimentDetail[]> => {
954-
try {
955-
const response = await axios.get("/api/v2/experiments/detail");
956-
return response.data;
957-
} catch (error) {
958-
if (axios.isAxiosError(error) && error.response?.status === 404) {
959-
return [];
960-
}
961-
throw error;
952+
export const getExperimentsDetail = async (): Promise<
953+
TypesGen.ExperimentDetail[]
954+
> => {
955+
try {
956+
const response = await axios.get("/api/v2/experiments/detail");
957+
return response.data;
958+
} catch (error) {
959+
if (axios.isAxiosError(error) && error.response?.status === 404) {
960+
return [];
962961
}
963-
};
962+
throw error;
963+
}
964+
};
964965

965966
export const getExternalAuthProvider = async (
966967
provider: string,

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Helmet } from "react-helmet-async";
33
import { useQuery } from "react-query";
44
import { deploymentDAUs } from "api/queries/deployment";
55
import { entitlements } from "api/queries/entitlements";
6-
import { availableExperiments } from "api/queries/experiments";
6+
import { experimentsDetail } from "api/queries/experiments";
77
import { pageTitle } from "utils/page";
88
import { useDeploySettings } from "../DeploySettingsLayout";
99
import { GeneralSettingsPageView } from "./GeneralSettingsPageView";
@@ -12,7 +12,7 @@ const GeneralSettingsPage: FC = () => {
1212
const { deploymentValues } = useDeploySettings();
1313
const deploymentDAUsQuery = useQuery(deploymentDAUs());
1414
const entitlementsQuery = useQuery(entitlements());
15-
const experimentsQuery = useQuery(availableExperiments());
15+
const experimentsQuery = useQuery(experimentsDetail());
1616

1717
return (
1818
<>
@@ -24,7 +24,7 @@ const GeneralSettingsPage: FC = () => {
2424
deploymentDAUs={deploymentDAUsQuery.data}
2525
deploymentDAUsError={deploymentDAUsQuery.error}
2626
entitlements={entitlementsQuery.data}
27-
safeExperiments={experimentsQuery.data?.safe ?? []}
27+
experiments={experimentsQuery.data}
2828
/>
2929
</>
3030
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const meta: Meta<typeof GeneralSettingsPageView> = {
4040
},
4141
],
4242
deploymentDAUs: MockDeploymentDAUResponse,
43-
safeExperiments: [],
43+
experiments: [],
4444
},
4545
};
4646

@@ -102,6 +102,6 @@ export const allExperimentsEnabled: Story = {
102102
hidden: false,
103103
},
104104
],
105-
safeExperiments: [],
105+
experiments: [],
106106
},
107107
};

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

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import AlertTitle from "@mui/material/AlertTitle";
12
import type { FC } from "react";
23
import type {
34
SerpentOption,
45
DAUsResponse,
56
Entitlements,
6-
Experiments,
7+
ExperimentDetail,
78
} from "api/typesGenerated";
89
import {
910
ActiveUserChart,
@@ -13,6 +14,7 @@ import { ErrorAlert } from "components/Alert/ErrorAlert";
1314
import { Stack } from "components/Stack/Stack";
1415
import { useDeploymentOptions } from "utils/deployOptions";
1516
import { docs } from "utils/docs";
17+
import { Alert } from "../../../components/Alert/Alert";
1618
import { Header } from "../Header";
1719
import OptionsTable from "../OptionsTable";
1820
import { ChartSection } from "./ChartSection";
@@ -22,16 +24,29 @@ export type GeneralSettingsPageViewProps = {
2224
deploymentDAUs?: DAUsResponse;
2325
deploymentDAUsError: unknown;
2426
entitlements: Entitlements | undefined;
25-
safeExperiments: Experiments | undefined;
27+
experiments?: ExperimentDetail[];
2628
};
2729

2830
export const GeneralSettingsPageView: FC<GeneralSettingsPageViewProps> = ({
2931
deploymentOptions,
3032
deploymentDAUs,
3133
deploymentDAUsError,
3234
entitlements,
33-
safeExperiments,
35+
experiments,
3436
}) => {
37+
const safe: string[] = [];
38+
const invalid: string[] = [];
39+
40+
if (experiments) {
41+
experiments?.forEach(function (value) {
42+
if (value.invalid) {
43+
invalid.push(value.name);
44+
} else {
45+
safe.push(value.name);
46+
}
47+
});
48+
}
49+
3550
return (
3651
<>
3752
<Header
@@ -58,14 +73,28 @@ export const GeneralSettingsPageView: FC<GeneralSettingsPageViewProps> = ({
5873
</ChartSection>
5974
</div>
6075
)}
76+
{invalid.length > 0 && (
77+
<Alert severity="warning">
78+
<AlertTitle>Invalid experiments in use:</AlertTitle>
79+
<ul>
80+
{invalid.map((it) => (
81+
<li key={it}>
82+
<pre>{it}</pre>
83+
</li>
84+
))}
85+
</ul>
86+
It is recommended that you remove these experiments from your
87+
configuration as they have no effect.
88+
</Alert>
89+
)}
6190
<OptionsTable
6291
options={useDeploymentOptions(
6392
deploymentOptions,
6493
"Access URL",
6594
"Wildcard Access URL",
6695
"Experiments",
6796
)}
68-
additionalValues={safeExperiments}
97+
additionalValues={safe}
6998
/>
7099
</Stack>
71100
</>

site/src/pages/DeploySettingsPage/optionValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function optionValue(
4141
const experimentMap: Record<string, boolean> | undefined =
4242
additionalValues?.reduce(
4343
(acc, v) => {
44-
return { ...acc, [v]: option.value.includes("*") ? true : false };
44+
return { ...acc, [v]: option.value.includes("*") };
4545
},
4646
{} as Record<string, boolean>,
4747
);

0 commit comments

Comments
 (0)