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

META-INF.resources.js.components.Scope.js 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 ClayForm, {ClaySelect} from '@clayui/form';
import {fetch} from 'frontend-js-web';
import React, {useEffect, useState} from 'react';

import {HEADLESS_BATCH_PLANNER_URL, SCHEMA_SELECTED_EVENT} from '../constants';

function Scope({portletNamespace}) {
	const [scopes, setScopes] = useState([]);

	useEffect(() => {
		const handleSchemaUpdated = (event) => {
			if (event.schemaName) {
				fetch(
					`${HEADLESS_BATCH_PLANNER_URL}/plans/${event.schemaName.replace(
						'#',
						encodeURIComponent('#')
					)}/site-scopes?export=${event.isExport}`
				)
					.then((response) => response.json())
					.then((json) => {
						setScopes(json.items);
					});
			}
			else {
				setScopes([]);
			}
		};

		Liferay.on(SCHEMA_SELECTED_EVENT, handleSchemaUpdated);

		return () => {
			Liferay.detach(SCHEMA_SELECTED_EVENT, handleSchemaUpdated);
		};
	}, []);

	const selectId = `${portletNamespace}siteId`;

	return (
		!!scopes.length && (
			
				

				
					{scopes.map((scope) => (
						
					))}
				
			
		)
	);
}

export default Scope;




© 2015 - 2025 Weber Informatics LLC | Privacy Policy