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

META-INF.resources.js.components.ModalImport.ModalImportFailed.tsx Maven / Gradle / Ivy

The newest version!
/**
 * SPDX-FileCopyrightText: (c) 2024 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 {Body, Cell, Head, Row, Table, Text} from '@clayui/core';
import ClayIcon from '@clayui/icon';
import ClayLoadingIndicator from '@clayui/loading-indicator';
import ClayModal from '@clayui/modal';
import {API, errorsUtils, stringUtils} from '@liferay/object-js-components-web';
import React, {useEffect, useState} from 'react';

import './ModalImportFailed.scss';

interface ModalImportFailedProps {
	error: API.ErrorDetails;
	handleOnclose: () => void;
	importedObjectDefinitions: ObjectDefinition[];
}

type ImportedObjectDefinitionsStatus = {
	errorType?: string;
	label: string;
	success: boolean;
};

type FailedObjectDefinitions = {
	error: {
		type: string;
	};
	objectDefinitionName: string;
};

const tableHeaderItems = [
	{
		id: 'objectDefinition',
		name: Liferay.Language.get('object-definition'),
	},
	{
		id: 'importStatus',
		name: Liferay.Language.get('import-status'),
	},
];

export function ModalImportFailed({
	error,
	handleOnclose,
	importedObjectDefinitions,
}: ModalImportFailedProps) {
	const [
		importedObjectDefinitionsStatus,
		setImportedObjectDefinitionsStatus,
	] = useState();

	const [loading, setLoading] = useState(false);

	useEffect(() => {
		setLoading(true);

		const failedObjectDefinitions = JSON.parse(
			error.message
		) as FailedObjectDefinitions[];

		if (failedObjectDefinitions.length) {
			const failedObjectDefinitionsMap = new Map();

			failedObjectDefinitions.forEach((failedObjectDefinition) => {
				failedObjectDefinitionsMap.set(
					failedObjectDefinition.objectDefinitionName,
					failedObjectDefinition.error.type
				);
			});

			const newImportedObjectDefinitionsStatus =
				importedObjectDefinitions.map((importedObjectDefinition) => {
					const failedObjectDefinition =
						failedObjectDefinitionsMap.has(
							importedObjectDefinition.name
						);

					return {
						errorType: failedObjectDefinition
							? failedObjectDefinitionsMap.get(
									importedObjectDefinition.name
								)
							: undefined,
						label: stringUtils.getLocalizableLabel({
							fallbackLabel: importedObjectDefinition.name,
							fallbackLanguageId:
								importedObjectDefinition.defaultLanguageId,
							labels: importedObjectDefinition.label,
						}),
						success: !failedObjectDefinition,
					} as ImportedObjectDefinitionsStatus;
				});

			setImportedObjectDefinitionsStatus(
				newImportedObjectDefinitionsStatus
			);
		}

		setLoading(false);
	}, [error.message, importedObjectDefinitions]);

	return (
		<>
			
				{Liferay.Language.get('object-definitions-failed-to-import')}
			

			
				{loading ? (
					
				) : (
					
							{

								// @ts-ignore

								(column) => (
									
										{column.name}
									
								)
							}
						
							{

								// @ts-ignore

								({errorType, label, success}) => (
									
										
											
{label}
{success ? Liferay.Language.get( 'import-succeeded' ) : errorType ? errorsUtils .ERRORS[ errorType ] : Liferay.Language.get( 'failed-to-import' )}
) }
)}
handleOnclose()} > {Liferay.Language.get('done')} } /> ); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy