META-INF.resources.js.components.baseComponents.BaseAPISchemaProperty.tsx Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.liferay.headless.builder.web
Show all versions of com.liferay.headless.builder.web
Liferay Headless Builder Web
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 ClayButton from '@clayui/button';
import ClayIcon from '@clayui/icon';
import classNames from 'classnames';
import {sub} from 'frontend-js-web';
import React, {Dispatch, SetStateAction, useContext, useState} from 'react';
import {EditSchemaContext} from '../EditAPIApplicationContext';
import {
ALLOWED_UNMODIFIABLE_OBJECTS,
BUSINESS_TYPES_TO_SYMBOLS,
} from '../utils/constants';
interface BaseAPISchemaPropertyProps {
added: boolean;
objectDefinition: ObjectDefinitionProps;
objectField: ObjectField;
objectRelationshipName?: string;
setSchemaUIData: Dispatch>;
}
interface ObjectDefinitionProps {
externalReferenceCode: string;
modifiable?: boolean;
name: string;
}
export default function BaseAPISchemaProperty({
added,
objectDefinition,
objectField,
objectRelationshipName,
setSchemaUIData,
}: BaseAPISchemaPropertyProps) {
const {apiSchemaId} = useContext(EditSchemaContext);
const [focused, setFocused] = useState(false);
const disabled =
added ||
(!objectDefinition.modifiable &&
!ALLOWED_UNMODIFIABLE_OBJECTS.includes(
objectDefinition.externalReferenceCode
));
const localizedPropertyName =
objectField.label[Liferay.ThemeDisplay.getDefaultLanguageId()]!;
const handleClick = () => {
setSchemaUIData((previous) => {
if (previous.schemaProperties) {
previous.schemaProperties.unshift({
businessType: objectField.businessType,
name: localizedPropertyName,
objectDefinitionName: objectDefinition.name,
objectFieldERC: objectField.externalReferenceCode,
objectFieldId: objectField.id,
objectFieldName: objectField.name,
r_apiSchemaToAPIProperties_c_apiSchemaId: apiSchemaId,
type: 'treeViewItem',
...(objectRelationshipName && {
objectRelationshipNames: objectRelationshipName,
}),
});
return {
...previous,
schemaProperties: [...previous.schemaProperties],
};
}
return previous;
});
};
return (
setFocused(false)}
onClick={() => !disabled && handleClick()}
onFocus={() => setFocused(true)}
>
{objectField.label[Liferay.ThemeDisplay.getDefaultLanguageId()]}
{!disabled && (
)}
);
}