- admin-i18n module: AdminText { en, pl }, component texts under the ipal
namespace (project translations win), en + pl admin languages when the
project sets none (project's supportedLanguages wins)
- every plugin label, description, option, tab and group as { en, pl };
explicit labels instead of auto-labels; sentence case; glossary terms
- visible renames (slugs, names, data unchanged): Cookie banner, Form
messages, Privacy group, Search engines, Maintenance, Spam protection,
E-mail sending, stats nav link Overview (hidden without access)
- Polish visitor defaults by page locale: cookie banner, form messages,
validators, lightbox, accessibility widget; {field} uses the label
- fixes: e-mail status banner used Turnstile wording; developer words and
env var names out of editor messages; stats numbers/dates in the admin
language; test e-mail no longer says ipal-kit
- test/adminUx.test.ts: length limits, en + pl present, no developer words
Co-Authored-By: Claude Opus 5.5 <[email protected]>
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
'use client'
|
|
import { useRowLabel, useTranslation } from '@payloadcms/ui'
|
|
|
|
import type { AdminText } from '../admin-i18n/define.js'
|
|
|
|
import { ipalT } from '../admin-i18n/t.js'
|
|
|
|
export type RowLabelProps = {
|
|
/**
|
|
* Shown with the row number when every path is empty, e.g. "Button" → "Button 02".
|
|
* A string or `{ en, pl }`; default "Item" in the admin language.
|
|
*/
|
|
fallback?: AdminText | Record<string, string> | string
|
|
/** Dot paths inside the row, tried in order — the first non-empty text wins. */
|
|
fields?: string[]
|
|
}
|
|
|
|
const at = (obj: unknown, path: string): unknown =>
|
|
path.split('.').reduce<unknown>((o, k) => (o && typeof o === 'object' ? (o as Record<string, unknown>)[k] : undefined), obj)
|
|
|
|
const toText = (v: unknown): string => {
|
|
if (typeof v === 'string') {return v.trim()}
|
|
if (typeof v === 'number') {return String(v)}
|
|
// populated relationship / upload → its title, name, filename or alt
|
|
if (v && typeof v === 'object') {
|
|
for (const k of ['title', 'name', 'label', 'alt', 'filename']) {
|
|
const t = (v as Record<string, unknown>)[k]
|
|
if (typeof t === 'string' && t.trim()) {return t.trim()}
|
|
}
|
|
}
|
|
return ''
|
|
}
|
|
|
|
/**
|
|
* Array row title in the admin panel: shows the row's own content ("Contact us",
|
|
* "Fast delivery") instead of "Item 01", so an editor finds the right row
|
|
* without expanding every one. Wire it with `rowLabel()`.
|
|
*/
|
|
export function RowLabel({ fallback, fields = ['heading', 'title', 'label', 'link.label', 'name'] }: RowLabelProps) {
|
|
const { data, rowNumber } = useRowLabel<Record<string, unknown>>()
|
|
const { i18n, t } = useTranslation()
|
|
for (const f of fields) {
|
|
const text = toText(at(data, f))
|
|
if (text) {return <span>{text.length > 60 ? `${text.slice(0, 57)}…` : text}</span>}
|
|
}
|
|
const name =
|
|
typeof fallback === 'string'
|
|
? fallback
|
|
: fallback
|
|
? ((fallback as Record<string, string>)[i18n.language] ?? fallback.en ?? Object.values(fallback)[0])
|
|
: ipalT(t, 'rowLabelItem')
|
|
return <span>{`${name} ${String((rowNumber ?? 0) + 1).padStart(2, '0')}`}</span>
|
|
}
|