fix default field type if missing value_type in attrs (#30913)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
a76c063d85
Коммит
141cfe36d1
@@ -48,6 +48,21 @@ describe('UserPropertyTypeMenu', () => {
|
|||||||
expect(screen.getByText('Text')).toBeInTheDocument();
|
expect(screen.getByText('Text')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders legacy text field with no value_type in attrs', () => {
|
||||||
|
const legacyField = {
|
||||||
|
...baseField,
|
||||||
|
type: 'text' as const,
|
||||||
|
attrs: {
|
||||||
|
sort_order: 0,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
renderComponent(legacyField as UserPropertyField);
|
||||||
|
|
||||||
|
// The menu button should show the current type
|
||||||
|
expect(screen.getByText('Text')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it('disables menu button when field is marked for deletion', () => {
|
it('disables menu button when field is marked for deletion', () => {
|
||||||
const deletedField = {
|
const deletedField = {
|
||||||
...baseField,
|
...baseField,
|
||||||
|
|||||||
@@ -119,12 +119,15 @@ export default SelectType;
|
|||||||
|
|
||||||
const getTypeDescriptor = (field: UserPropertyField): TypeDescriptor => {
|
const getTypeDescriptor = (field: UserPropertyField): TypeDescriptor => {
|
||||||
for (const descriptor of Object.values(TYPE_DESCRIPTOR)) {
|
for (const descriptor of Object.values(TYPE_DESCRIPTOR)) {
|
||||||
if (descriptor.fieldType === field.type && descriptor.valueType === field.attrs?.value_type) {
|
if (
|
||||||
|
descriptor.fieldType === field.type &&
|
||||||
|
descriptor.valueType === (field.attrs?.value_type ?? '')
|
||||||
|
) {
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error('Invalid type');
|
return TYPE_DESCRIPTOR.text;
|
||||||
};
|
};
|
||||||
|
|
||||||
type TypeID = 'text' | 'email' | 'phone' | 'url' | 'select' | 'multiselect';
|
type TypeID = 'text' | 'email' | 'phone' | 'url' | 'select' | 'multiselect';
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user