All Downloads are FREE. Search and download functionalities are using the official Maven repository.

META-INF.resources.js.ContributedFragmentEntryDropdownPropsTransformer.js Maven / Gradle / Ivy

There is a newer version: 4.0.119
Show 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 {render} from '@liferay/frontend-js-react-web';

import CopyFragmentModal from './CopyFragmentModal';

const ACTIONS = {
	copyContributedEntryToFragmentCollection(
		itemData,
		portletNamespace,
		fragmentCollections
	) {
		render(
			CopyFragmentModal,
			{
				addFragmentCollectionURL: itemData.addFragmentCollectionURL,
				contributedEntryKeys: [itemData.contributedEntryKey],
				copyFragmentEntriesURL: itemData.copyContributedEntryURL,
				fragmentCollections,
				portletNamespace,
			},
			document.createElement('div')
		);
	},
};

export default function propsTransformer({
	actions,
	additionalProps: {fragmentCollections},
	portletNamespace,
	...props
}) {
	const transformAction = (actionItem) => {
		if (actionItem.type === 'group') {
			return {
				...actionItem,
				items: actionItem.items?.map(transformAction),
			};
		}

		return {
			...actionItem,
			onClick(event) {
				const action = actionItem.data?.action;

				if (action) {
					event.preventDefault();

					ACTIONS[action](
						actionItem.data,
						portletNamespace,
						fragmentCollections
					);
				}
			},
		};
	};

	return {
		...props,
		actions: (actions || []).map(transformAction),
	};
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy