META-INF.resources.js.fragment-collection-preview.FragmentPreview.js Maven / Gradle / Ivy
The newest version!
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
import React, {useMemo} from 'react';
import {VariationPreview} from './VariationPreview';
import {combine} from './combine';
export function FragmentPreview({fragment, namespace}) {
const variations = useMemo(
() => getFragmentVariations(fragment),
[fragment]
);
return (
{fragment.label}
{variations.length ? (
variations.map((variation) => {
const label = `${fragment.label} ${variation
.map((part) => part.label)
.join(' ')}`;
return (
1}
variation={variation}
/>
);
})
) : (
)}
);
}
function getFragmentVariations(fragment) {
const configurationValues =
fragment.configuration.fieldSets?.flatMap((fieldSet) =>
fieldSet.fields
.filter(
(field) =>
field.type === 'select' &&
Array.isArray(field.typeOptions?.validValues)
)
.map((field) =>
field.typeOptions.validValues.map((validValue) => ({
label: validValue.label || validValue.value,
name: field.name,
value: validValue.value,
}))
)
) || [];
return combine(...configurationValues);
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy