mirror of
https://github.com/coder/coder.git
synced 2026-10-25 09:42:55 +08:00
chore(coderd): allow creating workspaces without specifying an organization (#14048)
This commit is contained in:
+1
-2
@@ -1019,12 +1019,11 @@ class ApiMethods {
|
||||
};
|
||||
|
||||
createWorkspace = async (
|
||||
organizationId: string,
|
||||
userId = "me",
|
||||
workspace: TypesGen.CreateWorkspaceRequest,
|
||||
): Promise<TypesGen.Workspace> => {
|
||||
const response = await this.axios.post<TypesGen.Workspace>(
|
||||
`/api/v2/organizations/${organizationId}/members/${userId}/workspaces`,
|
||||
`/api/v2/users/${userId}/workspaces`,
|
||||
workspace,
|
||||
);
|
||||
|
||||
|
||||
@@ -13,20 +13,20 @@ import type {
|
||||
import { delay } from "utils/delay";
|
||||
import { getTemplateVersionFiles } from "utils/templateVersion";
|
||||
|
||||
export const templateByNameKey = (organizationId: string, name: string) => [
|
||||
organizationId,
|
||||
export const templateByNameKey = (organization: string, name: string) => [
|
||||
organization,
|
||||
"template",
|
||||
name,
|
||||
"settings",
|
||||
];
|
||||
|
||||
export const templateByName = (
|
||||
organizationId: string,
|
||||
organization: string,
|
||||
name: string,
|
||||
): QueryOptions<Template> => {
|
||||
return {
|
||||
queryKey: templateByNameKey(organizationId, name),
|
||||
queryFn: async () => API.getTemplateByName(organizationId, name),
|
||||
queryKey: templateByNameKey(organization, name),
|
||||
queryFn: async () => API.getTemplateByName(organization, name),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -39,14 +39,13 @@ export const workspaceByOwnerAndName = (owner: string, name: string) => {
|
||||
|
||||
type CreateWorkspaceMutationVariables = CreateWorkspaceRequest & {
|
||||
userId: string;
|
||||
organizationId: string;
|
||||
};
|
||||
|
||||
export const createWorkspace = (queryClient: QueryClient) => {
|
||||
return {
|
||||
mutationFn: async (variables: CreateWorkspaceMutationVariables) => {
|
||||
const { userId, organizationId, ...req } = variables;
|
||||
return API.createWorkspace(organizationId, userId, req);
|
||||
const { userId, ...req } = variables;
|
||||
return API.createWorkspace(userId, req);
|
||||
},
|
||||
onSuccess: async () => {
|
||||
await queryClient.invalidateQueries(["workspaces"]);
|
||||
@@ -101,7 +100,7 @@ export const autoCreateWorkspace = (queryClient: QueryClient) => {
|
||||
templateVersionParameters = { template_id: template.id };
|
||||
}
|
||||
|
||||
return API.createWorkspace(organizationId, "me", {
|
||||
return API.createWorkspace("me", {
|
||||
...templateVersionParameters,
|
||||
name: workspaceName,
|
||||
rich_parameter_values: buildParameters,
|
||||
|
||||
@@ -59,7 +59,6 @@ describe("CreateWorkspacePage", () => {
|
||||
|
||||
await waitFor(() =>
|
||||
expect(API.createWorkspace).toBeCalledWith(
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
MockUser.id,
|
||||
expect.objectContaining({
|
||||
...MockWorkspaceRichParametersRequest,
|
||||
@@ -223,7 +222,6 @@ describe("CreateWorkspacePage", () => {
|
||||
|
||||
await waitFor(() =>
|
||||
expect(API.createWorkspace).toBeCalledWith(
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
MockUser.id,
|
||||
expect.objectContaining({
|
||||
...MockWorkspaceRequest,
|
||||
@@ -263,7 +261,6 @@ describe("CreateWorkspacePage", () => {
|
||||
|
||||
await waitFor(() =>
|
||||
expect(API.createWorkspace).toBeCalledWith(
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
MockUser.id,
|
||||
expect.objectContaining({
|
||||
...MockWorkspaceRequest,
|
||||
@@ -287,7 +284,6 @@ describe("CreateWorkspacePage", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(createWorkspaceSpy).toBeCalledWith(
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
"me",
|
||||
expect.objectContaining({
|
||||
template_version_id: MockTemplate.active_version_id,
|
||||
@@ -347,7 +343,6 @@ describe("CreateWorkspacePage", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(createWorkspaceSpy).toBeCalledWith(
|
||||
"00000000-0000-0000-0000-000000000000",
|
||||
"me",
|
||||
expect.objectContaining({
|
||||
template_version_id: MockTemplate.active_version_id,
|
||||
|
||||
@@ -33,7 +33,9 @@ export type CreateWorkspaceMode = (typeof createWorkspaceModes)[number];
|
||||
export type ExternalAuthPollingState = "idle" | "polling" | "abandoned";
|
||||
|
||||
const CreateWorkspacePage: FC = () => {
|
||||
const { template: templateName } = useParams() as { template: string };
|
||||
const { template: templateName } = useParams() as {
|
||||
template: string;
|
||||
};
|
||||
const { user: me } = useAuthenticated();
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
@@ -115,8 +117,8 @@ const CreateWorkspacePage: FC = () => {
|
||||
try {
|
||||
autoCreationStartedRef.current = true;
|
||||
const newWorkspace = await autoCreateWorkspaceMutation.mutateAsync({
|
||||
templateName,
|
||||
organizationId,
|
||||
templateName,
|
||||
buildParameters: autofillParameters,
|
||||
workspaceName: defaultName ?? generateWorkspaceName(),
|
||||
templateVersionId: realizedVersionId,
|
||||
@@ -214,7 +216,6 @@ const CreateWorkspacePage: FC = () => {
|
||||
const workspace = await createWorkspaceMutation.mutateAsync({
|
||||
...request,
|
||||
userId: owner.id,
|
||||
organizationId,
|
||||
});
|
||||
onCreateWorkspace(workspace);
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user