refactor: move auto fill feature into an experiment (#12230)

This commit is contained in:
Bruno Quaresma 2024-02-21 11:48:34 -03:00 committed by GitHub
parent c230bcf5ca
commit a827185b6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 18 deletions

7
coderd/apidoc/docs.go generated
View File

@ -9677,14 +9677,17 @@ const docTemplate = `{
"type": "string",
"enum": [
"example",
"shared-ports"
"shared-ports",
"auto-fill-parameters"
],
"x-enum-comments": {
"ExperimentAutoFillParameters": "This should not be taken out of experiments until we have redesigned the feature.",
"ExperimentExample": "This isn't used for anything."
},
"x-enum-varnames": [
"ExperimentExample",
"ExperimentSharedPorts"
"ExperimentSharedPorts",
"ExperimentAutoFillParameters"
]
},
"codersdk.ExternalAuth": {

View File

@ -8672,11 +8672,16 @@
},
"codersdk.Experiment": {
"type": "string",
"enum": ["example", "shared-ports"],
"enum": ["example", "shared-ports", "auto-fill-parameters"],
"x-enum-comments": {
"ExperimentAutoFillParameters": "This should not be taken out of experiments until we have redesigned the feature.",
"ExperimentExample": "This isn't used for anything."
},
"x-enum-varnames": ["ExperimentExample", "ExperimentSharedPorts"]
"x-enum-varnames": [
"ExperimentExample",
"ExperimentSharedPorts",
"ExperimentAutoFillParameters"
]
},
"codersdk.ExternalAuth": {
"type": "object",

View File

@ -2117,8 +2117,9 @@ type Experiment string
const (
// Add new experiments here!
ExperimentExample Experiment = "example" // This isn't used for anything.
ExperimentSharedPorts Experiment = "shared-ports"
ExperimentExample Experiment = "example" // This isn't used for anything.
ExperimentSharedPorts Experiment = "shared-ports"
ExperimentAutoFillParameters Experiment = "auto-fill-parameters" // This should not be taken out of experiments until we have redesigned the feature.
)
// ExperimentsAll should include all experiments that are safe for

9
docs/api/schemas.md generated
View File

@ -2917,10 +2917,11 @@ AuthorizationObject can represent a "set" of objects, such as: all workspaces in
#### Enumerated Values
| Value |
| -------------- |
| `example` |
| `shared-ports` |
| Value |
| ---------------------- |
| `example` |
| `shared-ports` |
| `auto-fill-parameters` |
## codersdk.ExternalAuth

View File

@ -1894,8 +1894,12 @@ export const Entitlements: Entitlement[] = [
];
// From codersdk/deployment.go
export type Experiment = "example" | "shared-ports";
export const Experiments: Experiment[] = ["example", "shared-ports"];
export type Experiment = "auto-fill-parameters" | "example" | "shared-ports";
export const Experiments: Experiment[] = [
"auto-fill-parameters",
"example",
"shared-ports",
];
// From codersdk/deployment.go
export type FeatureName =

View File

@ -26,6 +26,7 @@ import { paramsUsedToCreateWorkspace } from "utils/workspace";
import { CreateWorkspacePageView } from "./CreateWorkspacePageView";
import { CreateWSPermissions, createWorkspaceChecks } from "./permissions";
import { generateWorkspaceName } from "modules/workspaces/generateWorkspaceName";
import { useDashboard } from "modules/dashboard/useDashboard";
export const createWorkspaceModes = ["form", "auto", "duplicate"] as const;
export type CreateWorkspaceMode = (typeof createWorkspaceModes)[number];
@ -40,6 +41,7 @@ const CreateWorkspacePage: FC = () => {
const [searchParams, setSearchParams] = useSearchParams();
const mode = getWorkspaceMode(searchParams);
const customVersionId = searchParams.get("version") ?? undefined;
const { experiments } = useDashboard();
const defaultName = searchParams.get("name");
@ -51,12 +53,6 @@ const CreateWorkspacePage: FC = () => {
const templateQuery = useQuery(templateByName(organizationId, templateName));
const userParametersQuery = useQuery({
queryKey: ["userParameters"],
queryFn: () => getUserParameters(templateQuery.data!.id),
enabled: templateQuery.isSuccess,
});
const permissionsQuery = useQuery(
checkAuthorization({
checks: createWorkspaceChecks(organizationId),
@ -97,6 +93,13 @@ const CreateWorkspacePage: FC = () => {
[navigate],
);
// Auto fill parameters
const userParametersQuery = useQuery({
queryKey: ["userParameters"],
queryFn: () => getUserParameters(templateQuery.data!.id),
enabled:
experiments.includes("auto-fill-parameters") && templateQuery.isSuccess,
});
const autofillParameters = getAutofillParameters(
searchParams,
userParametersQuery.data ? userParametersQuery.data : [],