2022-12-06 06:58:53 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React, { useCallback } from 'react';
|
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import Alert from 'Components/Alert';
|
|
|
|
import Form from 'Components/Form/Form';
|
|
|
|
import FormGroup from 'Components/Form/FormGroup';
|
|
|
|
import FormInputGroup from 'Components/Form/FormInputGroup';
|
|
|
|
import FormLabel from 'Components/Form/FormLabel';
|
|
|
|
import ProviderFieldFormGroup from 'Components/Form/ProviderFieldFormGroup';
|
|
|
|
import Button from 'Components/Link/Button';
|
|
|
|
import SpinnerErrorButton from 'Components/Link/SpinnerErrorButton';
|
2023-07-22 19:14:33 +00:00
|
|
|
import InlineMarkdown from 'Components/Markdown/InlineMarkdown';
|
2022-12-06 06:58:53 +00:00
|
|
|
import ModalBody from 'Components/Modal/ModalBody';
|
|
|
|
import ModalContent from 'Components/Modal/ModalContent';
|
|
|
|
import ModalFooter from 'Components/Modal/ModalFooter';
|
|
|
|
import ModalHeader from 'Components/Modal/ModalHeader';
|
|
|
|
import { inputTypes, kinds } from 'Helpers/Props';
|
|
|
|
import {
|
|
|
|
clearAutoTaggingSpecificationPending,
|
|
|
|
saveAutoTaggingSpecification,
|
|
|
|
setAutoTaggingSpecificationFieldValue,
|
|
|
|
setAutoTaggingSpecificationValue
|
|
|
|
} from 'Store/Actions/settingsActions';
|
|
|
|
import { createProviderSettingsSelectorHook } from 'Store/Selectors/createProviderSettingsSelector';
|
2023-07-26 04:46:02 +00:00
|
|
|
import translate from 'Utilities/String/translate';
|
2022-12-06 06:58:53 +00:00
|
|
|
import styles from './EditSpecificationModalContent.css';
|
|
|
|
|
|
|
|
function EditSpecificationModalContent(props) {
|
|
|
|
const {
|
|
|
|
id,
|
|
|
|
onDeleteSpecificationPress,
|
|
|
|
onModalClose
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const advancedSettings = useSelector((state) => state.settings.advancedSettings);
|
|
|
|
|
|
|
|
const {
|
|
|
|
item,
|
|
|
|
...otherFormProps
|
|
|
|
} = useSelector(
|
|
|
|
createProviderSettingsSelectorHook('autoTaggingSpecifications', id)
|
|
|
|
);
|
|
|
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
const onInputChange = useCallback(({ name, value }) => {
|
|
|
|
dispatch(setAutoTaggingSpecificationValue({ name, value }));
|
|
|
|
}, [dispatch]);
|
|
|
|
|
|
|
|
const onFieldChange = useCallback(({ name, value }) => {
|
|
|
|
dispatch(setAutoTaggingSpecificationFieldValue({ name, value }));
|
|
|
|
}, [dispatch]);
|
|
|
|
|
|
|
|
const onCancelPress = useCallback(({ name, value }) => {
|
|
|
|
dispatch(clearAutoTaggingSpecificationPending());
|
|
|
|
onModalClose();
|
|
|
|
}, [dispatch, onModalClose]);
|
|
|
|
|
|
|
|
const onSavePress = useCallback(({ name, value }) => {
|
|
|
|
dispatch(saveAutoTaggingSpecification({ id }));
|
|
|
|
onModalClose();
|
|
|
|
}, [dispatch, id, onModalClose]);
|
|
|
|
|
|
|
|
const {
|
|
|
|
implementationName,
|
|
|
|
name,
|
|
|
|
negate,
|
|
|
|
required,
|
|
|
|
fields
|
|
|
|
} = item;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ModalContent onModalClose={onCancelPress}>
|
|
|
|
<ModalHeader>
|
2023-07-26 04:46:02 +00:00
|
|
|
{`${id ? translate('EditCondition') : translate('AddCondition')} - ${implementationName}`}
|
2022-12-06 06:58:53 +00:00
|
|
|
</ModalHeader>
|
|
|
|
|
|
|
|
<ModalBody>
|
|
|
|
<Form
|
|
|
|
{...otherFormProps}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
fields && fields.some((x) => x.label === 'Regular Expression') &&
|
|
|
|
<Alert kind={kinds.INFO}>
|
|
|
|
<div>
|
2023-07-22 19:14:33 +00:00
|
|
|
<InlineMarkdown data={translate('ConditionUsingRegularExpressions')} />
|
2022-12-06 06:58:53 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
2023-07-22 19:14:33 +00:00
|
|
|
<InlineMarkdown data={translate('RegularExpressionsTutorialLink')} />
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<InlineMarkdown data={translate('RegularExpressionsCanBeTested')} />
|
2022-12-06 06:58:53 +00:00
|
|
|
</div>
|
|
|
|
</Alert>
|
|
|
|
}
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
<FormLabel>
|
2023-07-26 04:46:02 +00:00
|
|
|
{translate('Name')}
|
2022-12-06 06:58:53 +00:00
|
|
|
</FormLabel>
|
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.TEXT}
|
|
|
|
name="name"
|
|
|
|
{...name}
|
|
|
|
onChange={onInputChange}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
{
|
|
|
|
fields && fields.map((field) => {
|
|
|
|
return (
|
|
|
|
<ProviderFieldFormGroup
|
|
|
|
key={field.name}
|
|
|
|
advancedSettings={advancedSettings}
|
|
|
|
provider="specifications"
|
|
|
|
providerData={item}
|
|
|
|
{...field}
|
|
|
|
onChange={onFieldChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
<FormLabel>
|
2023-07-26 04:46:02 +00:00
|
|
|
{translate('Negate')}
|
2022-12-06 06:58:53 +00:00
|
|
|
</FormLabel>
|
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.CHECK}
|
|
|
|
name="negate"
|
|
|
|
{...negate}
|
2023-07-22 19:14:33 +00:00
|
|
|
helpText={translate('AutoTaggingNegateHelpText', { implementationName })}
|
2022-12-06 06:58:53 +00:00
|
|
|
onChange={onInputChange}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
|
|
|
|
<FormGroup>
|
|
|
|
<FormLabel>
|
2023-07-26 04:46:02 +00:00
|
|
|
{translate('Required')}
|
2022-12-06 06:58:53 +00:00
|
|
|
</FormLabel>
|
|
|
|
|
|
|
|
<FormInputGroup
|
|
|
|
type={inputTypes.CHECK}
|
|
|
|
name="required"
|
|
|
|
{...required}
|
2023-07-22 19:14:33 +00:00
|
|
|
helpText={translate('AutoTaggingRequiredHelpText', { implementationName })}
|
2022-12-06 06:58:53 +00:00
|
|
|
onChange={onInputChange}
|
|
|
|
/>
|
|
|
|
</FormGroup>
|
|
|
|
</Form>
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
|
|
|
{
|
|
|
|
id ?
|
|
|
|
<Button
|
|
|
|
className={styles.deleteButton}
|
|
|
|
kind={kinds.DANGER}
|
|
|
|
onPress={onDeleteSpecificationPress}
|
|
|
|
>
|
2023-07-26 04:46:02 +00:00
|
|
|
{translate('Delete')}
|
2022-12-06 06:58:53 +00:00
|
|
|
</Button> :
|
|
|
|
null
|
|
|
|
}
|
|
|
|
|
|
|
|
<Button
|
|
|
|
onPress={onCancelPress}
|
|
|
|
>
|
2023-07-26 04:46:02 +00:00
|
|
|
{translate('Cancel')}
|
2022-12-06 06:58:53 +00:00
|
|
|
</Button>
|
|
|
|
|
|
|
|
<SpinnerErrorButton
|
|
|
|
isSpinning={false}
|
|
|
|
onPress={onSavePress}
|
|
|
|
>
|
2023-07-26 04:46:02 +00:00
|
|
|
{translate('Save')}
|
2022-12-06 06:58:53 +00:00
|
|
|
</SpinnerErrorButton>
|
|
|
|
</ModalFooter>
|
|
|
|
</ModalContent>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
EditSpecificationModalContent.propTypes = {
|
|
|
|
id: PropTypes.number,
|
|
|
|
onDeleteSpecificationPress: PropTypes.func,
|
|
|
|
onModalClose: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditSpecificationModalContent;
|