Skip to content

feat(site): disable rich parameters when using open in coder #10114

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
Oct 9, 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
7 changes: 7 additions & 0 deletions docs/templates/open-in-coder.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ approach for "Open in Coder" flows.

![Pre-filled parameters](../images/templates/pre-filled-parameters.png)

1. Optional: disable specific parameter fields by including their names as
specified in your template in the `disable_params` search params list

```md
[![Open in Coder](https://YOUR_ACCESS_URL/open-in-coder.svg)](https://YOUR_ACCESS_URL/templates/YOUR_TEMPLATE/workspace?disable_params=first_parameter,second_parameter)
```

## Example: Kubernetes

For a full example of the Open in Coder flow in Kubernetes, check out
Expand Down
24 changes: 23 additions & 1 deletion site/e2e/tests/createWorkspace.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { test } from "@playwright/test";
import { test, expect } from "@playwright/test";
import {
createTemplate,
createWorkspace,
Expand Down Expand Up @@ -119,3 +119,25 @@ test("create workspace and overwrite default parameters", async ({ page }) => {
);
await verifyParameters(page, workspaceName, richParameters, buildParameters);
});

test("create workspace with disable_param search params", async ({ page }) => {
const richParameters: RichParameter[] = [
firstParameter, // mutable
secondParameter, //immutable
];

const templateName = await createTemplate(
page,
echoResponsesWithParameters(richParameters),
);

await page.goto(
`/templates/${templateName}/workspace?disable_params=first_parameter,second_parameter`,
{
waitUntil: "domcontentloaded",
},
);

await expect(page.getByLabel(/First parameter/i)).toBeDisabled();
await expect(page.getByLabel(/Second parameter/i)).toBeDisabled();
});
14 changes: 12 additions & 2 deletions site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ExternalAuth } from "./ExternalAuth";
import { ErrorAlert } from "components/Alert/ErrorAlert";
import { Stack } from "components/Stack/Stack";
import { type ExternalAuthPollingState } from "./CreateWorkspacePage";
import { useSearchParams } from "react-router-dom";

export interface CreateWorkspacePageViewProps {
error: unknown;
Expand Down Expand Up @@ -72,6 +73,9 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
const [owner, setOwner] = useState(defaultOwner);
const { verifyExternalAuth, externalAuthErrors } =
useExternalAuthVerification(externalAuth);
const [searchParams] = useSearchParams();
const disabledParamsList = searchParams?.get("disable_params")?.split(",");

const form: FormikContextType<TypesGen.CreateWorkspaceRequest> =
useFormik<TypesGen.CreateWorkspaceRequest>({
initialValues: {
Expand Down Expand Up @@ -198,7 +202,10 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
value: value,
});
},
disabled: form.isSubmitting,
disabled:
disabledParamsList?.includes(
parameter.name.toLowerCase().replace(/ /g, "_"),
) || form.isSubmitting,
};
}}
/>
Expand All @@ -216,7 +223,10 @@ export const CreateWorkspacePageView: FC<CreateWorkspacePageViewProps> = ({
value: value,
});
},
disabled: form.isSubmitting,
disabled:
disabledParamsList?.includes(
parameter.name.toLowerCase().replace(/ /g, "_"),
) || form.isSubmitting,
};
}}
/>
Expand Down