You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
816 B
JavaScript
20 lines
816 B
JavaScript
const COPY_KEY_PATTERN = /^common\.operation\.(?:kind|action|setting)\.[a-z0-9_]+$/;
|
|
|
|
/** Render a user-facing operation title exclusively from stable copy keys. */
|
|
export function operationTitle(entry, text, fallbackKey) {
|
|
const translate = typeof text === 'function' ? text : () => '';
|
|
const keys = Array.isArray(entry?.operation_copy_keys)
|
|
? entry.operation_copy_keys.filter(key => (
|
|
typeof key === 'string' && COPY_KEY_PATTERN.test(key)
|
|
)) : [];
|
|
const labels = keys.map(key => String(translate(key) || '').trim())
|
|
.filter((label, index) => label && label !== keys[index]);
|
|
if (labels.length) {
|
|
const separator = String(
|
|
translate('common.operation.list_separator') || ', ',
|
|
);
|
|
return labels.join(separator);
|
|
}
|
|
return String(translate(fallbackKey) || '').trim();
|
|
}
|