fix(ui): edit-форма уважает as-of таймлайна (не now)

This commit is contained in:
Александр Зимин
2026-06-22 09:39:16 +00:00
parent 0c1cc385de
commit ac5eb53617
2 changed files with 19 additions and 4 deletions
+15 -3
View File
@@ -316,12 +316,23 @@ export const mySchemaDraftsQuery = (page = 0, size = 50) =>
export const useMySchemaDrafts = (page = 0, size = 50) =>
useQuery(mySchemaDraftsQuery(page, size))
export const recordRawQuery = (dictionaryName: string, businessKey: string) =>
export const recordRawQuery = (
dictionaryName: string,
businessKey: string,
at?: string,
) =>
queryOptions({
queryKey: ['record-raw', dictionaryName, businessKey] as const,
// at в queryKey — иначе time-travel snapshot закешируется под тем же ключом
// что и now-версия, и при смене as-of вернётся stale.
queryKey: ['record-raw', dictionaryName, businessKey, at ?? null] as const,
queryFn: async (): Promise<RecordResponse> => {
const { data } = await apiClient.get<RecordResponse>(
`/dictionaries/${dictionaryName}/records/${encodeURIComponent(businessKey)}`,
// at пробрасываем в backend (GET принимает ?at=) — резолв активной
// версии на момент таймлайна, а не на now. Без этого открытие записи
// в time-travel режиме бьёт now → RECORD_NOT_ACTIVE для записей,
// закрытых между as-of и now.
at ? { params: { at } } : undefined,
)
return data
},
@@ -948,9 +959,10 @@ export const useAiFeatureAvailable = () => useQuery(aiFeatureAvailableQuery)
export const useRecordRaw = (
dictionaryName: string,
businessKey: string | undefined,
at?: string,
) =>
useQuery({
...recordRawQuery(dictionaryName, businessKey ?? ''),
...recordRawQuery(dictionaryName, businessKey ?? '', at),
enabled: Boolean(businessKey),
})
@@ -659,7 +659,10 @@ function DictionaryDetail() {
}, [extraColumns, t])
const editingKey = edit.kind === 'edit' ? edit.record.businessKey : undefined
const rawRecordQuery = useRecordRaw(name, editingKey)
// timeTravelAt пробрасываем: в time-travel режиме edit-форма должна
// резолвить запись на момент таймлайна, а не на now (иначе закрытая между
// as-of и now запись → RECORD_NOT_ACTIVE).
const rawRecordQuery = useRecordRaw(name, editingKey, timeTravelAt)
const handleSubmit = (req: CreateRecordRequest) => {
// Fill validFrom at submit (review #5): defaultValues в RHF берётся