Files
faunosteo/apps/app/src/editor/refusal.ts
T

34 lines
952 B
TypeScript

import type { CommitOutcome } from './state/editorTypes'
type Translate = (key: string) => string
const EDIT_KINDS: ReadonlySet<string> = new Set([
'unknown_key',
'duplicate_key',
'invalid_target',
'id_changed',
'invalid_position',
'too_deep',
'has_dependents',
])
/**
* The words for a command that was not kept: the core's closed kind, or the store's
* block. Never the core's detail text (it can echo document content).
*/
export function refusalMessage(
t: Translate,
outcome: Exclude<CommitOutcome, { ok: true }>,
): string {
if (outcome.reason === 'blocked') {
return outcome.kind === 'recovery.pending'
? t('editor.refusal.recovery')
: t('editor.refusal.blocked')
}
if (outcome.reason !== 'core') return t('editor.refusal.blocked')
const { kind } = outcome.failure
return EDIT_KINDS.has(kind)
? t(`editor.refusal.core.${kind}`)
: t('editor.refusal.core.other').replace('{kind}', kind)
}