Documented Mutations
Migrate a useMutation hook to useDocumentedMutation. Copy shape from a migrated example (e.g. react-api-client/src/runs/usePlayRunMutation.ts).
Before coding
Prompt the user for an audit log key and text. Do not invent either. Then add:
- Key to
AuditLogActioninreact-api-client/src/accessControl/types.ts "key": "text"inapp/src/assets/localization/en/audit_log.jsononly (neverzh/)
Hook (react-api-client)
- Replace
useMutationwithuseDocumentedMutationfrom../accessControl. - Require
documentationState: DocumentationStateas the first arg. - Pass
actionsToDocumentas['audit_log_key']. - Mutation fn must take
{ variables, userNotes }(DocumentedMutationParameters) and forwarduserNotesto the api-client call. - Ensure the api-client function accepts/sends
userNotesif it does not already.
Callsites (app/)
- Flex / shared / ODD: pass
useDocumentationState()(or an existing docs state). - OT-2 only callsites do not need to be updated and should be passed
ACCESS_CONTROL_DISABLED_DOCUMENTATION_STATEfromapp/src/local-resources/access-control/utils.ts. - Docs modal cancel: on isDocumentedMutationError, stay on the screen that launched the mutation (confirm modal, wizard step, etc.). Reset any in-flight UI; do not toast, navigate away, or apply mutation success side effects.
Tests — update with proper mocks
- Hook tests: pass
ACCESS_CONTROL_DISABLED_DOCUMENTATION_STATEfromreact-api-client/src/accessControl/__fixtures__/documentationState. - App tests: mock
useDocumentationState(or pass the fixture) usingACCESS_CONTROL_DISABLED_DOCUMENTATION_STATEfromapp/src/local-resources/access-control/__fixtures__/documentationState. - Keep api-client /
useHostmocks; assertuserNotesis forwarded when relevant. - Do not add any new test files.
Checklist
- User supplied audit log key + English text
-
AuditLogAction+en/audit_log.jsonupdated - Hook uses
useDocumentedMutation+userNotes - api-client accepts
userNotes - Non-OT2 callsites get real docs state; OT2-only get disabled constant
- Docs cancel restores prior screen with no changes / no user-facing error
- Hook + app tests updated with proper mocks/fixtures