
META-INF.resources.js.components.ObjectField.Tabs.BasicInfo.SearchableContainer.tsx Maven / Gradle / Ivy
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 ClayAlert from '@clayui/alert';
import ClayForm, {ClayRadio, ClayRadioGroup} from '@clayui/form';
import {SingleSelect, Toggle} from '@liferay/object-js-components-web';
import classNames from 'classnames';
import React, {useEffect} from 'react';
import {defaultLanguageId} from '../../../../utils/constants';
import '../../EditObjectFieldContent.scss';
const languages = Liferay.Language.available;
const languageLabels = Object.entries(languages).map(([key, value]) => {
return {label: value, value: key};
});
interface SearchableProps {
isApproved: boolean;
modelBuilder?: boolean;
onSubmit?: (value?: Partial) => void;
readOnly: boolean;
setValues: (values: Partial) => void;
values: Partial;
}
export function SearchableContainer({
isApproved,
modelBuilder,
onSubmit,
readOnly,
setValues,
values,
}: SearchableProps) {
const isSearchableString =
values.indexed &&
(values.DBType === 'Clob' ||
values.DBType === 'String' ||
values.businessType === 'Attachment') &&
values.businessType !== 'Aggregation';
useEffect(() => {
if (!values.indexedLanguageId) {
setValues({
indexedLanguageId: defaultLanguageId,
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
{isApproved && (
{Liferay.Language.get(
'if-the-search-configuration-of-this-object-field-is-updated'
)}
)}
{
event.stopPropagation();
if (onSubmit) {
onSubmit();
}
}}
onToggle={(indexed) => setValues({indexed})}
toggled={values.indexed}
/>
{isSearchableString && (
{
event.stopPropagation();
if (onSubmit) {
onSubmit();
}
}}
>
{
const indexedAsKeyword = selected === 'true';
const indexedLanguageId = indexedAsKeyword
? ''
: defaultLanguageId;
setValues({
indexedAsKeyword,
indexedLanguageId,
});
}}
value={new Boolean(values.indexedAsKeyword).toString()}
>
)}
{isSearchableString && !values.indexedAsKeyword && (
{
setValues({indexedLanguageId: value as string});
if (onSubmit) {
onSubmit({
...values,
indexedLanguageId: value as string,
});
}
}}
required
selectedKey={values.indexedLanguageId as string}
/>
)}
);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy