feat(schema-workflow): PATCH /drafts/{id} — edit без recreate (A)

This commit is contained in:
Александр Зимин
2026-05-12 11:33:01 +00:00
parent ab6ec6ebec
commit b3a9104d54
11 changed files with 323 additions and 51 deletions
+13
View File
@@ -496,6 +496,7 @@ export type ChangelogKind =
| 'definition_create'
| 'definition_update'
| 'draft_create'
| 'draft_update'
| 'draft_review'
| 'draft_approve'
| 'draft_reject'
@@ -602,6 +603,18 @@ export type CreateSchemaDraftRequest = {
proposedSchema: unknown
}
/**
* Partial update existing draft без recreate. Status-gate enforced
* backend'ом: только DRAFT и CHANGES_REQUESTED. CHANGES_REQUESTED →
* DRAFT auto-transition после update (maker должен ре-submit).
*/
export type UpdateSchemaDraftRequest = {
/** Replacement JSON Schema (full document). undefined = не меняем. */
proposedSchema?: unknown
/** Новая maker rationale. undefined = не меняем. */
reason?: string
}
export type SubmitForReviewRequest = {
/** Optional explicit reviewer IDs. NULL/[] = pool. */
reviewers?: string[] | null
+30
View File
@@ -18,6 +18,7 @@ import {
type SchemaDraft,
type SubmitDraftRequest,
type SubmitForReviewRequest,
type UpdateSchemaDraftRequest,
type WebhookDelivery,
type WebhookSubscription,
type WebhookTestPingResult,
@@ -514,6 +515,35 @@ export const useCreateSchemaDraft = (dictionaryName: string) => {
})
}
/**
* Update content (proposedSchema / reason) в существующем draft'е без
* recreate. Status-gate: только DRAFT и CHANGES_REQUESTED. Backend
* автоматически переводит CHANGES_REQUESTED → DRAFT после update
* (maker должен ре-submit на ревью осознанно).
*/
export const useUpdateSchemaDraft = (dictionaryName: string) => {
const qc = useQueryClient()
return useMutation({
mutationFn: async (params: {
draftId: string
body: UpdateSchemaDraftRequest
}): Promise<SchemaDraft> => {
const { data } = await apiClient.patch<SchemaDraft>(
`/dictionaries/${dictionaryName}/drafts/${params.draftId}`,
params.body,
)
return data
},
onSuccess: () => {
qc.invalidateQueries({ queryKey: ['schema-draft-active', dictionaryName] })
qc.invalidateQueries({ queryKey: ['schema-draft', dictionaryName] })
qc.invalidateQueries({ queryKey: ['schema-drafts', dictionaryName] })
qc.invalidateQueries({ queryKey: ['schema-review-queue'] })
qc.invalidateQueries({ queryKey: ['changelog', dictionaryName] })
},
})
}
/** Maker submits draft → review_pending. 202 Accepted. */
export const useSubmitSchemaDraftForReview = (dictionaryName: string) => {
const qc = useQueryClient()