Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: show a warning when an organization has no provisioners#14136

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 5 commits intomainfromprovisioner-warning
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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 deletionsdocs/admin/provisioners.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -67,6 +67,13 @@ There are two exceptions:
**Organization-scoped Provisioners** can pick up build jobs created by any user.
These provisioners always have the implicit tags `scope=organization owner=""`.

```shell
coder provisionerd start --org <organization_name>
```

If you omit the `--org` argument, the provisioner will be assigned to the
default organization.

```shell
coder provisionerd start
```
Expand Down
12 changes: 12 additions & 0 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -627,6 +627,18 @@ class ApiMethods {
return response.data;
};

/**
* @param organization Can be the organization's ID or name
*/
getProvisionerDaemonsByOrganization = async (
organization: string,
): Promise<TypesGen.ProvisionerDaemon[]> => {
const response = await this.axios.get<TypesGen.ProvisionerDaemon[]>(
`/api/v2/organizations/${organization}/provisionerdaemons`,
);
return response.data;
};

getTemplate = async (templateId: string): Promise<TypesGen.Template> => {
const response = await this.axios.get<TypesGen.Template>(
`/api/v2/templates/${templateId}`,
Expand Down
13 changes: 13 additions & 0 deletionssite/src/api/queries/organizations.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -107,3 +107,16 @@ export const organizations = () => {
queryFn: () => API.getOrganizations(),
};
};

export const getProvisionerDaemonsKey = (organization: string) => [
"organization",
organization,
"provisionerDaemons",
];

export const provisionerDaemons = (organization: string) => {
return {
queryKey: getProvisionerDaemonsKey(organization),
queryFn: () => API.getProvisionerDaemonsByOrganization(organization),
};
};
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
import { action } from "@storybook/addon-actions";
import type { Meta, StoryObj } from "@storybook/react";
import { screen, userEvent } from "@storybook/test";
import {
getProvisionerDaemonsKey,
organizationsKey,
} from "api/queries/organizations";
import {
MockDefaultOrganization,
MockOrganization2,
MockTemplate,
MockTemplateExample,
MockTemplateVersionVariable1,
Expand DownExpand Up@@ -54,6 +61,31 @@ export const StarterTemplateWithOrgPicker: Story = {
},
};

export const StarterTemplateWithProvisionerWarning: Story = {
parameters: {
queries: [
{
key: organizationsKey,
data: [MockDefaultOrganization, MockOrganization2],
},
{
key: getProvisionerDaemonsKey(MockOrganization2.id),
data: [],
},
],
},
args: {
...StarterTemplate.args,
showOrganizationPicker: true,
},
play: async () => {
const organizationPicker = screen.getByPlaceholderText("Organization name");
await userEvent.click(organizationPicker);
const org2 = await screen.findByText(MockOrganization2.display_name);
await userEvent.click(org2);
},
};

export const DuplicateTemplateWithVariables: Story = {
args: {
copiedTemplate: MockTemplate,
Expand Down
60 changes: 49 additions & 11 deletionssite/src/pages/CreateTemplatePage/CreateTemplateForm.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
import Link from "@mui/material/Link";
import TextField from "@mui/material/TextField";
import { useFormik } from "formik";
import camelCase from "lodash/camelCase";
import capitalize from "lodash/capitalize";
import { useState, type FC } from "react";
import { useQuery } from "react-query";
import { useSearchParams } from "react-router-dom";
import * as Yup from "yup";
import { provisionerDaemons } from "api/queries/organizations";
import type {
Organization,
ProvisionerJobLog,
Expand All@@ -14,6 +17,7 @@ import type {
TemplateVersionVariable,
VariableValue,
} from "api/typesGenerated";
import { Alert } from "components/Alert/Alert";
import {
HorizontalForm,
FormSection,
Expand All@@ -23,6 +27,7 @@ import {
import { IconField } from "components/IconField/IconField";
import { OrganizationAutocomplete } from "components/OrganizationAutocomplete/OrganizationAutocomplete";
import { SelectedTemplate } from "pages/CreateWorkspacePage/SelectedTemplate";
import { docs } from "utils/docs";
import {
nameValidator,
getFormHelpers,
Expand DownExpand Up@@ -210,6 +215,24 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
});
const getFieldHelpers = getFormHelpers<CreateTemplateFormData>(form, error);

const provisionerDaemonsQuery = useQuery(
selectedOrg
? {
...provisionerDaemons(selectedOrg.id),
enabled: showOrganizationPicker,
select: (provisioners) => provisioners.length < 1,
}
: { enabled: false },
);

// TODO: Ideally, we would have a backend endpoint that could notify the
// frontend that a provisioner has been connected, so that we could hide
// this warning. In the meantime, **do not use this variable to disable
// form submission**!! A user could easily see this warning, connect a
// provisioner, and then not refresh the page. Even if they submit without
// a provisioner, it'll just sit in the job queue until they connect one.
const showProvisionerWarning = provisionerDaemonsQuery.data;

return (
<HorizontalForm onSubmit={form.handleSubmit}>
{/* General info */}
Expand All@@ -232,17 +255,20 @@ export const CreateTemplateForm: FC<CreateTemplateFormProps> = (props) => {
)}

{showOrganizationPicker && (
<OrganizationAutocomplete
{...getFieldHelpers("organization")}
required
label="Belongs to"
value={selectedOrg}
onChange={(newValue) => {
setSelectedOrg(newValue);
void form.setFieldValue("organization", newValue?.name || "");
}}
size="medium"
/>
<>
{showProvisionerWarning && <ProvisionerWarning />}
<OrganizationAutocomplete
{...getFieldHelpers("organization")}
required
label="Belongs to"
value={selectedOrg}
onChange={(newValue) => {
setSelectedOrg(newValue);
void form.setFieldValue("organization", newValue?.name || "");
}}
size="medium"
/>
</>
)}

{"copiedTemplate" in props && (
Expand DownExpand Up@@ -369,3 +395,15 @@ const fillNameAndDisplayWithFilename = async (
form.setFieldValue("display_name", capitalize(name)),
]);
};

const ProvisionerWarning: FC = () => {
return (
<Alert severity="warning" css={{ marginBottom: 16 }}>
This organization does not have any provisioners. Before you create a
template, you&apos;ll need to configure a provisioner.{" "}
<Link href={docs("/admin/provisioners#organization-scoped-provisioners")}>
See our documentation.
</Link>
</Alert>
);
};
Loading

[8]ページ先頭

©2009-2025 Movatter.jp