Add relations in workflow action fields (#12359)
This commit is contained in:
@ -14,6 +14,7 @@ import { FormRichTextV2FieldInput } from '@/object-record/record-field/form-type
|
||||
import { FormSelectFieldInput } from '@/object-record/record-field/form-types/components/FormSelectFieldInput';
|
||||
import { FormTextFieldInput } from '@/object-record/record-field/form-types/components/FormTextFieldInput';
|
||||
import { FormUuidFieldInput } from '@/object-record/record-field/form-types/components/FormUuidFieldInput';
|
||||
import { FormRelationToOneFieldInput } from '@/object-record/record-field/form-types/components/FormRelationToOneFieldInput';
|
||||
import { VariablePickerComponent } from '@/object-record/record-field/form-types/types/VariablePickerComponent';
|
||||
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
|
||||
import {
|
||||
@ -24,6 +25,8 @@ import {
|
||||
FieldMetadata,
|
||||
FieldMultiSelectValue,
|
||||
FieldPhonesValue,
|
||||
FieldRelationToOneValue,
|
||||
FieldRelationValue,
|
||||
FieldRichTextV2Value,
|
||||
FormFieldCurrencyValue,
|
||||
} from '@/object-record/record-field/types/FieldMetadata';
|
||||
@ -43,6 +46,7 @@ import { isFieldRichTextV2 } from '@/object-record/record-field/types/guards/isF
|
||||
import { isFieldSelect } from '@/object-record/record-field/types/guards/isFieldSelect';
|
||||
import { isFieldText } from '@/object-record/record-field/types/guards/isFieldText';
|
||||
import { isFieldUuid } from '@/object-record/record-field/types/guards/isFieldUuid';
|
||||
import { isFieldRelationToOneObject } from '@/object-record/record-field/types/guards/isFieldRelationToOneObject';
|
||||
import { JsonValue } from 'type-fest';
|
||||
|
||||
type FormFieldInputProps = {
|
||||
@ -205,5 +209,14 @@ export const FormFieldInput = ({
|
||||
readonly={readonly}
|
||||
placeholder={placeholder}
|
||||
/>
|
||||
) : isFieldRelationToOneObject(field) ? (
|
||||
<FormRelationToOneFieldInput
|
||||
label={field.label}
|
||||
objectNameSingular={field.metadata.relationObjectMetadataNameSingular}
|
||||
defaultValue={defaultValue as FieldRelationValue<FieldRelationToOneValue>}
|
||||
onChange={onChange}
|
||||
VariablePicker={VariablePicker}
|
||||
readonly={readonly}
|
||||
/>
|
||||
) : null;
|
||||
};
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
import { VariablePickerComponent } from '@/object-record/record-field/form-types/types/VariablePickerComponent';
|
||||
import { FormSingleRecordPicker } from '@/object-record/record-field/form-types/components/FormSingleRecordPicker';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { JsonValue } from 'type-fest';
|
||||
import {
|
||||
FieldRelationToOneValue,
|
||||
FieldRelationValue,
|
||||
} from '@/object-record/record-field/types/FieldMetadata';
|
||||
|
||||
export type FormRelationToOneFieldInputProps = {
|
||||
label?: string;
|
||||
objectNameSingular?: string;
|
||||
defaultValue?: FieldRelationValue<FieldRelationToOneValue>;
|
||||
onChange: (value: JsonValue) => void;
|
||||
readonly?: boolean;
|
||||
VariablePicker?: VariablePickerComponent;
|
||||
};
|
||||
|
||||
export const FormRelationToOneFieldInput = ({
|
||||
label,
|
||||
objectNameSingular,
|
||||
onChange,
|
||||
defaultValue,
|
||||
readonly,
|
||||
VariablePicker,
|
||||
}: FormRelationToOneFieldInputProps) => {
|
||||
return (
|
||||
isDefined(objectNameSingular) && (
|
||||
<FormSingleRecordPicker
|
||||
label={label}
|
||||
defaultValue={defaultValue?.id}
|
||||
onChange={(recordId) => {
|
||||
onChange({
|
||||
id: recordId,
|
||||
});
|
||||
}}
|
||||
objectNameSingular={objectNameSingular}
|
||||
disabled={readonly}
|
||||
VariablePicker={VariablePicker}
|
||||
/>
|
||||
)
|
||||
);
|
||||
};
|
||||
@ -58,7 +58,7 @@ type FormSingleRecordPickerValue =
|
||||
|
||||
export type FormSingleRecordPickerProps = {
|
||||
label?: string;
|
||||
defaultValue: RecordId | Variable;
|
||||
defaultValue?: RecordId | Variable;
|
||||
onChange: (value: RecordId | Variable) => void;
|
||||
objectNameSingular: string;
|
||||
disabled?: boolean;
|
||||
@ -95,7 +95,7 @@ export const FormSingleRecordPicker = ({
|
||||
: '',
|
||||
objectNameSingular,
|
||||
withSoftDeleted: true,
|
||||
skip: !isValidUuid(defaultValue),
|
||||
skip: !isDefined(defaultValue) || !isValidUuid(defaultValue),
|
||||
});
|
||||
|
||||
const dropdownId = `form-record-picker-${objectNameSingular}`;
|
||||
|
||||
Reference in New Issue
Block a user