feat(cms): copyable legal validation prompt in the legal page editor (MITHOME-113)
buildLegalValidationPrompt() is the single review template: the criteria (meaning, GDPR terminology, obligation strength, preserved markers, clarity), a severity table output with a final verdict, and the Hungarian/English text of every section paired by id, missing English flagged as high severity. The legal page sidebar shows it through the LegalValidationPrompt UI field (hu + en read from REST with draft=true and no locale fallback) with copy and refresh buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
329e2e3403
commit
acd1ff2ed9
@@ -1,8 +1,10 @@
|
||||
import { LegalValidationPrompt as LegalValidationPrompt_a8cca93565d7d00e7e22c4fe1497b43d } from '../../../../src/components/admin/LegalValidationPrompt'
|
||||
import { QuickSearch as QuickSearch_899db48c9ce30e524aae8643dea53f6d } from '../../../../src/components/admin/QuickSearch'
|
||||
import { CollectionCards as CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1 } from '@payloadcms/next/rsc'
|
||||
|
||||
/** @type import('payload').ImportMap */
|
||||
export const importMap = {
|
||||
"./src/components/admin/LegalValidationPrompt#LegalValidationPrompt": LegalValidationPrompt_a8cca93565d7d00e7e22c4fe1497b43d,
|
||||
"./src/components/admin/QuickSearch#QuickSearch": QuickSearch_899db48c9ce30e524aae8643dea53f6d,
|
||||
"@payloadcms/next/rsc#CollectionCards": CollectionCards_f9c02e79a4aed9a3924487c0cd4cafb1
|
||||
}
|
||||
|
||||
@@ -76,5 +76,14 @@ export const LegalPages: CollectionConfig = {
|
||||
{ name: 'reportRef', label: 'Validációs riport (hivatkozás)', type: 'text' },
|
||||
],
|
||||
},
|
||||
{
|
||||
// MITHOME-113 (D8): copyable review prompt built from the saved hu + en texts.
|
||||
name: 'validationPrompt',
|
||||
type: 'ui',
|
||||
admin: {
|
||||
position: 'sidebar',
|
||||
components: { Field: './src/components/admin/LegalValidationPrompt#LegalValidationPrompt' },
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { buildLegalValidationPrompt, type LegalText } from '@/lib/legal-validation-prompt'
|
||||
|
||||
/**
|
||||
* MITHOME-113 (design D8) — "Validation prompt" panel in the legal page
|
||||
* editor sidebar: a ready-to-copy prompt for reviewing the English
|
||||
* translation with a high-capability model. The prompt comes from the same
|
||||
* template the project's own validation uses (src/lib/legal-validation-prompt.ts).
|
||||
*
|
||||
* WHY REST reads instead of the form state: the edit form holds one locale
|
||||
* at a time; the prompt needs both. `draft=true` reads the latest saved
|
||||
* version, `fallback-locale=none` keeps missing English empty instead of
|
||||
* silently showing Hungarian as "English".
|
||||
* WHY the id comes from the URL: avoids adding @payloadcms/ui as a direct
|
||||
* dependency just for useDocumentInfo (same approach as QuickSearch).
|
||||
*/
|
||||
|
||||
type State =
|
||||
| { kind: 'loading' }
|
||||
| { kind: 'unsaved' }
|
||||
| { kind: 'error'; message: string }
|
||||
| { kind: 'empty' }
|
||||
| { kind: 'ready'; prompt: string }
|
||||
|
||||
function docIdFromPath(pathname: string): string | undefined {
|
||||
const id = pathname.match(/\/collections\/legal-pages\/([^/?#]+)/)?.[1]
|
||||
return id && id !== 'create' ? id : undefined
|
||||
}
|
||||
|
||||
async function readLocale(id: string, locale: 'hu' | 'en'): Promise<LegalText> {
|
||||
const res = await fetch(`/api/legal-pages/${id}?locale=${locale}&fallback-locale=none&draft=true&depth=0`, {
|
||||
credentials: 'include',
|
||||
})
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`)
|
||||
return res.json()
|
||||
}
|
||||
|
||||
async function fetchPromptState(): Promise<State> {
|
||||
const id = docIdFromPath(window.location.pathname)
|
||||
if (!id) return { kind: 'unsaved' }
|
||||
try {
|
||||
const [hu, en] = await Promise.all([readLocale(id, 'hu'), readLocale(id, 'en')])
|
||||
const prompt = buildLegalValidationPrompt(hu, en)
|
||||
return prompt ? { kind: 'ready', prompt } : { kind: 'empty' }
|
||||
} catch (error) {
|
||||
return { kind: 'error', message: error instanceof Error ? error.message : String(error) }
|
||||
}
|
||||
}
|
||||
|
||||
export function LegalValidationPrompt() {
|
||||
const [state, setState] = useState<State>({ kind: 'loading' })
|
||||
const [copied, setCopied] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
let active = true
|
||||
void fetchPromptState().then((next) => active && setState(next))
|
||||
return () => {
|
||||
active = false
|
||||
}
|
||||
}, [])
|
||||
|
||||
const reload = () => {
|
||||
setState({ kind: 'loading' })
|
||||
void fetchPromptState().then(setState)
|
||||
}
|
||||
|
||||
const copy = async (prompt: string) => {
|
||||
await navigator.clipboard.writeText(prompt)
|
||||
setCopied(true)
|
||||
setTimeout(() => setCopied(false), 2000)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field-type" style={{ marginBottom: 'var(--base)' }}>
|
||||
<label className="field-label">Validációs prompt (angol fordítás)</label>
|
||||
<p style={{ color: 'var(--theme-elevation-500)', fontSize: '0.8rem', margin: '0 0 0.5rem' }}>
|
||||
Másold be egy magas szintű modellbe (legalább kettőbe, egymástól függetlenül), majd rögzítsd az eredményt a
|
||||
„Jogi validáció” mezőkben. A prompt a legutóbb mentett változatból készül.
|
||||
</p>
|
||||
{state.kind === 'loading' && <p>Betöltés…</p>}
|
||||
{state.kind === 'unsaved' && <p>Előbb mentsd el a dokumentumot.</p>}
|
||||
{state.kind === 'empty' && <p>Még nincs angol szöveg — nincs mit validálni.</p>}
|
||||
{state.kind === 'error' && <p role="alert">A prompt nem tölthető be ({state.message}).</p>}
|
||||
{state.kind === 'ready' && (
|
||||
<>
|
||||
<textarea
|
||||
readOnly
|
||||
value={state.prompt}
|
||||
rows={8}
|
||||
aria-label="Validációs prompt"
|
||||
style={{ width: '100%', fontFamily: 'monospace', fontSize: '0.75rem' }}
|
||||
/>
|
||||
<button type="button" className="btn btn--style-primary btn--size-small" onClick={() => void copy(state.prompt)}>
|
||||
{copied ? 'Másolva ✓' : 'Prompt másolása'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<button type="button" className="btn btn--style-secondary btn--size-small" onClick={reload}>
|
||||
Frissítés
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { buildLegalValidationPrompt, hasEnglishContent } from './legal-validation-prompt'
|
||||
|
||||
const hu = {
|
||||
title: 'Adatvédelmi Tájékoztató',
|
||||
lastUpdated: '2026. augusztus 22.',
|
||||
sections: [
|
||||
{ id: 'bevezetes', title: '1. Bevezetés', content: 'A mozdIT Bt. mint adatkezelő…' },
|
||||
{ id: 'jogok', title: '5. Az érintettek jogai', content: 'Az érintettek bármikor…' },
|
||||
],
|
||||
}
|
||||
const en = {
|
||||
title: 'Privacy Notice',
|
||||
lastUpdated: '22 August 2026',
|
||||
sections: [{ id: 'bevezetes', title: '1. Introduction', content: 'mozdIT Bt., as controller…' }],
|
||||
}
|
||||
|
||||
describe('buildLegalValidationPrompt (MITHOME-113)', () => {
|
||||
const prompt = buildLegalValidationPrompt(hu, en)!
|
||||
|
||||
it('should include every review criterion and the output format', () => {
|
||||
for (const text of ['Meaning equivalence', 'GDPR', 'Strength of obligations', 'placeholders', 'Severity (high / medium / low)', 'APPROVE WITH CHANGES', 'not legal advice']) {
|
||||
expect(prompt).toContain(text)
|
||||
}
|
||||
})
|
||||
|
||||
it('should pair every Hungarian section with its English section by id', () => {
|
||||
expect(prompt).toContain('--- Section 1 (bevezetes) ---\n[HU] 1. Bevezetés\nA mozdIT Bt. mint adatkezelő…\n[EN] 1. Introduction\nmozdIT Bt., as controller…')
|
||||
expect(prompt).toContain('Document (EN): Privacy Notice')
|
||||
})
|
||||
|
||||
it('should flag a missing English section as high severity', () => {
|
||||
expect(prompt).toContain('--- Section 2 (jogok) ---')
|
||||
expect(prompt).toMatch(/\[EN\] \(missing — report as high severity\)\n\(missing — report as high severity\)$/)
|
||||
})
|
||||
|
||||
it('should return undefined when there is no English text', () => {
|
||||
expect(buildLegalValidationPrompt(hu, { title: ' ', sections: [{ id: 'bevezetes', title: null, content: '' }] })).toBeUndefined()
|
||||
expect(hasEnglishContent({})).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* MITHOME-113 (design D8): the single template for validating the English
|
||||
* translation of a legal page. Used both by the admin "Validation prompt"
|
||||
* panel (src/components/admin/LegalValidationPrompt.tsx) and by the
|
||||
* project's own multi-model validation, so the two are comparable.
|
||||
*
|
||||
* WHY in code, not in the CMS: the review criteria are a quality rule, not
|
||||
* page content — changes must go through git review so they cannot be
|
||||
* weakened by accident.
|
||||
* WHY English: the most stable instruction language across models; the
|
||||
* document texts stay in their original languages.
|
||||
*/
|
||||
|
||||
export type LegalSection = { id?: string | null; title?: string | null; content?: string | null }
|
||||
export type LegalText = { title?: string | null; lastUpdated?: string | null; sections?: LegalSection[] | null }
|
||||
|
||||
const MISSING = '(missing — report as high severity)'
|
||||
|
||||
const INSTRUCTIONS = `You are reviewing the English translation of a Hungarian legal document published on the website of mozdIT Bt., a Hungarian IT hosting provider. The Hungarian text is authoritative.
|
||||
|
||||
Check every section for:
|
||||
1. Meaning equivalence — nothing added, omitted or changed: same scope, conditions, numbers, deadlines and retention periods.
|
||||
2. Data-protection terminology consistent with the official English text of the GDPR (e.g. controller, processor, data subject, legal basis, legitimate interest, erasure, restriction of processing) and correct English names of Hungarian authorities and laws.
|
||||
3. Strength of obligations and rights — "shall", "must", "may", "is entitled to" must match the Hungarian.
|
||||
4. Preserved placeholders, e-mail addresses, URLs and formatting markers (**bold**, "•" bullets, line breaks).
|
||||
5. Clarity for an English-speaking reader without changing the legal meaning.
|
||||
|
||||
Output format:
|
||||
- A table with the columns: Section | Severity (high / medium / low) | Issue | Hungarian excerpt | Suggested English wording.
|
||||
High = changes a legal meaning, right or obligation; medium = terminology or ambiguity; low = style.
|
||||
- Then a final verdict — APPROVE, APPROVE WITH CHANGES or REJECT — with a one-sentence justification.
|
||||
Do not rewrite the whole document. Note that this review is not legal advice.`
|
||||
|
||||
const hasText = (value?: string | null) => Boolean(value?.trim())
|
||||
|
||||
export function hasEnglishContent(en: LegalText): boolean {
|
||||
return hasText(en.title) || (en.sections ?? []).some((s) => hasText(s.title) || hasText(s.content))
|
||||
}
|
||||
|
||||
function block(label: string, title?: string | null, content?: string | null) {
|
||||
return `[${label}] ${hasText(title) ? title : MISSING}\n${hasText(content) ? content : MISSING}`
|
||||
}
|
||||
|
||||
/** The review prompt, or undefined when there is no English text to validate. */
|
||||
export function buildLegalValidationPrompt(hu: LegalText, en: LegalText): string | undefined {
|
||||
if (!hasEnglishContent(en)) return undefined
|
||||
const enById = new Map((en.sections ?? []).map((s) => [s.id, s]))
|
||||
|
||||
const header = [
|
||||
`Document (HU): ${hu.title ?? ''}`,
|
||||
`Document (EN): ${hasText(en.title) ? en.title : MISSING}`,
|
||||
`Last updated (HU / EN): ${hu.lastUpdated ?? ''} / ${hasText(en.lastUpdated) ? en.lastUpdated : MISSING}`,
|
||||
].join('\n')
|
||||
|
||||
const sections = (hu.sections ?? []).map((section, index) => {
|
||||
const english = enById.get(section.id) ?? {}
|
||||
return [
|
||||
`--- Section ${index + 1}${section.id ? ` (${section.id})` : ''} ---`,
|
||||
block('HU', section.title, section.content),
|
||||
block('EN', english.title, english.content),
|
||||
].join('\n')
|
||||
})
|
||||
|
||||
return [INSTRUCTIONS, header, ...sections].join('\n\n')
|
||||
}
|
||||
Reference in New Issue
Block a user