({
workspacesToUpdate,
isProcessing,
onCancel,
onSubmit,
})
| 323 | }>; |
| 324 | |
| 325 | const ReviewForm: FC<ReviewFormProps> = ({ |
| 326 | workspacesToUpdate, |
| 327 | isProcessing, |
| 328 | onCancel, |
| 329 | onSubmit, |
| 330 | }) => { |
| 331 | const hookId = useId(); |
| 332 | const [stage, setStage] = useState<RisksStage>("notAccepted"); |
| 333 | const risksContainerRef = useRef<HTMLDivElement>(null); |
| 334 | const risksCheckboxRef = useRef<HTMLButtonElement>(null); |
| 335 | |
| 336 | // Dormant workspaces can't be activated without activating them first. For |
| 337 | // now, we'll only show the user that some workspaces can't be updated, and |
| 338 | // then skip over them for all other update logic |
| 339 | const { dormant, noUpdateNeeded, readyToUpdate } = |
| 340 | separateWorkspacesByUpdateType(workspacesToUpdate); |
| 341 | |
| 342 | // The workspaces don't have all necessary data by themselves, so we need to |
| 343 | // fetch the unique template versions, and massage the results |
| 344 | const uniqueTemplateVersionIds = new Set<string>( |
| 345 | readyToUpdate.map((ws) => ws.template_active_version_id), |
| 346 | ); |
| 347 | const templateVersionQueries = useQueries({ |
| 348 | queries: [...uniqueTemplateVersionIds].map((id) => templateVersion(id)), |
| 349 | }); |
| 350 | |
| 351 | // React Query persists previous errors even if a query is no longer in the |
| 352 | // error state, so we need to explicitly check the isError property to see |
| 353 | // if any of the queries actively have an error |
| 354 | const error = templateVersionQueries.find((q) => q.isError)?.error; |
| 355 | |
| 356 | const hasWorkspaces = workspacesToUpdate.length > 0; |
| 357 | const someWorkspacesCanBeUpdated = readyToUpdate.length > 0; |
| 358 | |
| 359 | const formIsNeeded = someWorkspacesCanBeUpdated || dormant.length > 0; |
| 360 | if (!formIsNeeded) { |
| 361 | return ( |
| 362 | <Container> |
| 363 | <ContainerBody |
| 364 | headerText={ |
| 365 | hasWorkspaces |
| 366 | ? "All workspaces up to date" |
| 367 | : "No workspaces selected" |
| 368 | } |
| 369 | showDescription |
| 370 | description={ |
| 371 | hasWorkspaces ? ( |
| 372 | <> |
| 373 | None of the{" "} |
| 374 | <span className="text-content-primary font-semibold"> |
| 375 | {workspacesToUpdate.length} |
| 376 | </span>{" "} |
| 377 | selected workspaces need updates. |
| 378 | </> |
| 379 | ) : ( |
| 380 | "Nothing to update." |
| 381 | ) |
| 382 | } |
nothing calls this directly
no test coverage detected