import {lazy, Suspense} from "react"; import {FieldType} from "../../fields"; import {MultiSelectSearchProps} from "../../fields/MultiSelectSearch"; import {NumberProps} from "../../fields/Number"; import {AmountValidatorOptions} from "../filterinterfaces"; import {usingTestableOptions} from "../CardHelpers"; import {__} from "../../../globals"; export type CustomFieldOptions = { name: string, // the html name of the field type: 'text' | 'number' | 'exists', comparisonTypes: { text: { expectedValue: string, comparisonType: 'is' | 'not_is' | 'startswith' | 'not_startswith' | 'endswith' | 'not_endswith' | 'contains' | 'not_contains' }, number: AmountValidatorOptions, exists: true | false } } const SingleFieldRenderer = lazy(() => import('../../../Fields').then(module => ({default: module.SingleFieldRenderer})) ); function CustomFieldTopRow(props: { componentRuntimeData: any, onUpdate: any, type: CustomFieldOptions['type'], }) { return , }} /> } }} /> } export const customFieldFieldsMap = ({options: {type}}: {options: CustomFieldOptions}) => [ [{id: 'type', renderType: FieldType.Tab},], [ { id: 'name', renderType: FieldType.Custom, fieldProps: (options, onUpdate, {componentRuntimeData}) => ({ component: }), }, ...(type === 'text' ? [ {id: 'comparisonTypes.text.expectedValue', renderType: FieldType.Text}, ] : (type === 'number' ? [ {id: 'comparisonTypes.number.quantity', renderType: FieldType.Number, fieldProps: {} as NumberProps} ] : [])) ], ] export const CustomFieldComputedValue = usingTestableOptions(({type, name, comparisonTypes: {text, number, exists}}, {}) => { const textLabels: Record = { is: text.expectedValue, not_is: __('(not) *').replace('*', text.expectedValue), startswith: __('(starts with) *').replace('*', text.expectedValue), not_startswith: __('(doesn\'t start with) *').replace('*', text.expectedValue), endswith: __('(ends with) *').replace('*', text.expectedValue), not_endswith: __('(doesn\'t end with) *').replace('*', text.expectedValue), contains: __('(contains) *').replace('*', text.expectedValue), not_contains: __('(doesn\'t contain) *').replace('*', text.expectedValue), } if (type === 'text') { return } else if (type === 'number') { const numberLabels: Record = { equals: number.quantity.amount, minimum: __('Minimum *').replace('*', number.quantity.amount), maximum: __('Maximum *').replace('*', number.quantity.amount), range: `${__('* - *').replace('*', number.quantity.range.minimum).replace('*', number.quantity.range.maxmimum)}`, } return } return }) function RenderedField(props: { name: string, value: string | number, }) { return

{props.name}: {props.value}

; }