chore: Refactor template update mutations and actions#7386
Merged
Conversation
Contributor
🧪 Review environmenthttps://r7hcc3yikt7rshehwcfiea4f4q0kndqt.lambda-url.ca-central-1.on.aws/ |
…:cds-snc/platform-forms-client into chore/refactor_template_update_mutations
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the template update flow to a single command-based updateTemplate mutation, with shared update command types consumed across the UI/server actions and template persistence layer. It reduces the number of per-field mutation helpers and centralizes authorization, validation, cache invalidation, and audit logging around update operations.
Changes:
- Introduces shared
UpdateTemplateCommand/UpdateTemplateActiontypes and migrates callers to the command-based update surface. - Consolidates multiple template update mutations into
lib/templates/mutations/updateTemplate.tsand removes the old per-field mutation helpers. - Updates form builder UI and server actions to call the unified update path; updates tests accordingly.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/tests/templates.test.ts | Updates tests to use the new command-based updateTemplate calls and updated Prisma update shapes. |
| lib/templates/types.ts | Adds shared command/action types for template updates. |
| lib/templates/mutations/updateTemplate.ts | Refactors mutation into a consolidated command handler with per-action authorization, validation, query building, and audit logging. |
| lib/templates/mutations/updateSecurityAttribute.ts | Removes legacy per-field mutation (replaced by unified update). |
| lib/templates/mutations/updateIsPublishedForTemplate.ts | Removes legacy publish mutation (replaced by unified update). |
| lib/templates/mutations/updateFormSaveAndResume.ts | Removes legacy save/resume mutation (replaced by unified update). |
| lib/templates/mutations/updateFormPurpose.ts | Removes legacy purpose mutation (replaced by unified update). |
| lib/templates/mutations/updateFormBranding.ts | Removes legacy branding mutation (replaced by unified update). |
| lib/templates/mutations/updateClosedData.ts | Removes legacy closed-data mutation (replaced by unified update). |
| components/clientComponents/globals/Header/PublishMenu/PublishButton.tsx | Switches publish/close flows to call the unified updateTemplate action with commands. |
| app/api/templates/[formID]/route.ts | Removes active PUT handler (currently left as commented-out code); keeps GET/DELETE. |
| app/(gcforms)/[locale]/(form administration)/form-builder/actions.ts | Refactors server actions to route multiple update operations through unified command handling. |
| app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/manage/components/close/SetClosingDate.tsx | Updates close-date UI to use unified updateTemplate commands. |
| app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/saveAndResume/SetSaveAndResume.tsx | Updates save/resume UI to use unified updateTemplate commands. |
| app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/FormProfile.tsx | Updates form purpose/security attribute updates to use unified updateTemplate commands. |
| app/(gcforms)/[locale]/(form administration)/form-builder/[id]/settings/components/branding/Branding.tsx | Updates branding updates to use unified updateTemplate commands. |
| app/(gcforms)/[locale]/(form administration)/form-builder/[id]/publish/components/Publish.tsx | Updates publish flow to use unified updateTemplate commands. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
timarney
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary | Résumé
Related: #7336
This PR refactors the template update flow to use a consolidated updateTemplate mutation path with shared command types across the frontend and backend. The goal is to reduce duplicated mutation logic, make the update surface easier to reason about, and improve type safety from the form builder actions all the way through to persistence.
This is part of a broader effort (#7302, #7323) to reduce surface area in the lib/templates module for upcoming Template Versioning work.
What changed
Why
The previous structure spread template update behaviour across several separate mutation helpers, which made the update path harder to maintain and easier to drift out of sync. This refactor makes the mutation flow more consistent, reduces duplication, and gives us stronger compile-time guarantees around the data being sent from the UI to the backend.