Files
klz-cables.com/.pnpm-store/v10/files/55/d31c1a9e00502c3fe10b248e03d92368dd96bbc6ff7f597c301a2e816d6244f709f943a9e5e1a823f12dae2842d76209b3bda55f12bbf5dae11fd0302d4f6f
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

28 lines
1.3 KiB
Plaintext

import { getTranslation } from '@payloadcms/translations';
import { isValidReactElement } from './isValidReactElement.js';
/**
* Returns the appropriate display value for a field.
* - For select and radio fields:
* - Returns JSX elements as-is.
* - Translates localized label objects based on the current language.
* - Returns string labels directly.
* - Falls back to the option value if no valid label is found.
* - For all other field types, returns `cellData` unchanged.
*/
export const getDisplayedFieldValue = (cellData, field, i18n) => {
if ((field?.type === 'select' || field?.type === 'radio') && Array.isArray(field.options)) {
const selectedOption = field.options.find(opt => typeof opt === 'object' ? opt.value === cellData : opt === cellData);
if (selectedOption) {
if (typeof selectedOption === 'object' && 'label' in selectedOption) {
return isValidReactElement(selectedOption.label) ? selectedOption.label // Return JSX directly
: getTranslation(selectedOption.label, i18n) || selectedOption.value // Use translation or fallback to value
;
}
return selectedOption // If option is a string, return it directly
;
}
}
return cellData // Default fallback if no match found
;
};
//# sourceMappingURL=getDisplayedFieldValue.js.map