META-INF.resources.js.configuration_browse.HighlightedDDMStructuresConfiguration.tsx Maven / Gradle / Ivy
/**
* 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 ClayButton from '@clayui/button';
import {openSelectionModal, sub} from 'frontend-js-web';
import React, {useState} from 'react';
import {StructureList} from './StructureList';
export interface DDMStructure {
ddmStructureId: string;
name: string;
scope: string;
}
interface Props {
ddmStructures?: DDMStructure[];
portletNamespace: string;
selectDDMStructureURL: string;
}
export default function HighlightedDDMStructuresConfiguration({
ddmStructures: initialDDMStructures,
portletNamespace,
selectDDMStructureURL,
}: Props) {
const [ddmStructures, setDDMStructures] = useState(
initialDDMStructures || []
);
const onSelectButtonClick = () =>
openSelectionModal({
multiple: true,
onSelect: (selectedItems: Array<{value: string}>) =>
setDDMStructures((previousDDMStructures) =>
removeDuplicates(
[
...previousDDMStructures,
...selectedItems.map(
itemSelectorValueToDDMStructure
),
],
(ddmStructure) => ddmStructure.ddmStructureId
)
),
title: sub(
Liferay.Language.get('select-x'),
Liferay.Language.get('structures')
),
url: selectDDMStructureURL,
});
return (
{Liferay.Language.get(
'select-the-structures-you-want-to-highlight-in-web-content-administration-to-quickly-access-and-manage-all-its-contents'
)}
ddmStructure.ddmStructureId)
.join(',')}
/>
{Liferay.Language.get('highlighted-structures')}
{Liferay.Language.get('select')}
setDDMStructures(nextStructures)
}
structures={ddmStructures}
/>
);
}
export function itemSelectorValueToDDMStructure(item: {
value: string;
}): DDMStructure {
const parsedValue = JSON.parse(item.value) as {
ddmstructureid: string;
name: string;
scope: string;
};
return {
ddmStructureId: parsedValue.ddmstructureid,
name: parsedValue.name,
scope: parsedValue.scope,
};
}
export function removeDuplicates(
list: T[],
getElementId: (element: T) => string
): T[] {
return list.filter((element, index, array) => {
const elementId = getElementId(element);
return (
index ===
array.findIndex(
(otherElement) => elementId === getElementId(otherElement)
)
);
});
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy