(queryClient: QueryClient)
| 151 | }; |
| 152 | |
| 153 | export const autoCreateWorkspace = (queryClient: QueryClient) => { |
| 154 | return { |
| 155 | mutationFn: async ({ |
| 156 | organizationId, |
| 157 | templateName, |
| 158 | workspaceName, |
| 159 | templateVersionId, |
| 160 | buildParameters, |
| 161 | match, |
| 162 | }: AutoCreateWorkspaceOptions) => { |
| 163 | if (match) { |
| 164 | const matchWorkspace = await findMatchWorkspace( |
| 165 | `owner:me template:${templateName} ${match}`, |
| 166 | ); |
| 167 | if (matchWorkspace) { |
| 168 | return matchWorkspace; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | let templateVersionParameters: Partial<CreateWorkspaceRequest>; |
| 173 | |
| 174 | if (templateVersionId) { |
| 175 | templateVersionParameters = { template_version_id: templateVersionId }; |
| 176 | } else { |
| 177 | const template = await API.getTemplateByName( |
| 178 | organizationId, |
| 179 | templateName, |
| 180 | ); |
| 181 | templateVersionParameters = { template_id: template.id }; |
| 182 | } |
| 183 | |
| 184 | return API.createWorkspace("me", { |
| 185 | ...templateVersionParameters, |
| 186 | name: workspaceName, |
| 187 | rich_parameter_values: buildParameters, |
| 188 | }); |
| 189 | }, |
| 190 | onSuccess: async () => { |
| 191 | await invalidateWorkspaceListQueries(queryClient); |
| 192 | }, |
| 193 | }; |
| 194 | }; |
| 195 | |
| 196 | async function findMatchWorkspace(q: string): Promise<Workspace | undefined> { |
| 197 | try { |
no test coverage detected