Remove deprecated EMAIL, PHONE, LINK (#7551)
In this PR: - remove deprecated EMAIL, PHONE, LINK field types (except for Zapier package as there is another work ongoing) - remove composite currency filter on currencyCode, actor filter on name and workspaceMember as the UX is not great yet
This commit is contained in:
@ -352,15 +352,12 @@ export enum FieldMetadataType {
|
|||||||
Currency = 'CURRENCY',
|
Currency = 'CURRENCY',
|
||||||
Date = 'DATE',
|
Date = 'DATE',
|
||||||
DateTime = 'DATE_TIME',
|
DateTime = 'DATE_TIME',
|
||||||
Email = 'EMAIL',
|
|
||||||
Emails = 'EMAILS',
|
Emails = 'EMAILS',
|
||||||
FullName = 'FULL_NAME',
|
FullName = 'FULL_NAME',
|
||||||
Link = 'LINK',
|
|
||||||
Links = 'LINKS',
|
Links = 'LINKS',
|
||||||
MultiSelect = 'MULTI_SELECT',
|
MultiSelect = 'MULTI_SELECT',
|
||||||
Number = 'NUMBER',
|
Number = 'NUMBER',
|
||||||
Numeric = 'NUMERIC',
|
Numeric = 'NUMERIC',
|
||||||
Phone = 'PHONE',
|
|
||||||
Phones = 'PHONES',
|
Phones = 'PHONES',
|
||||||
Position = 'POSITION',
|
Position = 'POSITION',
|
||||||
Rating = 'RATING',
|
Rating = 'RATING',
|
||||||
|
|||||||
@ -263,15 +263,12 @@ export enum FieldMetadataType {
|
|||||||
Currency = 'CURRENCY',
|
Currency = 'CURRENCY',
|
||||||
Date = 'DATE',
|
Date = 'DATE',
|
||||||
DateTime = 'DATE_TIME',
|
DateTime = 'DATE_TIME',
|
||||||
Email = 'EMAIL',
|
|
||||||
Emails = 'EMAILS',
|
Emails = 'EMAILS',
|
||||||
FullName = 'FULL_NAME',
|
FullName = 'FULL_NAME',
|
||||||
Link = 'LINK',
|
|
||||||
Links = 'LINKS',
|
Links = 'LINKS',
|
||||||
MultiSelect = 'MULTI_SELECT',
|
MultiSelect = 'MULTI_SELECT',
|
||||||
Number = 'NUMBER',
|
Number = 'NUMBER',
|
||||||
Numeric = 'NUMERIC',
|
Numeric = 'NUMERIC',
|
||||||
Phone = 'PHONE',
|
|
||||||
Phones = 'PHONES',
|
Phones = 'PHONES',
|
||||||
Position = 'POSITION',
|
Position = 'POSITION',
|
||||||
Rating = 'RATING',
|
Rating = 'RATING',
|
||||||
|
|||||||
@ -7,8 +7,6 @@ export const SORTABLE_FIELD_METADATA_TYPES = [
|
|||||||
FieldMetadataType.Text,
|
FieldMetadataType.Text,
|
||||||
FieldMetadataType.Boolean,
|
FieldMetadataType.Boolean,
|
||||||
FieldMetadataType.Select,
|
FieldMetadataType.Select,
|
||||||
FieldMetadataType.Phone,
|
|
||||||
FieldMetadataType.Email,
|
|
||||||
FieldMetadataType.Emails,
|
FieldMetadataType.Emails,
|
||||||
FieldMetadataType.FullName,
|
FieldMetadataType.FullName,
|
||||||
FieldMetadataType.Rating,
|
FieldMetadataType.Rating,
|
||||||
|
|||||||
@ -26,10 +26,8 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({
|
|||||||
FieldMetadataType.DateTime,
|
FieldMetadataType.DateTime,
|
||||||
FieldMetadataType.Date,
|
FieldMetadataType.Date,
|
||||||
FieldMetadataType.Text,
|
FieldMetadataType.Text,
|
||||||
FieldMetadataType.Email,
|
|
||||||
FieldMetadataType.Emails,
|
FieldMetadataType.Emails,
|
||||||
FieldMetadataType.Number,
|
FieldMetadataType.Number,
|
||||||
FieldMetadataType.Link,
|
|
||||||
FieldMetadataType.Links,
|
FieldMetadataType.Links,
|
||||||
FieldMetadataType.FullName,
|
FieldMetadataType.FullName,
|
||||||
FieldMetadataType.Address,
|
FieldMetadataType.Address,
|
||||||
@ -68,8 +66,6 @@ export const getFilterTypeFromFieldType = (fieldType: FieldMetadataType) => {
|
|||||||
return 'DATE_TIME';
|
return 'DATE_TIME';
|
||||||
case FieldMetadataType.Date:
|
case FieldMetadataType.Date:
|
||||||
return 'DATE';
|
return 'DATE';
|
||||||
case FieldMetadataType.Link:
|
|
||||||
return 'LINK';
|
|
||||||
case FieldMetadataType.Links:
|
case FieldMetadataType.Links:
|
||||||
return 'LINKS';
|
return 'LINKS';
|
||||||
case FieldMetadataType.FullName:
|
case FieldMetadataType.FullName:
|
||||||
@ -78,12 +74,8 @@ export const getFilterTypeFromFieldType = (fieldType: FieldMetadataType) => {
|
|||||||
return 'NUMBER';
|
return 'NUMBER';
|
||||||
case FieldMetadataType.Currency:
|
case FieldMetadataType.Currency:
|
||||||
return 'CURRENCY';
|
return 'CURRENCY';
|
||||||
case FieldMetadataType.Email:
|
|
||||||
return 'EMAIL';
|
|
||||||
case FieldMetadataType.Emails:
|
case FieldMetadataType.Emails:
|
||||||
return 'EMAILS';
|
return 'EMAILS';
|
||||||
case FieldMetadataType.Phone:
|
|
||||||
return 'PHONE';
|
|
||||||
case FieldMetadataType.Phones:
|
case FieldMetadataType.Phones:
|
||||||
return 'PHONES';
|
return 'PHONES';
|
||||||
case FieldMetadataType.Relation:
|
case FieldMetadataType.Relation:
|
||||||
|
|||||||
@ -26,10 +26,8 @@ export const mapFieldMetadataToGraphQLQuery = ({
|
|||||||
const fieldIsSimpleValue = [
|
const fieldIsSimpleValue = [
|
||||||
FieldMetadataType.Uuid,
|
FieldMetadataType.Uuid,
|
||||||
FieldMetadataType.Text,
|
FieldMetadataType.Text,
|
||||||
FieldMetadataType.Phone,
|
|
||||||
FieldMetadataType.DateTime,
|
FieldMetadataType.DateTime,
|
||||||
FieldMetadataType.Date,
|
FieldMetadataType.Date,
|
||||||
FieldMetadataType.Email,
|
|
||||||
FieldMetadataType.Number,
|
FieldMetadataType.Number,
|
||||||
FieldMetadataType.Boolean,
|
FieldMetadataType.Boolean,
|
||||||
FieldMetadataType.Rating,
|
FieldMetadataType.Rating,
|
||||||
@ -97,14 +95,6 @@ ${mapObjectMetadataToGraphQLQuery({
|
|||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldType === FieldMetadataType.Link) {
|
|
||||||
return `${field.name}
|
|
||||||
{
|
|
||||||
label
|
|
||||||
url
|
|
||||||
}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldType === FieldMetadataType.Links) {
|
if (fieldType === FieldMetadataType.Links) {
|
||||||
return `${field.name}
|
return `${field.name}
|
||||||
{
|
{
|
||||||
|
|||||||
@ -131,7 +131,6 @@ export const getRecordNodeFromRecord = <T extends ObjectRecord>({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
case FieldMetadataType.Link:
|
|
||||||
case FieldMetadataType.Links:
|
case FieldMetadataType.Links:
|
||||||
case FieldMetadataType.Address:
|
case FieldMetadataType.Address:
|
||||||
case FieldMetadataType.FullName:
|
case FieldMetadataType.FullName:
|
||||||
|
|||||||
@ -36,7 +36,7 @@ const meta: Meta<typeof MultipleFiltersDropdownButton> = {
|
|||||||
fieldMetadataId: '2',
|
fieldMetadataId: '2',
|
||||||
iconName: 'Icon123',
|
iconName: 'Icon123',
|
||||||
label: 'Email',
|
label: 'Email',
|
||||||
type: FieldMetadataType.Email,
|
type: FieldMetadataType.Emails,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldMetadataId: '3',
|
fieldMetadataId: '3',
|
||||||
|
|||||||
@ -4,16 +4,13 @@ import { PickLiteral } from '~/types/PickLiteral';
|
|||||||
export type FilterableFieldType = PickLiteral<
|
export type FilterableFieldType = PickLiteral<
|
||||||
FieldType,
|
FieldType,
|
||||||
| 'TEXT'
|
| 'TEXT'
|
||||||
| 'PHONE'
|
|
||||||
| 'PHONES'
|
| 'PHONES'
|
||||||
| 'EMAIL'
|
|
||||||
| 'EMAILS'
|
| 'EMAILS'
|
||||||
| 'DATE_TIME'
|
| 'DATE_TIME'
|
||||||
| 'DATE'
|
| 'DATE'
|
||||||
| 'NUMBER'
|
| 'NUMBER'
|
||||||
| 'CURRENCY'
|
| 'CURRENCY'
|
||||||
| 'FULL_NAME'
|
| 'FULL_NAME'
|
||||||
| 'LINK'
|
|
||||||
| 'LINKS'
|
| 'LINKS'
|
||||||
| 'RELATION'
|
| 'RELATION'
|
||||||
| 'ADDRESS'
|
| 'ADDRESS'
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
|
||||||
|
|
||||||
import { FilterableFieldType } from '@/object-record/object-filter-dropdown/types/FilterableFieldType';
|
|
||||||
import { FilterDefinition } from '@/object-record/object-filter-dropdown/types/FilterDefinition';
|
import { FilterDefinition } from '@/object-record/object-filter-dropdown/types/FilterDefinition';
|
||||||
|
import { FilterableFieldType } from '@/object-record/object-filter-dropdown/types/FilterableFieldType';
|
||||||
import { getOperandsForFilterDefinition } from '../getOperandsForFilterType';
|
import { getOperandsForFilterDefinition } from '../getOperandsForFilterType';
|
||||||
|
|
||||||
describe('getOperandsForFilterType', () => {
|
describe('getOperandsForFilterType', () => {
|
||||||
@ -34,10 +34,8 @@ describe('getOperandsForFilterType', () => {
|
|||||||
|
|
||||||
const testCases = [
|
const testCases = [
|
||||||
['TEXT', [...containsOperands, ...emptyOperands]],
|
['TEXT', [...containsOperands, ...emptyOperands]],
|
||||||
['EMAIL', [...containsOperands, ...emptyOperands]],
|
|
||||||
['FULL_NAME', [...containsOperands, ...emptyOperands]],
|
['FULL_NAME', [...containsOperands, ...emptyOperands]],
|
||||||
['ADDRESS', [...containsOperands, ...emptyOperands]],
|
['ADDRESS', [...containsOperands, ...emptyOperands]],
|
||||||
['LINK', [...containsOperands, ...emptyOperands]],
|
|
||||||
['LINKS', [...containsOperands, ...emptyOperands]],
|
['LINKS', [...containsOperands, ...emptyOperands]],
|
||||||
['ACTOR', [...containsOperands, ...emptyOperands]],
|
['ACTOR', [...containsOperands, ...emptyOperands]],
|
||||||
['CURRENCY', [...numberOperands, ...emptyOperands]],
|
['CURRENCY', [...numberOperands, ...emptyOperands]],
|
||||||
|
|||||||
@ -14,12 +14,9 @@ export const getOperandsForFilterDefinition = (
|
|||||||
|
|
||||||
switch (filterDefinition.type) {
|
switch (filterDefinition.type) {
|
||||||
case 'TEXT':
|
case 'TEXT':
|
||||||
case 'EMAIL':
|
|
||||||
case 'EMAILS':
|
case 'EMAILS':
|
||||||
case 'FULL_NAME':
|
case 'FULL_NAME':
|
||||||
case 'ADDRESS':
|
case 'ADDRESS':
|
||||||
case 'PHONE':
|
|
||||||
case 'LINK':
|
|
||||||
case 'LINKS':
|
case 'LINKS':
|
||||||
case 'ARRAY':
|
case 'ARRAY':
|
||||||
case 'PHONES':
|
case 'PHONES':
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinit
|
|||||||
import {
|
import {
|
||||||
FieldActorMetadata,
|
FieldActorMetadata,
|
||||||
FieldFullNameMetadata,
|
FieldFullNameMetadata,
|
||||||
FieldLinkMetadata,
|
|
||||||
FieldRatingMetadata,
|
FieldRatingMetadata,
|
||||||
FieldSelectMetadata,
|
FieldSelectMetadata,
|
||||||
FieldTextMetadata
|
FieldTextMetadata
|
||||||
@ -67,18 +66,6 @@ export const fullNameFieldDefinition: FieldDefinition<FieldFullNameMetadata> = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const linkFieldDefinition: FieldDefinition<FieldLinkMetadata> = {
|
|
||||||
fieldMetadataId,
|
|
||||||
label: 'LinkedIn URL',
|
|
||||||
iconName: 'url',
|
|
||||||
type: FieldMetadataType.Link,
|
|
||||||
defaultValue: { url: '', label: '' },
|
|
||||||
metadata: {
|
|
||||||
fieldName: 'linkedInURL',
|
|
||||||
placeHolder: 'https://linkedin.com/user',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const phonesFieldMetadataItem = mockedPersonObjectMetadataItem.fields?.find(
|
const phonesFieldMetadataItem = mockedPersonObjectMetadataItem.fields?.find(
|
||||||
({ name }) => name === 'phones',
|
({ name }) => name === 'phones',
|
||||||
);
|
);
|
||||||
|
|||||||
@ -13,7 +13,6 @@ import { isFieldIdentifierDisplay } from '@/object-record/record-field/meta-type
|
|||||||
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
|
import { isFieldActor } from '@/object-record/record-field/types/guards/isFieldActor';
|
||||||
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
|
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
|
||||||
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
|
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
|
||||||
import { isFieldDisplayedAsPhone } from '@/object-record/record-field/types/guards/isFieldDisplayedAsPhone';
|
|
||||||
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
||||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||||
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
||||||
@ -27,13 +26,10 @@ import { ChipFieldDisplay } from '../meta-types/display/components/ChipFieldDisp
|
|||||||
import { CurrencyFieldDisplay } from '../meta-types/display/components/CurrencyFieldDisplay';
|
import { CurrencyFieldDisplay } from '../meta-types/display/components/CurrencyFieldDisplay';
|
||||||
import { DateFieldDisplay } from '../meta-types/display/components/DateFieldDisplay';
|
import { DateFieldDisplay } from '../meta-types/display/components/DateFieldDisplay';
|
||||||
import { DateTimeFieldDisplay } from '../meta-types/display/components/DateTimeFieldDisplay';
|
import { DateTimeFieldDisplay } from '../meta-types/display/components/DateTimeFieldDisplay';
|
||||||
import { EmailFieldDisplay } from '../meta-types/display/components/EmailFieldDisplay';
|
|
||||||
import { FullNameFieldDisplay } from '../meta-types/display/components/FullNameFieldDisplay';
|
import { FullNameFieldDisplay } from '../meta-types/display/components/FullNameFieldDisplay';
|
||||||
import { JsonFieldDisplay } from '../meta-types/display/components/JsonFieldDisplay';
|
import { JsonFieldDisplay } from '../meta-types/display/components/JsonFieldDisplay';
|
||||||
import { LinkFieldDisplay } from '../meta-types/display/components/LinkFieldDisplay';
|
|
||||||
import { MultiSelectFieldDisplay } from '../meta-types/display/components/MultiSelectFieldDisplay';
|
import { MultiSelectFieldDisplay } from '../meta-types/display/components/MultiSelectFieldDisplay';
|
||||||
import { NumberFieldDisplay } from '../meta-types/display/components/NumberFieldDisplay';
|
import { NumberFieldDisplay } from '../meta-types/display/components/NumberFieldDisplay';
|
||||||
import { PhoneFieldDisplay } from '../meta-types/display/components/PhoneFieldDisplay';
|
|
||||||
import { RelationToOneFieldDisplay } from '../meta-types/display/components/RelationToOneFieldDisplay';
|
import { RelationToOneFieldDisplay } from '../meta-types/display/components/RelationToOneFieldDisplay';
|
||||||
import { SelectFieldDisplay } from '../meta-types/display/components/SelectFieldDisplay';
|
import { SelectFieldDisplay } from '../meta-types/display/components/SelectFieldDisplay';
|
||||||
import { TextFieldDisplay } from '../meta-types/display/components/TextFieldDisplay';
|
import { TextFieldDisplay } from '../meta-types/display/components/TextFieldDisplay';
|
||||||
@ -42,12 +38,9 @@ import { isFieldAddress } from '../types/guards/isFieldAddress';
|
|||||||
import { isFieldCurrency } from '../types/guards/isFieldCurrency';
|
import { isFieldCurrency } from '../types/guards/isFieldCurrency';
|
||||||
import { isFieldDate } from '../types/guards/isFieldDate';
|
import { isFieldDate } from '../types/guards/isFieldDate';
|
||||||
import { isFieldDateTime } from '../types/guards/isFieldDateTime';
|
import { isFieldDateTime } from '../types/guards/isFieldDateTime';
|
||||||
import { isFieldEmail } from '../types/guards/isFieldEmail';
|
|
||||||
import { isFieldFullName } from '../types/guards/isFieldFullName';
|
import { isFieldFullName } from '../types/guards/isFieldFullName';
|
||||||
import { isFieldLink } from '../types/guards/isFieldLink';
|
|
||||||
import { isFieldMultiSelect } from '../types/guards/isFieldMultiSelect';
|
import { isFieldMultiSelect } from '../types/guards/isFieldMultiSelect';
|
||||||
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
||||||
import { isFieldPhone } from '../types/guards/isFieldPhone';
|
|
||||||
import { isFieldRawJson } from '../types/guards/isFieldRawJson';
|
import { isFieldRawJson } from '../types/guards/isFieldRawJson';
|
||||||
import { isFieldSelect } from '../types/guards/isFieldSelect';
|
import { isFieldSelect } from '../types/guards/isFieldSelect';
|
||||||
import { isFieldText } from '../types/guards/isFieldText';
|
import { isFieldText } from '../types/guards/isFieldText';
|
||||||
@ -67,23 +60,16 @@ export const FieldDisplay = () => {
|
|||||||
<RelationToOneFieldDisplay />
|
<RelationToOneFieldDisplay />
|
||||||
) : isFieldRelationFromManyObjects(fieldDefinition) ? (
|
) : isFieldRelationFromManyObjects(fieldDefinition) ? (
|
||||||
<RelationFromManyFieldDisplay />
|
<RelationFromManyFieldDisplay />
|
||||||
) : isFieldPhone(fieldDefinition) ||
|
|
||||||
isFieldDisplayedAsPhone(fieldDefinition) ? (
|
|
||||||
<PhoneFieldDisplay />
|
|
||||||
) : isFieldText(fieldDefinition) ? (
|
) : isFieldText(fieldDefinition) ? (
|
||||||
<TextFieldDisplay />
|
<TextFieldDisplay />
|
||||||
) : isFieldUuid(fieldDefinition) ? (
|
) : isFieldUuid(fieldDefinition) ? (
|
||||||
<UuidFieldDisplay />
|
<UuidFieldDisplay />
|
||||||
) : isFieldEmail(fieldDefinition) ? (
|
|
||||||
<EmailFieldDisplay />
|
|
||||||
) : isFieldDateTime(fieldDefinition) ? (
|
) : isFieldDateTime(fieldDefinition) ? (
|
||||||
<DateTimeFieldDisplay />
|
<DateTimeFieldDisplay />
|
||||||
) : isFieldDate(fieldDefinition) ? (
|
) : isFieldDate(fieldDefinition) ? (
|
||||||
<DateFieldDisplay />
|
<DateFieldDisplay />
|
||||||
) : isFieldNumber(fieldDefinition) ? (
|
) : isFieldNumber(fieldDefinition) ? (
|
||||||
<NumberFieldDisplay />
|
<NumberFieldDisplay />
|
||||||
) : isFieldLink(fieldDefinition) ? (
|
|
||||||
<LinkFieldDisplay />
|
|
||||||
) : isFieldLinks(fieldDefinition) ? (
|
) : isFieldLinks(fieldDefinition) ? (
|
||||||
<LinksFieldDisplay />
|
<LinksFieldDisplay />
|
||||||
) : isFieldCurrency(fieldDefinition) ? (
|
) : isFieldCurrency(fieldDefinition) ? (
|
||||||
|
|||||||
@ -11,44 +11,37 @@ import { RawJsonFieldInput } from '@/object-record/record-field/meta-types/input
|
|||||||
import { RelationFromManyFieldInput } from '@/object-record/record-field/meta-types/input/components/RelationFromManyFieldInput';
|
import { RelationFromManyFieldInput } from '@/object-record/record-field/meta-types/input/components/RelationFromManyFieldInput';
|
||||||
import { SelectFieldInput } from '@/object-record/record-field/meta-types/input/components/SelectFieldInput';
|
import { SelectFieldInput } from '@/object-record/record-field/meta-types/input/components/SelectFieldInput';
|
||||||
import { RecordFieldInputScope } from '@/object-record/record-field/scopes/RecordFieldInputScope';
|
import { RecordFieldInputScope } from '@/object-record/record-field/scopes/RecordFieldInputScope';
|
||||||
import { isFieldDate } from '@/object-record/record-field/types/guards/isFieldDate';
|
|
||||||
import { isFieldDisplayedAsPhone } from '@/object-record/record-field/types/guards/isFieldDisplayedAsPhone';
|
|
||||||
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
|
||||||
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
|
||||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
|
||||||
import { isFieldMultiSelect } from '@/object-record/record-field/types/guards/isFieldMultiSelect';
|
|
||||||
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
||||||
import { isFieldRawJson } from '@/object-record/record-field/types/guards/isFieldRawJson';
|
|
||||||
import { isFieldRelationFromManyObjects } from '@/object-record/record-field/types/guards/isFieldRelationFromManyObjects';
|
import { isFieldRelationFromManyObjects } from '@/object-record/record-field/types/guards/isFieldRelationFromManyObjects';
|
||||||
import { isFieldRelationToOneObject } from '@/object-record/record-field/types/guards/isFieldRelationToOneObject';
|
import { isFieldRelationToOneObject } from '@/object-record/record-field/types/guards/isFieldRelationToOneObject';
|
||||||
import { isFieldSelect } from '@/object-record/record-field/types/guards/isFieldSelect';
|
|
||||||
import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';
|
import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';
|
||||||
|
|
||||||
import { ArrayFieldInput } from '@/object-record/record-field/meta-types/input/components/ArrayFieldInput';
|
import { ArrayFieldInput } from '@/object-record/record-field/meta-types/input/components/ArrayFieldInput';
|
||||||
import { RichTextFieldInput } from '@/object-record/record-field/meta-types/input/components/RichTextFieldInput';
|
import { RichTextFieldInput } from '@/object-record/record-field/meta-types/input/components/RichTextFieldInput';
|
||||||
|
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
|
||||||
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
|
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
|
||||||
|
import { isFieldBoolean } from '@/object-record/record-field/types/guards/isFieldBoolean';
|
||||||
|
import { isFieldCurrency } from '@/object-record/record-field/types/guards/isFieldCurrency';
|
||||||
|
import { isFieldDate } from '@/object-record/record-field/types/guards/isFieldDate';
|
||||||
|
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
||||||
|
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
||||||
|
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
||||||
|
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||||
|
import { isFieldMultiSelect } from '@/object-record/record-field/types/guards/isFieldMultiSelect';
|
||||||
|
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
||||||
|
import { isFieldRating } from '@/object-record/record-field/types/guards/isFieldRating';
|
||||||
|
import { isFieldRawJson } from '@/object-record/record-field/types/guards/isFieldRawJson';
|
||||||
import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText';
|
import { isFieldRichText } from '@/object-record/record-field/types/guards/isFieldRichText';
|
||||||
|
import { isFieldSelect } from '@/object-record/record-field/types/guards/isFieldSelect';
|
||||||
import { FieldContext } from '../contexts/FieldContext';
|
import { FieldContext } from '../contexts/FieldContext';
|
||||||
import { BooleanFieldInput } from '../meta-types/input/components/BooleanFieldInput';
|
import { BooleanFieldInput } from '../meta-types/input/components/BooleanFieldInput';
|
||||||
import { CurrencyFieldInput } from '../meta-types/input/components/CurrencyFieldInput';
|
import { CurrencyFieldInput } from '../meta-types/input/components/CurrencyFieldInput';
|
||||||
import { DateTimeFieldInput } from '../meta-types/input/components/DateTimeFieldInput';
|
import { DateTimeFieldInput } from '../meta-types/input/components/DateTimeFieldInput';
|
||||||
import { EmailFieldInput } from '../meta-types/input/components/EmailFieldInput';
|
|
||||||
import { LinkFieldInput } from '../meta-types/input/components/LinkFieldInput';
|
|
||||||
import { NumberFieldInput } from '../meta-types/input/components/NumberFieldInput';
|
import { NumberFieldInput } from '../meta-types/input/components/NumberFieldInput';
|
||||||
import { PhoneFieldInput } from '../meta-types/input/components/PhoneFieldInput';
|
|
||||||
import { RatingFieldInput } from '../meta-types/input/components/RatingFieldInput';
|
import { RatingFieldInput } from '../meta-types/input/components/RatingFieldInput';
|
||||||
import { RelationToOneFieldInput } from '../meta-types/input/components/RelationToOneFieldInput';
|
import { RelationToOneFieldInput } from '../meta-types/input/components/RelationToOneFieldInput';
|
||||||
import { TextFieldInput } from '../meta-types/input/components/TextFieldInput';
|
import { TextFieldInput } from '../meta-types/input/components/TextFieldInput';
|
||||||
import { FieldInputEvent } from '../types/FieldInputEvent';
|
import { FieldInputEvent } from '../types/FieldInputEvent';
|
||||||
import { isFieldAddress } from '../types/guards/isFieldAddress';
|
|
||||||
import { isFieldBoolean } from '../types/guards/isFieldBoolean';
|
|
||||||
import { isFieldCurrency } from '../types/guards/isFieldCurrency';
|
|
||||||
import { isFieldDateTime } from '../types/guards/isFieldDateTime';
|
|
||||||
import { isFieldEmail } from '../types/guards/isFieldEmail';
|
|
||||||
import { isFieldLink } from '../types/guards/isFieldLink';
|
|
||||||
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
|
||||||
import { isFieldPhone } from '../types/guards/isFieldPhone';
|
|
||||||
import { isFieldRating } from '../types/guards/isFieldRating';
|
|
||||||
import { isFieldText } from '../types/guards/isFieldText';
|
import { isFieldText } from '../types/guards/isFieldText';
|
||||||
|
|
||||||
type FieldInputProps = {
|
type FieldInputProps = {
|
||||||
@ -84,15 +77,6 @@ export const FieldInput = ({
|
|||||||
<RelationToOneFieldInput onSubmit={onSubmit} onCancel={onCancel} />
|
<RelationToOneFieldInput onSubmit={onSubmit} onCancel={onCancel} />
|
||||||
) : isFieldRelationFromManyObjects(fieldDefinition) ? (
|
) : isFieldRelationFromManyObjects(fieldDefinition) ? (
|
||||||
<RelationFromManyFieldInput onSubmit={onSubmit} />
|
<RelationFromManyFieldInput onSubmit={onSubmit} />
|
||||||
) : isFieldPhone(fieldDefinition) ||
|
|
||||||
isFieldDisplayedAsPhone(fieldDefinition) ? (
|
|
||||||
<PhoneFieldInput
|
|
||||||
onEnter={onEnter}
|
|
||||||
onEscape={onEscape}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
onTab={onTab}
|
|
||||||
onShiftTab={onShiftTab}
|
|
||||||
/>
|
|
||||||
) : isFieldPhones(fieldDefinition) ? (
|
) : isFieldPhones(fieldDefinition) ? (
|
||||||
<PhonesFieldInput onCancel={onCancel} />
|
<PhonesFieldInput onCancel={onCancel} />
|
||||||
) : isFieldText(fieldDefinition) ? (
|
) : isFieldText(fieldDefinition) ? (
|
||||||
@ -103,14 +87,6 @@ export const FieldInput = ({
|
|||||||
onTab={onTab}
|
onTab={onTab}
|
||||||
onShiftTab={onShiftTab}
|
onShiftTab={onShiftTab}
|
||||||
/>
|
/>
|
||||||
) : isFieldEmail(fieldDefinition) ? (
|
|
||||||
<EmailFieldInput
|
|
||||||
onEnter={onEnter}
|
|
||||||
onEscape={onEscape}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
onTab={onTab}
|
|
||||||
onShiftTab={onShiftTab}
|
|
||||||
/>
|
|
||||||
) : isFieldEmails(fieldDefinition) ? (
|
) : isFieldEmails(fieldDefinition) ? (
|
||||||
<EmailsFieldInput onCancel={onCancel} />
|
<EmailsFieldInput onCancel={onCancel} />
|
||||||
) : isFieldFullName(fieldDefinition) ? (
|
) : isFieldFullName(fieldDefinition) ? (
|
||||||
@ -145,14 +121,6 @@ export const FieldInput = ({
|
|||||||
onTab={onTab}
|
onTab={onTab}
|
||||||
onShiftTab={onShiftTab}
|
onShiftTab={onShiftTab}
|
||||||
/>
|
/>
|
||||||
) : isFieldLink(fieldDefinition) ? (
|
|
||||||
<LinkFieldInput
|
|
||||||
onEnter={onEnter}
|
|
||||||
onEscape={onEscape}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
onTab={onTab}
|
|
||||||
onShiftTab={onShiftTab}
|
|
||||||
/>
|
|
||||||
) : isFieldLinks(fieldDefinition) ? (
|
) : isFieldLinks(fieldDefinition) ? (
|
||||||
<LinksFieldInput onCancel={onCancel} />
|
<LinksFieldInput onCancel={onCancel} />
|
||||||
) : isFieldCurrency(fieldDefinition) ? (
|
) : isFieldCurrency(fieldDefinition) ? (
|
||||||
|
|||||||
@ -35,14 +35,8 @@ import { isFieldCurrency } from '../types/guards/isFieldCurrency';
|
|||||||
import { isFieldCurrencyValue } from '../types/guards/isFieldCurrencyValue';
|
import { isFieldCurrencyValue } from '../types/guards/isFieldCurrencyValue';
|
||||||
import { isFieldDateTime } from '../types/guards/isFieldDateTime';
|
import { isFieldDateTime } from '../types/guards/isFieldDateTime';
|
||||||
import { isFieldDateTimeValue } from '../types/guards/isFieldDateTimeValue';
|
import { isFieldDateTimeValue } from '../types/guards/isFieldDateTimeValue';
|
||||||
import { isFieldEmail } from '../types/guards/isFieldEmail';
|
|
||||||
import { isFieldEmailValue } from '../types/guards/isFieldEmailValue';
|
|
||||||
import { isFieldLink } from '../types/guards/isFieldLink';
|
|
||||||
import { isFieldLinkValue } from '../types/guards/isFieldLinkValue';
|
|
||||||
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
import { isFieldNumber } from '../types/guards/isFieldNumber';
|
||||||
import { isFieldNumberValue } from '../types/guards/isFieldNumberValue';
|
import { isFieldNumberValue } from '../types/guards/isFieldNumberValue';
|
||||||
import { isFieldPhone } from '../types/guards/isFieldPhone';
|
|
||||||
import { isFieldPhoneValue } from '../types/guards/isFieldPhoneValue';
|
|
||||||
import { isFieldRating } from '../types/guards/isFieldRating';
|
import { isFieldRating } from '../types/guards/isFieldRating';
|
||||||
import { isFieldRatingValue } from '../types/guards/isFieldRatingValue';
|
import { isFieldRatingValue } from '../types/guards/isFieldRatingValue';
|
||||||
import { isFieldText } from '../types/guards/isFieldText';
|
import { isFieldText } from '../types/guards/isFieldText';
|
||||||
@ -68,9 +62,6 @@ export const usePersistField = () => {
|
|||||||
const fieldIsText =
|
const fieldIsText =
|
||||||
isFieldText(fieldDefinition) && isFieldTextValue(valueToPersist);
|
isFieldText(fieldDefinition) && isFieldTextValue(valueToPersist);
|
||||||
|
|
||||||
const fieldIsEmail =
|
|
||||||
isFieldEmail(fieldDefinition) && isFieldEmailValue(valueToPersist);
|
|
||||||
|
|
||||||
const fieldIsEmails =
|
const fieldIsEmails =
|
||||||
isFieldEmails(fieldDefinition) && isFieldEmailsValue(valueToPersist);
|
isFieldEmails(fieldDefinition) && isFieldEmailsValue(valueToPersist);
|
||||||
|
|
||||||
@ -81,9 +72,6 @@ export const usePersistField = () => {
|
|||||||
const fieldIsDate =
|
const fieldIsDate =
|
||||||
isFieldDate(fieldDefinition) && isFieldDateValue(valueToPersist);
|
isFieldDate(fieldDefinition) && isFieldDateValue(valueToPersist);
|
||||||
|
|
||||||
const fieldIsLink =
|
|
||||||
isFieldLink(fieldDefinition) && isFieldLinkValue(valueToPersist);
|
|
||||||
|
|
||||||
const fieldIsLinks =
|
const fieldIsLinks =
|
||||||
isFieldLinks(fieldDefinition) && isFieldLinksValue(valueToPersist);
|
isFieldLinks(fieldDefinition) && isFieldLinksValue(valueToPersist);
|
||||||
|
|
||||||
@ -105,9 +93,6 @@ export const usePersistField = () => {
|
|||||||
isFieldFullName(fieldDefinition) &&
|
isFieldFullName(fieldDefinition) &&
|
||||||
isFieldFullNameValue(valueToPersist);
|
isFieldFullNameValue(valueToPersist);
|
||||||
|
|
||||||
const fieldIsPhone =
|
|
||||||
isFieldPhone(fieldDefinition) && isFieldPhoneValue(valueToPersist);
|
|
||||||
|
|
||||||
const fieldIsPhones =
|
const fieldIsPhones =
|
||||||
isFieldPhones(fieldDefinition) && isFieldPhonesValue(valueToPersist);
|
isFieldPhones(fieldDefinition) && isFieldPhonesValue(valueToPersist);
|
||||||
|
|
||||||
@ -133,15 +118,12 @@ export const usePersistField = () => {
|
|||||||
fieldIsRelationToOneObject ||
|
fieldIsRelationToOneObject ||
|
||||||
fieldIsText ||
|
fieldIsText ||
|
||||||
fieldIsBoolean ||
|
fieldIsBoolean ||
|
||||||
fieldIsEmail ||
|
|
||||||
fieldIsEmails ||
|
fieldIsEmails ||
|
||||||
fieldIsRating ||
|
fieldIsRating ||
|
||||||
fieldIsNumber ||
|
fieldIsNumber ||
|
||||||
fieldIsDateTime ||
|
fieldIsDateTime ||
|
||||||
fieldIsDate ||
|
fieldIsDate ||
|
||||||
fieldIsPhone ||
|
|
||||||
fieldIsPhones ||
|
fieldIsPhones ||
|
||||||
fieldIsLink ||
|
|
||||||
fieldIsLinks ||
|
fieldIsLinks ||
|
||||||
fieldIsCurrency ||
|
fieldIsCurrency ||
|
||||||
fieldIsFullName ||
|
fieldIsFullName ||
|
||||||
|
|||||||
@ -1,8 +0,0 @@
|
|||||||
import { useEmailFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useEmailFieldDisplay';
|
|
||||||
import { EmailDisplay } from '@/ui/field/display/components/EmailDisplay';
|
|
||||||
|
|
||||||
export const EmailFieldDisplay = () => {
|
|
||||||
const { fieldValue } = useEmailFieldDisplay();
|
|
||||||
|
|
||||||
return <EmailDisplay value={fieldValue} />;
|
|
||||||
};
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { useLinkFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useLinkFieldDisplay';
|
|
||||||
import { LinkDisplay } from '@/ui/field/display/components/LinkDisplay';
|
|
||||||
|
|
||||||
export const LinkFieldDisplay = () => {
|
|
||||||
const { fieldValue } = useLinkFieldDisplay();
|
|
||||||
|
|
||||||
return <LinkDisplay value={fieldValue} />;
|
|
||||||
};
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { usePhoneFieldDisplay } from '@/object-record/record-field/meta-types/hooks/usePhoneFieldDisplay';
|
|
||||||
import { PhoneDisplay } from '@/ui/field/display/components/PhoneDisplay';
|
|
||||||
|
|
||||||
export const PhoneFieldDisplay = () => {
|
|
||||||
const { fieldValue } = usePhoneFieldDisplay();
|
|
||||||
|
|
||||||
return <PhoneDisplay value={fieldValue} />;
|
|
||||||
};
|
|
||||||
@ -1,40 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
|
||||||
|
|
||||||
import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput';
|
|
||||||
import { FieldEmailValue } from '@/object-record/record-field/types/FieldMetadata';
|
|
||||||
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
|
|
||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
||||||
|
|
||||||
import { FieldContext } from '../../contexts/FieldContext';
|
|
||||||
import { assertFieldMetadata } from '../../types/guards/assertFieldMetadata';
|
|
||||||
import { isFieldEmail } from '../../types/guards/isFieldEmail';
|
|
||||||
|
|
||||||
export const useEmailField = () => {
|
|
||||||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
|
||||||
|
|
||||||
assertFieldMetadata(FieldMetadataType.Email, isFieldEmail, fieldDefinition);
|
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
|
||||||
|
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<string>(
|
|
||||||
recordStoreFamilySelector({
|
|
||||||
recordId,
|
|
||||||
fieldName: fieldName,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const { setDraftValue, getDraftValueSelector } =
|
|
||||||
useRecordFieldInput<FieldEmailValue>(`${recordId}-${fieldName}`);
|
|
||||||
|
|
||||||
const draftValue = useRecoilValue(getDraftValueSelector());
|
|
||||||
|
|
||||||
return {
|
|
||||||
fieldDefinition,
|
|
||||||
draftValue,
|
|
||||||
setDraftValue,
|
|
||||||
fieldValue,
|
|
||||||
setFieldValue,
|
|
||||||
hotkeyScope,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
|
|
||||||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
|
||||||
|
|
||||||
import { FieldContext } from '../../contexts/FieldContext';
|
|
||||||
|
|
||||||
export const useEmailFieldDisplay = () => {
|
|
||||||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
|
||||||
|
|
||||||
const fieldValue = useRecordFieldValue<string>(recordId, fieldName);
|
|
||||||
|
|
||||||
return {
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
hotkeyScope,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,53 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
|
||||||
|
|
||||||
import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput';
|
|
||||||
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
|
|
||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
||||||
|
|
||||||
import { FieldContext } from '../../contexts/FieldContext';
|
|
||||||
import { usePersistField } from '../../hooks/usePersistField';
|
|
||||||
import { FieldLinkValue } from '../../types/FieldMetadata';
|
|
||||||
import { assertFieldMetadata } from '../../types/guards/assertFieldMetadata';
|
|
||||||
import { isFieldLink } from '../../types/guards/isFieldLink';
|
|
||||||
import { isFieldLinkValue } from '../../types/guards/isFieldLinkValue';
|
|
||||||
|
|
||||||
export const useLinkField = () => {
|
|
||||||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
|
||||||
|
|
||||||
assertFieldMetadata(FieldMetadataType.Link, isFieldLink, fieldDefinition);
|
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
|
||||||
|
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<FieldLinkValue>(
|
|
||||||
recordStoreFamilySelector({
|
|
||||||
recordId,
|
|
||||||
fieldName: fieldName,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const { setDraftValue, getDraftValueSelector } =
|
|
||||||
useRecordFieldInput<FieldLinkValue>(`${recordId}-${fieldName}`);
|
|
||||||
|
|
||||||
const draftValue = useRecoilValue(getDraftValueSelector());
|
|
||||||
|
|
||||||
const persistField = usePersistField();
|
|
||||||
|
|
||||||
const persistLinkField = (newValue: FieldLinkValue) => {
|
|
||||||
if (!isFieldLinkValue(newValue)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
persistField(newValue);
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
draftValue,
|
|
||||||
setDraftValue,
|
|
||||||
setFieldValue,
|
|
||||||
hotkeyScope,
|
|
||||||
persistLinkField,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
|
|
||||||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
|
||||||
|
|
||||||
import { FieldContext } from '../../contexts/FieldContext';
|
|
||||||
import { FieldLinkValue } from '../../types/FieldMetadata';
|
|
||||||
|
|
||||||
export const useLinkFieldDisplay = () => {
|
|
||||||
const { recordId, fieldDefinition } = useContext(FieldContext);
|
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
|
||||||
const fieldValue = useRecordFieldValue<FieldLinkValue | undefined>(
|
|
||||||
recordId,
|
|
||||||
fieldName,
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,61 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
import { isPossiblePhoneNumber } from 'libphonenumber-js';
|
|
||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
|
||||||
|
|
||||||
import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput';
|
|
||||||
import { FieldPhoneValue } from '@/object-record/record-field/types/FieldMetadata';
|
|
||||||
import { isFieldDisplayedAsPhone } from '@/object-record/record-field/types/guards/isFieldDisplayedAsPhone';
|
|
||||||
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector';
|
|
||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
||||||
|
|
||||||
import { FieldContext } from '../../contexts/FieldContext';
|
|
||||||
import { usePersistField } from '../../hooks/usePersistField';
|
|
||||||
import { assertFieldMetadata } from '../../types/guards/assertFieldMetadata';
|
|
||||||
import { isFieldPhone } from '../../types/guards/isFieldPhone';
|
|
||||||
|
|
||||||
export const usePhoneField = () => {
|
|
||||||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// TODO: temporary - remove when 'Phone' field in 'Person' object
|
|
||||||
// is migrated to use FieldMetadataType.Phone as type.
|
|
||||||
assertFieldMetadata(
|
|
||||||
FieldMetadataType.Text,
|
|
||||||
isFieldDisplayedAsPhone,
|
|
||||||
fieldDefinition,
|
|
||||||
);
|
|
||||||
} catch {
|
|
||||||
assertFieldMetadata(FieldMetadataType.Phone, isFieldPhone, fieldDefinition);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
|
||||||
|
|
||||||
const [fieldValue, setFieldValue] = useRecoilState<string>(
|
|
||||||
recordStoreFamilySelector({
|
|
||||||
recordId,
|
|
||||||
fieldName: fieldName,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const persistField = usePersistField();
|
|
||||||
|
|
||||||
const persistPhoneField = (newPhoneValue: string) => {
|
|
||||||
if (!isPossiblePhoneNumber(newPhoneValue) && newPhoneValue !== '') return;
|
|
||||||
|
|
||||||
persistField(newPhoneValue);
|
|
||||||
};
|
|
||||||
const { setDraftValue, getDraftValueSelector } =
|
|
||||||
useRecordFieldInput<FieldPhoneValue>(`${recordId}-${fieldName}`);
|
|
||||||
|
|
||||||
const draftValue = useRecoilValue(getDraftValueSelector());
|
|
||||||
|
|
||||||
return {
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
setFieldValue,
|
|
||||||
draftValue,
|
|
||||||
setDraftValue,
|
|
||||||
hotkeyScope,
|
|
||||||
persistPhoneField,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
import { useContext } from 'react';
|
|
||||||
|
|
||||||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
|
|
||||||
|
|
||||||
import { FieldContext } from '../../contexts/FieldContext';
|
|
||||||
|
|
||||||
export const usePhoneFieldDisplay = () => {
|
|
||||||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
|
|
||||||
|
|
||||||
const fieldName = fieldDefinition.metadata.fieldName;
|
|
||||||
|
|
||||||
const fieldValue = useRecordFieldValue<string>(recordId, fieldName);
|
|
||||||
|
|
||||||
return {
|
|
||||||
fieldDefinition,
|
|
||||||
fieldValue,
|
|
||||||
hotkeyScope,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@ -1,72 +0,0 @@
|
|||||||
import { TextInput } from '@/ui/field/input/components/TextInput';
|
|
||||||
|
|
||||||
import { FieldInputOverlay } from '../../../../../ui/field/input/components/FieldInputOverlay';
|
|
||||||
import { usePersistField } from '../../../hooks/usePersistField';
|
|
||||||
import { useEmailField } from '../../hooks/useEmailField';
|
|
||||||
|
|
||||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
|
||||||
|
|
||||||
export type EmailFieldInputProps = {
|
|
||||||
onClickOutside?: FieldInputEvent;
|
|
||||||
onEnter?: FieldInputEvent;
|
|
||||||
onEscape?: FieldInputEvent;
|
|
||||||
onTab?: FieldInputEvent;
|
|
||||||
onShiftTab?: FieldInputEvent;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const EmailFieldInput = ({
|
|
||||||
onEnter,
|
|
||||||
onEscape,
|
|
||||||
onClickOutside,
|
|
||||||
onTab,
|
|
||||||
onShiftTab,
|
|
||||||
}: EmailFieldInputProps) => {
|
|
||||||
const { fieldDefinition, draftValue, setDraftValue, hotkeyScope } =
|
|
||||||
useEmailField();
|
|
||||||
|
|
||||||
const persistField = usePersistField();
|
|
||||||
|
|
||||||
const handleEnter = (newText: string) => {
|
|
||||||
onEnter?.(() => persistField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEscape = (newText: string) => {
|
|
||||||
onEscape?.(() => persistField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClickOutside = (
|
|
||||||
event: MouseEvent | TouchEvent,
|
|
||||||
newText: string,
|
|
||||||
) => {
|
|
||||||
onClickOutside?.(() => persistField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTab = (newText: string) => {
|
|
||||||
onTab?.(() => persistField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleShiftTab = (newText: string) => {
|
|
||||||
onShiftTab?.(() => persistField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (newText: string) => {
|
|
||||||
setDraftValue(newText);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FieldInputOverlay>
|
|
||||||
<TextInput
|
|
||||||
placeholder={fieldDefinition.metadata.placeHolder}
|
|
||||||
autoFocus
|
|
||||||
value={draftValue ?? ''}
|
|
||||||
onClickOutside={handleClickOutside}
|
|
||||||
onEnter={handleEnter}
|
|
||||||
onEscape={handleEscape}
|
|
||||||
onShiftTab={handleShiftTab}
|
|
||||||
onTab={handleTab}
|
|
||||||
hotkeyScope={hotkeyScope}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
</FieldInputOverlay>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,97 +0,0 @@
|
|||||||
import { TextInput } from '@/ui/field/input/components/TextInput';
|
|
||||||
|
|
||||||
import { FieldInputOverlay } from '../../../../../ui/field/input/components/FieldInputOverlay';
|
|
||||||
import { useLinkField } from '../../hooks/useLinkField';
|
|
||||||
|
|
||||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
|
||||||
|
|
||||||
type LinkFieldInputProps = {
|
|
||||||
onClickOutside?: FieldInputEvent;
|
|
||||||
onEnter?: FieldInputEvent;
|
|
||||||
onEscape?: FieldInputEvent;
|
|
||||||
onTab?: FieldInputEvent;
|
|
||||||
onShiftTab?: FieldInputEvent;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const LinkFieldInput = ({
|
|
||||||
onEnter,
|
|
||||||
onEscape,
|
|
||||||
onClickOutside,
|
|
||||||
onTab,
|
|
||||||
onShiftTab,
|
|
||||||
}: LinkFieldInputProps) => {
|
|
||||||
const { draftValue, setDraftValue, hotkeyScope, persistLinkField } =
|
|
||||||
useLinkField();
|
|
||||||
|
|
||||||
const handleEnter = (newURL: string) => {
|
|
||||||
onEnter?.(() =>
|
|
||||||
persistLinkField({
|
|
||||||
url: newURL,
|
|
||||||
label: '',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEscape = (newURL: string) => {
|
|
||||||
onEscape?.(() =>
|
|
||||||
persistLinkField({
|
|
||||||
url: newURL,
|
|
||||||
label: '',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClickOutside = (
|
|
||||||
event: MouseEvent | TouchEvent,
|
|
||||||
newURL: string,
|
|
||||||
) => {
|
|
||||||
onClickOutside?.(() =>
|
|
||||||
persistLinkField({
|
|
||||||
url: newURL,
|
|
||||||
label: '',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTab = (newURL: string) => {
|
|
||||||
onTab?.(() =>
|
|
||||||
persistLinkField({
|
|
||||||
url: newURL,
|
|
||||||
label: '',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleShiftTab = (newURL: string) => {
|
|
||||||
onShiftTab?.(() =>
|
|
||||||
persistLinkField({
|
|
||||||
url: newURL,
|
|
||||||
label: '',
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (newURL: string) => {
|
|
||||||
setDraftValue({
|
|
||||||
url: newURL,
|
|
||||||
label: '',
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FieldInputOverlay>
|
|
||||||
<TextInput
|
|
||||||
value={draftValue?.url ?? ''}
|
|
||||||
autoFocus
|
|
||||||
placeholder="URL"
|
|
||||||
hotkeyScope={hotkeyScope}
|
|
||||||
onClickOutside={handleClickOutside}
|
|
||||||
onEnter={handleEnter}
|
|
||||||
onEscape={handleEscape}
|
|
||||||
onTab={handleTab}
|
|
||||||
onShiftTab={handleShiftTab}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
</FieldInputOverlay>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,74 +0,0 @@
|
|||||||
import { PhoneInput } from '@/ui/field/input/components/PhoneInput';
|
|
||||||
|
|
||||||
import { FieldInputOverlay } from '../../../../../ui/field/input/components/FieldInputOverlay';
|
|
||||||
import { usePhoneField } from '../../hooks/usePhoneField';
|
|
||||||
|
|
||||||
import { FieldInputEvent } from './DateTimeFieldInput';
|
|
||||||
|
|
||||||
export type PhoneFieldInputProps = {
|
|
||||||
onClickOutside?: FieldInputEvent;
|
|
||||||
onEnter?: FieldInputEvent;
|
|
||||||
onEscape?: FieldInputEvent;
|
|
||||||
onTab?: FieldInputEvent;
|
|
||||||
onShiftTab?: FieldInputEvent;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const PhoneFieldInput = ({
|
|
||||||
onEnter,
|
|
||||||
onEscape,
|
|
||||||
onClickOutside,
|
|
||||||
onTab,
|
|
||||||
onShiftTab,
|
|
||||||
}: PhoneFieldInputProps) => {
|
|
||||||
const {
|
|
||||||
fieldDefinition,
|
|
||||||
draftValue,
|
|
||||||
setDraftValue,
|
|
||||||
hotkeyScope,
|
|
||||||
persistPhoneField,
|
|
||||||
} = usePhoneField();
|
|
||||||
|
|
||||||
const handleEnter = (newText: string) => {
|
|
||||||
onEnter?.(() => persistPhoneField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleEscape = (newText: string) => {
|
|
||||||
onEscape?.(() => persistPhoneField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClickOutside = (
|
|
||||||
event: MouseEvent | TouchEvent,
|
|
||||||
newText: string,
|
|
||||||
) => {
|
|
||||||
onClickOutside?.(() => persistPhoneField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTab = (newText: string) => {
|
|
||||||
onTab?.(() => persistPhoneField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleShiftTab = (newText: string) => {
|
|
||||||
onShiftTab?.(() => persistPhoneField(newText));
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleChange = (newText: string) => {
|
|
||||||
setDraftValue(newText);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<FieldInputOverlay>
|
|
||||||
<PhoneInput
|
|
||||||
placeholder={fieldDefinition.metadata.placeHolder}
|
|
||||||
autoFocus
|
|
||||||
value={draftValue ?? ''}
|
|
||||||
onClickOutside={handleClickOutside}
|
|
||||||
onEnter={handleEnter}
|
|
||||||
onEscape={handleEscape}
|
|
||||||
onShiftTab={handleShiftTab}
|
|
||||||
onTab={handleTab}
|
|
||||||
hotkeyScope={hotkeyScope}
|
|
||||||
onChange={handleChange}
|
|
||||||
/>
|
|
||||||
</FieldInputOverlay>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@ -1,177 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import { Decorator, Meta, StoryObj } from '@storybook/react';
|
|
||||||
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';
|
|
||||||
|
|
||||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
|
||||||
import { FieldMetadataType } from '~/generated/graphql';
|
|
||||||
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
|
|
||||||
|
|
||||||
import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
|
|
||||||
import { useEmailField } from '../../../hooks/useEmailField';
|
|
||||||
import { EmailFieldInput, EmailFieldInputProps } from '../EmailFieldInput';
|
|
||||||
|
|
||||||
const EmailFieldValueSetterEffect = ({ value }: { value: string }) => {
|
|
||||||
const { setFieldValue } = useEmailField();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setFieldValue(value);
|
|
||||||
}, [setFieldValue, value]);
|
|
||||||
|
|
||||||
return <></>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type EmailFieldInputWithContextProps = EmailFieldInputProps & {
|
|
||||||
value: string;
|
|
||||||
recordId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const EmailFieldInputWithContext = ({
|
|
||||||
recordId,
|
|
||||||
value,
|
|
||||||
onEnter,
|
|
||||||
onEscape,
|
|
||||||
onClickOutside,
|
|
||||||
onTab,
|
|
||||||
onShiftTab,
|
|
||||||
}: EmailFieldInputWithContextProps) => {
|
|
||||||
const setHotKeyScope = useSetHotkeyScope();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setHotKeyScope('hotkey-scope');
|
|
||||||
}, [setHotKeyScope]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<FieldContextProvider
|
|
||||||
fieldDefinition={{
|
|
||||||
fieldMetadataId: 'email',
|
|
||||||
label: 'Email',
|
|
||||||
type: FieldMetadataType.Email,
|
|
||||||
iconName: 'IconLink',
|
|
||||||
metadata: {
|
|
||||||
fieldName: 'email',
|
|
||||||
placeHolder: 'username@email.com',
|
|
||||||
objectMetadataNameSingular: 'person',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
recordId={recordId}
|
|
||||||
>
|
|
||||||
<EmailFieldValueSetterEffect value={value} />
|
|
||||||
<EmailFieldInput
|
|
||||||
onEnter={onEnter}
|
|
||||||
onEscape={onEscape}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
onTab={onTab}
|
|
||||||
onShiftTab={onShiftTab}
|
|
||||||
/>
|
|
||||||
</FieldContextProvider>
|
|
||||||
<div data-testid="data-field-input-click-outside-div" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const enterJestFn = fn();
|
|
||||||
const escapeJestfn = fn();
|
|
||||||
const clickOutsideJestFn = fn();
|
|
||||||
const tabJestFn = fn();
|
|
||||||
const shiftTabJestFn = fn();
|
|
||||||
|
|
||||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
|
||||||
if (context.parameters.clearMocks === true) {
|
|
||||||
enterJestFn.mockClear();
|
|
||||||
escapeJestfn.mockClear();
|
|
||||||
clickOutsideJestFn.mockClear();
|
|
||||||
tabJestFn.mockClear();
|
|
||||||
shiftTabJestFn.mockClear();
|
|
||||||
}
|
|
||||||
return <Story />;
|
|
||||||
};
|
|
||||||
|
|
||||||
const meta: Meta = {
|
|
||||||
title: 'UI/Data/Field/Input/EmailFieldInput',
|
|
||||||
component: EmailFieldInputWithContext,
|
|
||||||
args: {
|
|
||||||
value: 'username@email.com',
|
|
||||||
onEnter: enterJestFn,
|
|
||||||
onEscape: escapeJestfn,
|
|
||||||
onClickOutside: clickOutsideJestFn,
|
|
||||||
onTab: tabJestFn,
|
|
||||||
onShiftTab: shiftTabJestFn,
|
|
||||||
},
|
|
||||||
argTypes: {
|
|
||||||
onEnter: { control: false },
|
|
||||||
onEscape: { control: false },
|
|
||||||
onClickOutside: { control: false },
|
|
||||||
onTab: { control: false },
|
|
||||||
onShiftTab: { control: false },
|
|
||||||
},
|
|
||||||
decorators: [clearMocksDecorator, SnackBarDecorator],
|
|
||||||
parameters: {
|
|
||||||
clearMocks: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default meta;
|
|
||||||
|
|
||||||
type Story = StoryObj<typeof EmailFieldInputWithContext>;
|
|
||||||
|
|
||||||
export const Default: Story = {};
|
|
||||||
|
|
||||||
export const Enter: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(enterJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{enter}');
|
|
||||||
expect(enterJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Escape: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(escapeJestfn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{esc}');
|
|
||||||
expect(escapeJestfn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ClickOutside: Story = {
|
|
||||||
play: async ({ canvasElement }) => {
|
|
||||||
const canvas = within(canvasElement);
|
|
||||||
|
|
||||||
expect(clickOutsideJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
const emptyDiv = canvas.getByTestId('data-field-input-click-outside-div');
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.click(emptyDiv);
|
|
||||||
expect(clickOutsideJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Tab: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(tabJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{tab}');
|
|
||||||
expect(tabJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ShiftTab: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(shiftTabJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{shift>}{tab}');
|
|
||||||
expect(shiftTabJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -1,178 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import { Decorator, Meta, StoryObj } from '@storybook/react';
|
|
||||||
import { expect, fn, userEvent, waitFor, within } from '@storybook/test';
|
|
||||||
|
|
||||||
import { useSetHotkeyScope } from '@/ui/utilities/hotkey/hooks/useSetHotkeyScope';
|
|
||||||
import { FieldMetadataType } from '~/generated/graphql';
|
|
||||||
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
|
|
||||||
|
|
||||||
import { FieldContextProvider } from '../../../__stories__/FieldContextProvider';
|
|
||||||
import { usePhoneField } from '../../../hooks/usePhoneField';
|
|
||||||
import { PhoneFieldInput, PhoneFieldInputProps } from '../PhoneFieldInput';
|
|
||||||
|
|
||||||
const PhoneFieldValueSetterEffect = ({ value }: { value: string }) => {
|
|
||||||
const { setFieldValue } = usePhoneField();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setFieldValue(value);
|
|
||||||
}, [setFieldValue, value]);
|
|
||||||
|
|
||||||
return <></>;
|
|
||||||
};
|
|
||||||
|
|
||||||
type PhoneFieldInputWithContextProps = PhoneFieldInputProps & {
|
|
||||||
value: string;
|
|
||||||
recordId?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
const PhoneFieldInputWithContext = ({
|
|
||||||
recordId,
|
|
||||||
value,
|
|
||||||
onEnter,
|
|
||||||
onEscape,
|
|
||||||
onClickOutside,
|
|
||||||
onTab,
|
|
||||||
onShiftTab,
|
|
||||||
}: PhoneFieldInputWithContextProps) => {
|
|
||||||
const setHotKeyScope = useSetHotkeyScope();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setHotKeyScope('hotkey-scope');
|
|
||||||
}, [setHotKeyScope]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<FieldContextProvider
|
|
||||||
fieldDefinition={{
|
|
||||||
fieldMetadataId: 'phone',
|
|
||||||
label: 'Phone',
|
|
||||||
type: FieldMetadataType.Phone,
|
|
||||||
iconName: 'IconPhone',
|
|
||||||
metadata: {
|
|
||||||
fieldName: 'phone',
|
|
||||||
placeHolder: 'Enter phone number',
|
|
||||||
objectMetadataNameSingular: 'person',
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
recordId={recordId}
|
|
||||||
>
|
|
||||||
<PhoneFieldValueSetterEffect value={value} />
|
|
||||||
<PhoneFieldInput
|
|
||||||
onEnter={onEnter}
|
|
||||||
onEscape={onEscape}
|
|
||||||
onClickOutside={onClickOutside}
|
|
||||||
onTab={onTab}
|
|
||||||
onShiftTab={onShiftTab}
|
|
||||||
/>
|
|
||||||
</FieldContextProvider>
|
|
||||||
<div data-testid="data-field-input-click-outside-div" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const enterJestFn = fn();
|
|
||||||
const escapeJestfn = fn();
|
|
||||||
const clickOutsideJestFn = fn();
|
|
||||||
const tabJestFn = fn();
|
|
||||||
const shiftTabJestFn = fn();
|
|
||||||
|
|
||||||
const clearMocksDecorator: Decorator = (Story, context) => {
|
|
||||||
if (context.parameters.clearMocks === true) {
|
|
||||||
enterJestFn.mockClear();
|
|
||||||
escapeJestfn.mockClear();
|
|
||||||
clickOutsideJestFn.mockClear();
|
|
||||||
tabJestFn.mockClear();
|
|
||||||
shiftTabJestFn.mockClear();
|
|
||||||
}
|
|
||||||
return <Story />;
|
|
||||||
};
|
|
||||||
|
|
||||||
const meta: Meta = {
|
|
||||||
title: 'UI/Data/Field/Input/PhoneFieldInput',
|
|
||||||
component: PhoneFieldInputWithContext,
|
|
||||||
args: {
|
|
||||||
value: '+1-12-123-456',
|
|
||||||
isPositive: true,
|
|
||||||
onEnter: enterJestFn,
|
|
||||||
onEscape: escapeJestfn,
|
|
||||||
onClickOutside: clickOutsideJestFn,
|
|
||||||
onTab: tabJestFn,
|
|
||||||
onShiftTab: shiftTabJestFn,
|
|
||||||
},
|
|
||||||
argTypes: {
|
|
||||||
onEnter: { control: false },
|
|
||||||
onEscape: { control: false },
|
|
||||||
onClickOutside: { control: false },
|
|
||||||
onTab: { control: false },
|
|
||||||
onShiftTab: { control: false },
|
|
||||||
},
|
|
||||||
decorators: [clearMocksDecorator, SnackBarDecorator],
|
|
||||||
parameters: {
|
|
||||||
clearMocks: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default meta;
|
|
||||||
|
|
||||||
type Story = StoryObj<typeof PhoneFieldInputWithContext>;
|
|
||||||
|
|
||||||
export const Default: Story = {};
|
|
||||||
|
|
||||||
export const Enter: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(enterJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{enter}');
|
|
||||||
expect(enterJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Escape: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(escapeJestfn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{esc}');
|
|
||||||
expect(escapeJestfn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ClickOutside: Story = {
|
|
||||||
play: async ({ canvasElement }) => {
|
|
||||||
const canvas = within(canvasElement);
|
|
||||||
|
|
||||||
expect(clickOutsideJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
const emptyDiv = canvas.getByTestId('data-field-input-click-outside-div');
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.click(emptyDiv);
|
|
||||||
expect(clickOutsideJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Tab: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(tabJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{tab}');
|
|
||||||
expect(tabJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ShiftTab: Story = {
|
|
||||||
play: async () => {
|
|
||||||
expect(shiftTabJestFn).toHaveBeenCalledTimes(0);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
|
||||||
userEvent.keyboard('{shift>}{tab}');
|
|
||||||
expect(shiftTabJestFn).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
@ -6,15 +6,12 @@ import {
|
|||||||
FieldCurrencyValue,
|
FieldCurrencyValue,
|
||||||
FieldDateTimeValue,
|
FieldDateTimeValue,
|
||||||
FieldEmailsValue,
|
FieldEmailsValue,
|
||||||
FieldEmailValue,
|
|
||||||
FieldFullNameValue,
|
FieldFullNameValue,
|
||||||
FieldJsonValue,
|
FieldJsonValue,
|
||||||
FieldLinksValue,
|
FieldLinksValue,
|
||||||
FieldLinkValue,
|
|
||||||
FieldMultiSelectValue,
|
FieldMultiSelectValue,
|
||||||
FieldNumberValue,
|
FieldNumberValue,
|
||||||
FieldPhonesValue,
|
FieldPhonesValue,
|
||||||
FieldPhoneValue,
|
|
||||||
FieldRatingValue,
|
FieldRatingValue,
|
||||||
FieldRelationFromManyValue,
|
FieldRelationFromManyValue,
|
||||||
FieldRelationToOneValue,
|
FieldRelationToOneValue,
|
||||||
@ -27,13 +24,11 @@ import {
|
|||||||
export type FieldTextDraftValue = string;
|
export type FieldTextDraftValue = string;
|
||||||
export type FieldNumberDraftValue = number;
|
export type FieldNumberDraftValue = number;
|
||||||
export type FieldDateTimeDraftValue = string;
|
export type FieldDateTimeDraftValue = string;
|
||||||
export type FieldPhoneDraftValue = string;
|
|
||||||
export type FieldPhonesDraftValue = {
|
export type FieldPhonesDraftValue = {
|
||||||
primaryPhoneNumber: string;
|
primaryPhoneNumber: string;
|
||||||
primaryPhoneCountryCode: string;
|
primaryPhoneCountryCode: string;
|
||||||
additionalPhones?: PhoneRecord[] | null;
|
additionalPhones?: PhoneRecord[] | null;
|
||||||
};
|
};
|
||||||
export type FieldEmailDraftValue = string;
|
|
||||||
export type FieldEmailsDraftValue = {
|
export type FieldEmailsDraftValue = {
|
||||||
primaryEmail: string;
|
primaryEmail: string;
|
||||||
additionalEmails: string[] | null;
|
additionalEmails: string[] | null;
|
||||||
@ -42,7 +37,6 @@ export type FieldSelectDraftValue = string;
|
|||||||
export type FieldMultiSelectDraftValue = string[];
|
export type FieldMultiSelectDraftValue = string[];
|
||||||
export type FieldRelationDraftValue = string;
|
export type FieldRelationDraftValue = string;
|
||||||
export type FieldRelationManyDraftValue = string[];
|
export type FieldRelationManyDraftValue = string[];
|
||||||
export type FieldLinkDraftValue = { url: string; label: string };
|
|
||||||
export type FieldLinksDraftValue = {
|
export type FieldLinksDraftValue = {
|
||||||
primaryLinkLabel: string;
|
primaryLinkLabel: string;
|
||||||
primaryLinkUrl: string;
|
primaryLinkUrl: string;
|
||||||
@ -80,36 +74,30 @@ export type FieldInputDraftValue<FieldValue> = FieldValue extends FieldTextValue
|
|||||||
? FieldNumberDraftValue
|
? FieldNumberDraftValue
|
||||||
: FieldValue extends FieldBooleanValue
|
: FieldValue extends FieldBooleanValue
|
||||||
? FieldBooleanValue
|
? FieldBooleanValue
|
||||||
: FieldValue extends FieldPhoneValue
|
: FieldValue extends FieldPhonesValue
|
||||||
? FieldPhoneDraftValue
|
? FieldPhonesDraftValue
|
||||||
: FieldValue extends FieldPhonesValue
|
: FieldValue extends FieldEmailsValue
|
||||||
? FieldPhonesDraftValue
|
? FieldEmailsDraftValue
|
||||||
: FieldValue extends FieldEmailValue
|
: FieldValue extends FieldLinksValue
|
||||||
? FieldEmailDraftValue
|
? FieldLinksDraftValue
|
||||||
: FieldValue extends FieldEmailsValue
|
: FieldValue extends FieldCurrencyValue
|
||||||
? FieldEmailsDraftValue
|
? FieldCurrencyDraftValue
|
||||||
: FieldValue extends FieldLinkValue
|
: FieldValue extends FieldFullNameValue
|
||||||
? FieldLinkDraftValue
|
? FieldFullNameDraftValue
|
||||||
: FieldValue extends FieldLinksValue
|
: FieldValue extends FieldRatingValue
|
||||||
? FieldLinksDraftValue
|
? FieldRatingValue
|
||||||
: FieldValue extends FieldCurrencyValue
|
: FieldValue extends FieldSelectValue
|
||||||
? FieldCurrencyDraftValue
|
? FieldSelectDraftValue
|
||||||
: FieldValue extends FieldFullNameValue
|
: FieldValue extends FieldMultiSelectValue
|
||||||
? FieldFullNameDraftValue
|
? FieldMultiSelectDraftValue
|
||||||
: FieldValue extends FieldRatingValue
|
: FieldValue extends FieldRelationToOneValue
|
||||||
? FieldRatingValue
|
? FieldRelationDraftValue
|
||||||
: FieldValue extends FieldSelectValue
|
: FieldValue extends FieldRelationFromManyValue
|
||||||
? FieldSelectDraftValue
|
? FieldRelationManyDraftValue
|
||||||
: FieldValue extends FieldMultiSelectValue
|
: FieldValue extends FieldAddressValue
|
||||||
? FieldMultiSelectDraftValue
|
? FieldAddressDraftValue
|
||||||
: FieldValue extends FieldRelationToOneValue
|
: FieldValue extends FieldJsonValue
|
||||||
? FieldRelationDraftValue
|
? FieldJsonDraftValue
|
||||||
: FieldValue extends FieldRelationFromManyValue
|
: FieldValue extends FieldActorValue
|
||||||
? FieldRelationManyDraftValue
|
? FieldActorDraftValue
|
||||||
: FieldValue extends FieldAddressValue
|
: never;
|
||||||
? FieldAddressDraftValue
|
|
||||||
: FieldValue extends FieldJsonValue
|
|
||||||
? FieldJsonDraftValue
|
|
||||||
: FieldValue extends FieldActorValue
|
|
||||||
? FieldActorDraftValue
|
|
||||||
: never;
|
|
||||||
|
|||||||
@ -183,13 +183,10 @@ export type FieldDateValue = string | null;
|
|||||||
export type FieldNumberValue = number | null;
|
export type FieldNumberValue = number | null;
|
||||||
export type FieldBooleanValue = boolean;
|
export type FieldBooleanValue = boolean;
|
||||||
|
|
||||||
export type FieldPhoneValue = string;
|
|
||||||
export type FieldEmailValue = string;
|
|
||||||
export type FieldEmailsValue = {
|
export type FieldEmailsValue = {
|
||||||
primaryEmail: string;
|
primaryEmail: string;
|
||||||
additionalEmails: string[] | null;
|
additionalEmails: string[] | null;
|
||||||
};
|
};
|
||||||
export type FieldLinkValue = { url: string; label: string };
|
|
||||||
export type FieldLinksValue = {
|
export type FieldLinksValue = {
|
||||||
primaryLinkLabel: string;
|
primaryLinkLabel: string;
|
||||||
primaryLinkUrl: string;
|
primaryLinkUrl: string;
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
||||||
|
|
||||||
import { FieldDefinition } from '../FieldDefinition';
|
|
||||||
import { FieldEmailMetadata, FieldMetadata } from '../FieldMetadata';
|
|
||||||
|
|
||||||
export const isFieldEmail = (
|
|
||||||
field: Pick<FieldDefinition<FieldMetadata>, 'type'>,
|
|
||||||
): field is FieldDefinition<FieldEmailMetadata> =>
|
|
||||||
field.type === FieldMetadataType.Email;
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { isString } from '@sniptt/guards';
|
|
||||||
|
|
||||||
import { FieldEmailValue } from '../FieldMetadata';
|
|
||||||
|
|
||||||
// TODO: add zod
|
|
||||||
export const isFieldEmailValue = (
|
|
||||||
fieldValue: unknown,
|
|
||||||
): fieldValue is FieldEmailValue => isString(fieldValue);
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
||||||
|
|
||||||
import { FieldDefinition } from '../FieldDefinition';
|
|
||||||
import { FieldLinkMetadata, FieldMetadata } from '../FieldMetadata';
|
|
||||||
|
|
||||||
export const isFieldLink = (
|
|
||||||
field: Pick<FieldDefinition<FieldMetadata>, 'type'>,
|
|
||||||
): field is FieldDefinition<FieldLinkMetadata> =>
|
|
||||||
field.type === FieldMetadataType.Link;
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { FieldLinkValue } from '../FieldMetadata';
|
|
||||||
|
|
||||||
const linkSchema = z.object({
|
|
||||||
url: z.string(),
|
|
||||||
label: z.string(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const isFieldLinkValue = (
|
|
||||||
fieldValue: unknown,
|
|
||||||
): fieldValue is FieldLinkValue => linkSchema.safeParse(fieldValue).success;
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
|
||||||
|
|
||||||
import { FieldDefinition } from '../FieldDefinition';
|
|
||||||
import { FieldMetadata, FieldPhoneMetadata } from '../FieldMetadata';
|
|
||||||
|
|
||||||
export const isFieldPhone = (
|
|
||||||
field: Pick<FieldDefinition<FieldMetadata>, 'type'>,
|
|
||||||
): field is FieldDefinition<FieldPhoneMetadata> =>
|
|
||||||
field.type === FieldMetadataType.Phone;
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { isString } from '@sniptt/guards';
|
|
||||||
|
|
||||||
import { FieldPhoneValue } from '../FieldMetadata';
|
|
||||||
|
|
||||||
// TODO: add zod
|
|
||||||
export const isFieldPhoneValue = (
|
|
||||||
fieldValue: unknown,
|
|
||||||
): fieldValue is FieldPhoneValue => isString(fieldValue);
|
|
||||||
@ -2,7 +2,6 @@ import {
|
|||||||
booleanFieldDefinition,
|
booleanFieldDefinition,
|
||||||
fieldMetadataId,
|
fieldMetadataId,
|
||||||
fullNameFieldDefinition,
|
fullNameFieldDefinition,
|
||||||
linkFieldDefinition,
|
|
||||||
relationFieldDefinition,
|
relationFieldDefinition,
|
||||||
selectFieldDefinition,
|
selectFieldDefinition,
|
||||||
} from '@/object-record/record-field/__mocks__/fieldDefinitions';
|
} from '@/object-record/record-field/__mocks__/fieldDefinitions';
|
||||||
@ -101,19 +100,4 @@ describe('isFieldValueEmpty', () => {
|
|||||||
}),
|
}),
|
||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return correct value for link field', () => {
|
|
||||||
expect(
|
|
||||||
isFieldValueEmpty({
|
|
||||||
fieldDefinition: linkFieldDefinition,
|
|
||||||
fieldValue: { url: '', label: '' },
|
|
||||||
}),
|
|
||||||
).toBe(true);
|
|
||||||
expect(
|
|
||||||
isFieldValueEmpty({
|
|
||||||
fieldDefinition: linkFieldDefinition,
|
|
||||||
fieldValue: { url: 'https://linkedin.com/user-slug', label: '' },
|
|
||||||
}),
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,10 +5,8 @@ import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'
|
|||||||
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
|
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
|
||||||
import { isFieldCurrency } from '@/object-record/record-field/types/guards/isFieldCurrency';
|
import { isFieldCurrency } from '@/object-record/record-field/types/guards/isFieldCurrency';
|
||||||
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
||||||
import { isFieldEmail } from '@/object-record/record-field/types/guards/isFieldEmail';
|
|
||||||
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
||||||
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
||||||
import { isFieldLink } from '@/object-record/record-field/types/guards/isFieldLink';
|
|
||||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||||
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
||||||
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
||||||
@ -33,14 +31,10 @@ export const computeDraftValueFromString = <FieldValue>({
|
|||||||
isFieldText(fieldDefinition) ||
|
isFieldText(fieldDefinition) ||
|
||||||
isFieldDateTime(fieldDefinition) ||
|
isFieldDateTime(fieldDefinition) ||
|
||||||
isFieldNumber(fieldDefinition) ||
|
isFieldNumber(fieldDefinition) ||
|
||||||
isFieldEmail(fieldDefinition) ||
|
|
||||||
isFieldRelation(fieldDefinition)
|
isFieldRelation(fieldDefinition)
|
||||||
) {
|
) {
|
||||||
return value as FieldInputDraftValue<FieldValue>;
|
return value as FieldInputDraftValue<FieldValue>;
|
||||||
}
|
}
|
||||||
if (isFieldLink(fieldDefinition)) {
|
|
||||||
return { url: value, label: value } as FieldInputDraftValue<FieldValue>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFieldCurrency(fieldDefinition)) {
|
if (isFieldCurrency(fieldDefinition)) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata'
|
|||||||
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
|
import { isFieldAddress } from '@/object-record/record-field/types/guards/isFieldAddress';
|
||||||
import { isFieldCurrency } from '@/object-record/record-field/types/guards/isFieldCurrency';
|
import { isFieldCurrency } from '@/object-record/record-field/types/guards/isFieldCurrency';
|
||||||
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
||||||
import { isFieldEmail } from '@/object-record/record-field/types/guards/isFieldEmail';
|
|
||||||
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
||||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||||
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
||||||
@ -27,7 +26,6 @@ export const computeEmptyDraftValue = <FieldValue>({
|
|||||||
isFieldText(fieldDefinition) ||
|
isFieldText(fieldDefinition) ||
|
||||||
isFieldDateTime(fieldDefinition) ||
|
isFieldDateTime(fieldDefinition) ||
|
||||||
isFieldNumber(fieldDefinition) ||
|
isFieldNumber(fieldDefinition) ||
|
||||||
isFieldEmail(fieldDefinition) ||
|
|
||||||
isFieldRelation(fieldDefinition) ||
|
isFieldRelation(fieldDefinition) ||
|
||||||
isFieldRawJson(fieldDefinition)
|
isFieldRawJson(fieldDefinition)
|
||||||
) {
|
) {
|
||||||
|
|||||||
@ -11,9 +11,6 @@ import { isFieldRelation } from '@/object-record/record-field/types/guards/isFie
|
|||||||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';
|
||||||
|
|
||||||
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
|
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray';
|
||||||
import { isFieldEmail } from '../types/guards/isFieldEmail';
|
|
||||||
import { isFieldLink } from '../types/guards/isFieldLink';
|
|
||||||
import { isFieldPhone } from '../types/guards/isFieldPhone';
|
|
||||||
|
|
||||||
export const getFieldButtonIcon = (
|
export const getFieldButtonIcon = (
|
||||||
fieldDefinition:
|
fieldDefinition:
|
||||||
@ -24,9 +21,6 @@ export const getFieldButtonIcon = (
|
|||||||
if (isUndefinedOrNull(fieldDefinition)) return undefined;
|
if (isUndefinedOrNull(fieldDefinition)) return undefined;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isFieldLink(fieldDefinition) ||
|
|
||||||
isFieldEmail(fieldDefinition) ||
|
|
||||||
isFieldPhone(fieldDefinition) ||
|
|
||||||
isFieldDisplayedAsPhone(fieldDefinition) ||
|
isFieldDisplayedAsPhone(fieldDefinition) ||
|
||||||
isFieldMultiSelect(fieldDefinition) ||
|
isFieldMultiSelect(fieldDefinition) ||
|
||||||
(isFieldRelation(fieldDefinition) &&
|
(isFieldRelation(fieldDefinition) &&
|
||||||
|
|||||||
@ -13,19 +13,15 @@ import { isFieldCurrency } from '@/object-record/record-field/types/guards/isFie
|
|||||||
import { isFieldCurrencyValue } from '@/object-record/record-field/types/guards/isFieldCurrencyValue';
|
import { isFieldCurrencyValue } from '@/object-record/record-field/types/guards/isFieldCurrencyValue';
|
||||||
import { isFieldDate } from '@/object-record/record-field/types/guards/isFieldDate';
|
import { isFieldDate } from '@/object-record/record-field/types/guards/isFieldDate';
|
||||||
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
import { isFieldDateTime } from '@/object-record/record-field/types/guards/isFieldDateTime';
|
||||||
import { isFieldEmail } from '@/object-record/record-field/types/guards/isFieldEmail';
|
|
||||||
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails';
|
||||||
import { isFieldEmailsValue } from '@/object-record/record-field/types/guards/isFieldEmailsValue';
|
import { isFieldEmailsValue } from '@/object-record/record-field/types/guards/isFieldEmailsValue';
|
||||||
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
|
||||||
import { isFieldFullNameValue } from '@/object-record/record-field/types/guards/isFieldFullNameValue';
|
import { isFieldFullNameValue } from '@/object-record/record-field/types/guards/isFieldFullNameValue';
|
||||||
import { isFieldLink } from '@/object-record/record-field/types/guards/isFieldLink';
|
|
||||||
import { isFieldLinkValue } from '@/object-record/record-field/types/guards/isFieldLinkValue';
|
|
||||||
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
import { isFieldLinks } from '@/object-record/record-field/types/guards/isFieldLinks';
|
||||||
import { isFieldLinksValue } from '@/object-record/record-field/types/guards/isFieldLinksValue';
|
import { isFieldLinksValue } from '@/object-record/record-field/types/guards/isFieldLinksValue';
|
||||||
import { isFieldMultiSelect } from '@/object-record/record-field/types/guards/isFieldMultiSelect';
|
import { isFieldMultiSelect } from '@/object-record/record-field/types/guards/isFieldMultiSelect';
|
||||||
import { isFieldMultiSelectValue } from '@/object-record/record-field/types/guards/isFieldMultiSelectValue';
|
import { isFieldMultiSelectValue } from '@/object-record/record-field/types/guards/isFieldMultiSelectValue';
|
||||||
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
|
||||||
import { isFieldPhone } from '@/object-record/record-field/types/guards/isFieldPhone';
|
|
||||||
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
import { isFieldPhones } from '@/object-record/record-field/types/guards/isFieldPhones';
|
||||||
import { isFieldPhonesValue } from '@/object-record/record-field/types/guards/isFieldPhonesValue';
|
import { isFieldPhonesValue } from '@/object-record/record-field/types/guards/isFieldPhonesValue';
|
||||||
import { isFieldPosition } from '@/object-record/record-field/types/guards/isFieldPosition';
|
import { isFieldPosition } from '@/object-record/record-field/types/guards/isFieldPosition';
|
||||||
@ -60,12 +56,10 @@ export const isFieldValueEmpty = ({
|
|||||||
isFieldDate(fieldDefinition) ||
|
isFieldDate(fieldDefinition) ||
|
||||||
isFieldNumber(fieldDefinition) ||
|
isFieldNumber(fieldDefinition) ||
|
||||||
isFieldRating(fieldDefinition) ||
|
isFieldRating(fieldDefinition) ||
|
||||||
isFieldEmail(fieldDefinition) ||
|
|
||||||
isFieldBoolean(fieldDefinition) ||
|
isFieldBoolean(fieldDefinition) ||
|
||||||
isFieldRelation(fieldDefinition) ||
|
isFieldRelation(fieldDefinition) ||
|
||||||
isFieldRawJson(fieldDefinition) ||
|
isFieldRawJson(fieldDefinition) ||
|
||||||
isFieldRichText(fieldDefinition) ||
|
isFieldRichText(fieldDefinition) ||
|
||||||
isFieldPhone(fieldDefinition) ||
|
|
||||||
isFieldPosition(fieldDefinition)
|
isFieldPosition(fieldDefinition)
|
||||||
) {
|
) {
|
||||||
return isValueEmpty(fieldValue);
|
return isValueEmpty(fieldValue);
|
||||||
@ -101,10 +95,6 @@ export const isFieldValueEmpty = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFieldLink(fieldDefinition)) {
|
|
||||||
return !isFieldLinkValue(fieldValue) || isValueEmpty(fieldValue?.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isFieldAddress(fieldDefinition)) {
|
if (isFieldAddress(fieldDefinition)) {
|
||||||
return (
|
return (
|
||||||
!isFieldAddressValue(fieldValue) ||
|
!isFieldAddressValue(fieldValue) ||
|
||||||
|
|||||||
@ -32,8 +32,6 @@ export const applyEmptyFilters = (
|
|||||||
|
|
||||||
switch (definition.type) {
|
switch (definition.type) {
|
||||||
case 'TEXT':
|
case 'TEXT':
|
||||||
case 'EMAIL':
|
|
||||||
case 'PHONE':
|
|
||||||
emptyRecordFilter = {
|
emptyRecordFilter = {
|
||||||
or: [
|
or: [
|
||||||
{ [correspondingField.name]: { ilike: '' } as StringFilter },
|
{ [correspondingField.name]: { ilike: '' } as StringFilter },
|
||||||
@ -113,16 +111,6 @@ export const applyEmptyFilters = (
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'LINK':
|
|
||||||
emptyRecordFilter = {
|
|
||||||
or: [
|
|
||||||
{ [correspondingField.name]: { url: { ilike: '' } } as URLFilter },
|
|
||||||
{
|
|
||||||
[correspondingField.name]: { url: { is: 'NULL' } } as URLFilter,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case 'LINKS': {
|
case 'LINKS': {
|
||||||
if (!isCompositeField) {
|
if (!isCompositeField) {
|
||||||
const linksFilters = generateILikeFiltersForCompositeFields(
|
const linksFilters = generateILikeFiltersForCompositeFields(
|
||||||
|
|||||||
@ -17,7 +17,6 @@ import {
|
|||||||
PhonesFilter,
|
PhonesFilter,
|
||||||
RecordGqlOperationFilter,
|
RecordGqlOperationFilter,
|
||||||
StringFilter,
|
StringFilter,
|
||||||
URLFilter,
|
|
||||||
UUIDFilter,
|
UUIDFilter,
|
||||||
} from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
} from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
||||||
import { isMatchingBooleanFilter } from '@/object-record/record-filter/utils/isMatchingBooleanFilter';
|
import { isMatchingBooleanFilter } from '@/object-record/record-filter/utils/isMatchingBooleanFilter';
|
||||||
@ -144,8 +143,6 @@ export const isRecordMatchingFilter = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (objectMetadataField.type) {
|
switch (objectMetadataField.type) {
|
||||||
case FieldMetadataType.Email:
|
|
||||||
case FieldMetadataType.Phone:
|
|
||||||
case FieldMetadataType.Select:
|
case FieldMetadataType.Select:
|
||||||
case FieldMetadataType.Rating:
|
case FieldMetadataType.Rating:
|
||||||
case FieldMetadataType.MultiSelect:
|
case FieldMetadataType.MultiSelect:
|
||||||
@ -155,22 +152,6 @@ export const isRecordMatchingFilter = ({
|
|||||||
value: record[filterKey],
|
value: record[filterKey],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case FieldMetadataType.Link: {
|
|
||||||
const urlFilter = filterValue as URLFilter;
|
|
||||||
|
|
||||||
return (
|
|
||||||
(urlFilter.url === undefined ||
|
|
||||||
isMatchingStringFilter({
|
|
||||||
stringFilter: urlFilter.url,
|
|
||||||
value: record[filterKey].url,
|
|
||||||
})) &&
|
|
||||||
(urlFilter.label === undefined ||
|
|
||||||
isMatchingStringFilter({
|
|
||||||
stringFilter: urlFilter.label,
|
|
||||||
value: record[filterKey].label,
|
|
||||||
}))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
case FieldMetadataType.FullName: {
|
case FieldMetadataType.FullName: {
|
||||||
const fullNameFilter = filterValue as FullNameFilter;
|
const fullNameFilter = filterValue as FullNameFilter;
|
||||||
|
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import {
|
|||||||
RecordGqlOperationFilter,
|
RecordGqlOperationFilter,
|
||||||
RelationFilter,
|
RelationFilter,
|
||||||
StringFilter,
|
StringFilter,
|
||||||
URLFilter,
|
|
||||||
UUIDFilter,
|
UUIDFilter,
|
||||||
} from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
} from '@/object-record/graphql/types/RecordGqlOperationFilter';
|
||||||
import { makeAndFilterVariables } from '@/object-record/utils/makeAndFilterVariables';
|
import { makeAndFilterVariables } from '@/object-record/utils/makeAndFilterVariables';
|
||||||
@ -388,43 +387,6 @@ export const turnObjectDropdownFilterIntoQueryFilter = (
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'LINK':
|
|
||||||
switch (rawUIFilter.operand) {
|
|
||||||
case ViewFilterOperand.Contains:
|
|
||||||
objectRecordFilters.push({
|
|
||||||
[correspondingField.name]: {
|
|
||||||
url: {
|
|
||||||
ilike: `%${rawUIFilter.value}%`,
|
|
||||||
},
|
|
||||||
} as URLFilter,
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case ViewFilterOperand.DoesNotContain:
|
|
||||||
objectRecordFilters.push({
|
|
||||||
not: {
|
|
||||||
[correspondingField.name]: {
|
|
||||||
url: {
|
|
||||||
ilike: `%${rawUIFilter.value}%`,
|
|
||||||
},
|
|
||||||
} as URLFilter,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
case ViewFilterOperand.IsEmpty:
|
|
||||||
case ViewFilterOperand.IsNotEmpty:
|
|
||||||
applyEmptyFilters(
|
|
||||||
rawUIFilter.operand,
|
|
||||||
correspondingField,
|
|
||||||
objectRecordFilters,
|
|
||||||
rawUIFilter.definition,
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error(
|
|
||||||
`Unknown operand ${rawUIFilter.operand} for ${rawUIFilter.definition.type} filter`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'LINKS': {
|
case 'LINKS': {
|
||||||
const linksFilters = generateILikeFiltersForCompositeFields(
|
const linksFilters = generateILikeFiltersForCompositeFields(
|
||||||
rawUIFilter.value,
|
rawUIFilter.value,
|
||||||
|
|||||||
@ -1,5 +1,3 @@
|
|||||||
import { isValidPhoneNumber } from 'libphonenumber-js';
|
|
||||||
|
|
||||||
import { FieldValidationDefinition } from '@/spreadsheet-import/types';
|
import { FieldValidationDefinition } from '@/spreadsheet-import/types';
|
||||||
import { isDefined } from 'twenty-ui';
|
import { isDefined } from 'twenty-ui';
|
||||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||||
@ -41,15 +39,6 @@ export const getSpreadSheetFieldValidationDefinitions = (
|
|||||||
level: 'error',
|
level: 'error',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
case FieldMetadataType.Phone:
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
rule: 'function',
|
|
||||||
isValid: (value: string) => isValidPhoneNumber(value),
|
|
||||||
errorMessage: fieldName + ' is not valid',
|
|
||||||
level: 'error',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
case FieldMetadataType.Relation:
|
case FieldMetadataType.Relation:
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -8,20 +8,12 @@ export const generateEmptyFieldValue = (
|
|||||||
fieldMetadataItem: Pick<FieldMetadataItem, 'type' | 'relationDefinition'>,
|
fieldMetadataItem: Pick<FieldMetadataItem, 'type' | 'relationDefinition'>,
|
||||||
) => {
|
) => {
|
||||||
switch (fieldMetadataItem.type) {
|
switch (fieldMetadataItem.type) {
|
||||||
case FieldMetadataType.Email:
|
|
||||||
case FieldMetadataType.Phone:
|
|
||||||
case FieldMetadataType.Text: {
|
case FieldMetadataType.Text: {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
case FieldMetadataType.Emails: {
|
case FieldMetadataType.Emails: {
|
||||||
return { primaryEmail: '', additionalEmails: null };
|
return { primaryEmail: '', additionalEmails: null };
|
||||||
}
|
}
|
||||||
case FieldMetadataType.Link: {
|
|
||||||
return {
|
|
||||||
label: '',
|
|
||||||
url: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case FieldMetadataType.Links: {
|
case FieldMetadataType.Links: {
|
||||||
return { primaryLinkUrl: '', primaryLinkLabel: '', secondaryLinks: null };
|
return { primaryLinkUrl: '', primaryLinkLabel: '', secondaryLinks: null };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import {
|
|||||||
FieldEmailsValue,
|
FieldEmailsValue,
|
||||||
FieldFullNameValue,
|
FieldFullNameValue,
|
||||||
FieldLinksValue,
|
FieldLinksValue,
|
||||||
FieldLinkValue,
|
|
||||||
FieldPhonesValue,
|
FieldPhonesValue,
|
||||||
} from '@/object-record/record-field/types/FieldMetadata';
|
} from '@/object-record/record-field/types/FieldMetadata';
|
||||||
import { SettingsFieldTypeConfig } from '@/settings/data-model/constants/SettingsNonCompositeFieldTypeConfigs';
|
import { SettingsFieldTypeConfig } from '@/settings/data-model/constants/SettingsNonCompositeFieldTypeConfigs';
|
||||||
@ -38,8 +37,8 @@ export const SETTINGS_COMPOSITE_FIELD_TYPE_CONFIGS = {
|
|||||||
[FieldMetadataType.Currency]: {
|
[FieldMetadataType.Currency]: {
|
||||||
label: 'Currency',
|
label: 'Currency',
|
||||||
Icon: IllustrationIconCurrency,
|
Icon: IllustrationIconCurrency,
|
||||||
subFields: ['amountMicros', 'currencyCode'],
|
subFields: ['amountMicros'],
|
||||||
filterableSubFields: ['amountMicros', 'currencyCode'],
|
filterableSubFields: ['amountMicros'],
|
||||||
labelBySubField: {
|
labelBySubField: {
|
||||||
amountMicros: 'Amount',
|
amountMicros: 'Amount',
|
||||||
currencyCode: 'Currency',
|
currencyCode: 'Currency',
|
||||||
@ -69,18 +68,6 @@ export const SETTINGS_COMPOSITE_FIELD_TYPE_CONFIGS = {
|
|||||||
},
|
},
|
||||||
category: 'Basic',
|
category: 'Basic',
|
||||||
} as const satisfies SettingsCompositeFieldTypeConfig<FieldEmailsValue>,
|
} as const satisfies SettingsCompositeFieldTypeConfig<FieldEmailsValue>,
|
||||||
[FieldMetadataType.Link]: {
|
|
||||||
label: 'Link',
|
|
||||||
Icon: IllustrationIconLink,
|
|
||||||
exampleValue: { url: 'www.twenty.com', label: '' },
|
|
||||||
category: 'Basic',
|
|
||||||
subFields: ['url', 'label'],
|
|
||||||
filterableSubFields: ['url', 'label'],
|
|
||||||
labelBySubField: {
|
|
||||||
url: 'URL',
|
|
||||||
label: 'Label',
|
|
||||||
},
|
|
||||||
} as const satisfies SettingsCompositeFieldTypeConfig<FieldLinkValue>,
|
|
||||||
[FieldMetadataType.Links]: {
|
[FieldMetadataType.Links]: {
|
||||||
label: 'Links',
|
label: 'Links',
|
||||||
Icon: IllustrationIconLink,
|
Icon: IllustrationIconLink,
|
||||||
@ -178,8 +165,8 @@ export const SETTINGS_COMPOSITE_FIELD_TYPE_CONFIGS = {
|
|||||||
label: 'Actor',
|
label: 'Actor',
|
||||||
Icon: IllustrationIconSetting,
|
Icon: IllustrationIconSetting,
|
||||||
category: 'Basic',
|
category: 'Basic',
|
||||||
subFields: ['source', 'name', 'workspaceMemberId'],
|
subFields: ['source'],
|
||||||
filterableSubFields: ['source', 'name', 'workspaceMemberId'],
|
filterableSubFields: ['source'],
|
||||||
labelBySubField: {
|
labelBySubField: {
|
||||||
source: 'Source',
|
source: 'Source',
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
|
|||||||
@ -4,10 +4,8 @@ import {
|
|||||||
IllustrationIconCalendarEvent,
|
IllustrationIconCalendarEvent,
|
||||||
IllustrationIconCalendarTime,
|
IllustrationIconCalendarTime,
|
||||||
IllustrationIconJson,
|
IllustrationIconJson,
|
||||||
IllustrationIconMail,
|
|
||||||
IllustrationIconNumbers,
|
IllustrationIconNumbers,
|
||||||
IllustrationIconOneToMany,
|
IllustrationIconOneToMany,
|
||||||
IllustrationIconPhone,
|
|
||||||
IllustrationIconSetting,
|
IllustrationIconSetting,
|
||||||
IllustrationIconStar,
|
IllustrationIconStar,
|
||||||
IllustrationIconTag,
|
IllustrationIconTag,
|
||||||
@ -22,11 +20,9 @@ import {
|
|||||||
FieldBooleanValue,
|
FieldBooleanValue,
|
||||||
FieldDateTimeValue,
|
FieldDateTimeValue,
|
||||||
FieldDateValue,
|
FieldDateValue,
|
||||||
FieldEmailValue,
|
|
||||||
FieldJsonValue,
|
FieldJsonValue,
|
||||||
FieldMultiSelectValue,
|
FieldMultiSelectValue,
|
||||||
FieldNumberValue,
|
FieldNumberValue,
|
||||||
FieldPhoneValue,
|
|
||||||
FieldRatingValue,
|
FieldRatingValue,
|
||||||
FieldRelationValue,
|
FieldRelationValue,
|
||||||
FieldRichTextValue,
|
FieldRichTextValue,
|
||||||
@ -114,17 +110,6 @@ export const SETTINGS_NON_COMPOSITE_FIELD_TYPE_CONFIGS: SettingsNonCompositeFiel
|
|||||||
Icon: IllustrationIconOneToMany,
|
Icon: IllustrationIconOneToMany,
|
||||||
category: 'Relation',
|
category: 'Relation',
|
||||||
} as const satisfies SettingsFieldTypeConfig<FieldRelationValue<any>>,
|
} as const satisfies SettingsFieldTypeConfig<FieldRelationValue<any>>,
|
||||||
[FieldMetadataType.Email]: {
|
|
||||||
label: 'Email',
|
|
||||||
Icon: IllustrationIconMail,
|
|
||||||
category: 'Basic',
|
|
||||||
} as const satisfies SettingsFieldTypeConfig<FieldEmailValue>,
|
|
||||||
[FieldMetadataType.Phone]: {
|
|
||||||
label: 'Phone',
|
|
||||||
Icon: IllustrationIconPhone,
|
|
||||||
exampleValue: '+1234-567-890',
|
|
||||||
category: 'Basic',
|
|
||||||
} as const satisfies SettingsFieldTypeConfig<FieldPhoneValue>,
|
|
||||||
[FieldMetadataType.Rating]: {
|
[FieldMetadataType.Rating]: {
|
||||||
label: 'Rating',
|
label: 'Rating',
|
||||||
Icon: IllustrationIconStar,
|
Icon: IllustrationIconStar,
|
||||||
|
|||||||
@ -113,11 +113,9 @@ const previewableTypes = [
|
|||||||
FieldMetadataType.DateTime,
|
FieldMetadataType.DateTime,
|
||||||
FieldMetadataType.Emails,
|
FieldMetadataType.Emails,
|
||||||
FieldMetadataType.FullName,
|
FieldMetadataType.FullName,
|
||||||
FieldMetadataType.Link,
|
|
||||||
FieldMetadataType.Links,
|
FieldMetadataType.Links,
|
||||||
FieldMetadataType.MultiSelect,
|
FieldMetadataType.MultiSelect,
|
||||||
FieldMetadataType.Number,
|
FieldMetadataType.Number,
|
||||||
FieldMetadataType.Phone,
|
|
||||||
FieldMetadataType.Phones,
|
FieldMetadataType.Phones,
|
||||||
FieldMetadataType.Rating,
|
FieldMetadataType.Rating,
|
||||||
FieldMetadataType.RawJson,
|
FieldMetadataType.RawJson,
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { PickLiteral } from '~/types/PickLiteral';
|
|||||||
export const COMPOSITE_FIELD_TYPES = [
|
export const COMPOSITE_FIELD_TYPES = [
|
||||||
'CURRENCY',
|
'CURRENCY',
|
||||||
'EMAILS',
|
'EMAILS',
|
||||||
'LINK',
|
|
||||||
'LINKS',
|
'LINKS',
|
||||||
'ADDRESS',
|
'ADDRESS',
|
||||||
'PHONES',
|
'PHONES',
|
||||||
|
|||||||
@ -43,13 +43,13 @@ export const SIGN_IN_BACKGROUND_MOCK_FILTER_DEFINITIONS = [
|
|||||||
fieldMetadataId: '20202020-a61d-4b78-b998-3fd88b4f73a1',
|
fieldMetadataId: '20202020-a61d-4b78-b998-3fd88b4f73a1',
|
||||||
label: 'Linkedin',
|
label: 'Linkedin',
|
||||||
iconName: 'IconBrandLinkedin',
|
iconName: 'IconBrandLinkedin',
|
||||||
type: 'LINK',
|
type: 'LINKS',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldMetadataId: '20202020-46e3-479a-b8f4-77137c74daa6',
|
fieldMetadataId: '20202020-46e3-479a-b8f4-77137c74daa6',
|
||||||
label: 'X',
|
label: 'X',
|
||||||
iconName: 'IconBrandX',
|
iconName: 'IconBrandX',
|
||||||
type: 'LINK',
|
type: 'LINKS',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldMetadataId: '20202020-4a5a-466f-92d9-c3870d9502a9',
|
fieldMetadataId: '20202020-4a5a-466f-92d9-c3870d9502a9',
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { isNonEmptyString } from '@sniptt/guards';
|
import { isNonEmptyString } from '@sniptt/guards';
|
||||||
|
|
||||||
import { FieldLinkValue } from '@/object-record/record-field/types/FieldMetadata';
|
|
||||||
import { RoundedLink } from '@/ui/navigation/link/components/RoundedLink';
|
import { RoundedLink } from '@/ui/navigation/link/components/RoundedLink';
|
||||||
import {
|
import {
|
||||||
LinkType,
|
LinkType,
|
||||||
@ -8,7 +7,7 @@ import {
|
|||||||
} from '@/ui/navigation/link/components/SocialLink';
|
} from '@/ui/navigation/link/components/SocialLink';
|
||||||
|
|
||||||
type LinkDisplayProps = {
|
type LinkDisplayProps = {
|
||||||
value?: FieldLinkValue;
|
value?: { url: string; label?: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const LinkDisplay = ({ value }: LinkDisplayProps) => {
|
export const LinkDisplay = ({ value }: LinkDisplayProps) => {
|
||||||
|
|||||||
@ -43,12 +43,9 @@ export const SettingsObjectNewFieldSelect = () => {
|
|||||||
});
|
});
|
||||||
const excludedFieldTypes: SettingsFieldType[] = (
|
const excludedFieldTypes: SettingsFieldType[] = (
|
||||||
[
|
[
|
||||||
FieldMetadataType.Link,
|
|
||||||
FieldMetadataType.Numeric,
|
FieldMetadataType.Numeric,
|
||||||
FieldMetadataType.RichText,
|
FieldMetadataType.RichText,
|
||||||
FieldMetadataType.Actor,
|
FieldMetadataType.Actor,
|
||||||
FieldMetadataType.Email,
|
|
||||||
FieldMetadataType.Phone,
|
|
||||||
] as const
|
] as const
|
||||||
).filter(isDefined);
|
).filter(isDefined);
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import { DataSeedDemoWorkspaceCommand } from 'src/database/commands/data-seed-de
|
|||||||
import { DataSeedDemoWorkspaceModule } from 'src/database/commands/data-seed-demo-workspace/data-seed-demo-workspace.module';
|
import { DataSeedDemoWorkspaceModule } from 'src/database/commands/data-seed-demo-workspace/data-seed-demo-workspace.module';
|
||||||
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-workspace.command';
|
import { DataSeedWorkspaceCommand } from 'src/database/commands/data-seed-dev-workspace.command';
|
||||||
import { ConfirmationQuestion } from 'src/database/commands/questions/confirmation.question';
|
import { ConfirmationQuestion } from 'src/database/commands/questions/confirmation.question';
|
||||||
import { UpgradeTo0_30CommandModule } from 'src/database/commands/upgrade-version/0-30/0-30-upgrade-version.module';
|
|
||||||
import { UpgradeTo0_31CommandModule } from 'src/database/commands/upgrade-version/0-31/0-31-upgrade-version.module';
|
import { UpgradeTo0_31CommandModule } from 'src/database/commands/upgrade-version/0-31/0-31-upgrade-version.module';
|
||||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
||||||
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
|
import { BillingSubscription } from 'src/engine/core-modules/billing/entities/billing-subscription.entity';
|
||||||
@ -47,7 +46,6 @@ import { WorkspaceSyncMetadataModule } from 'src/engine/workspace-manager/worksp
|
|||||||
DataSeedDemoWorkspaceModule,
|
DataSeedDemoWorkspaceModule,
|
||||||
WorkspaceCacheStorageModule,
|
WorkspaceCacheStorageModule,
|
||||||
WorkspaceMetadataVersionModule,
|
WorkspaceMetadataVersionModule,
|
||||||
UpgradeTo0_30CommandModule,
|
|
||||||
UpgradeTo0_31CommandModule,
|
UpgradeTo0_31CommandModule,
|
||||||
FeatureFlagModule,
|
FeatureFlagModule,
|
||||||
],
|
],
|
||||||
|
|||||||
@ -1,161 +0,0 @@
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import { isDefined } from 'class-validator';
|
|
||||||
import { Command } from 'nest-commander';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ActiveWorkspacesCommandOptions,
|
|
||||||
ActiveWorkspacesCommandRunner,
|
|
||||||
} from 'src/database/commands/active-workspaces.command';
|
|
||||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
|
||||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
|
||||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
||||||
import { ViewService } from 'src/modules/view/services/view.service';
|
|
||||||
@Command({
|
|
||||||
name: 'upgrade-0.30:fix-email-field-migration',
|
|
||||||
description:
|
|
||||||
'Fix migration - delete deprecated email fields and add emails to person views',
|
|
||||||
})
|
|
||||||
export class FixEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRunner {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Workspace, 'core')
|
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
|
||||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
|
||||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
|
||||||
private readonly fieldMetadataService: FieldMetadataService,
|
|
||||||
private readonly typeORMService: TypeORMService,
|
|
||||||
private readonly dataSourceService: DataSourceService,
|
|
||||||
private readonly viewService: ViewService,
|
|
||||||
) {
|
|
||||||
super(workspaceRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeActiveWorkspacesCommand(
|
|
||||||
_passedParam: string[],
|
|
||||||
_options: ActiveWorkspacesCommandOptions,
|
|
||||||
workspaceIds: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
this.logger.log('Running command to fix migration');
|
|
||||||
|
|
||||||
for (const workspaceId of workspaceIds) {
|
|
||||||
let dataSourceMetadata;
|
|
||||||
|
|
||||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
|
||||||
try {
|
|
||||||
dataSourceMetadata =
|
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!dataSourceMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspaceDataSource =
|
|
||||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
|
||||||
|
|
||||||
if (!workspaceDataSource) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not connect to dataSource for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Could not connect to workspace data source for workspace ${workspaceId}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const deprecatedPersonEmailFieldsMetadata =
|
|
||||||
await this.fieldMetadataRepository.findBy({
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.email,
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const migratedEmailFieldMetadata = await this.fieldMetadataRepository
|
|
||||||
.findBy({
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
})
|
|
||||||
.then((fields) => fields[0]);
|
|
||||||
|
|
||||||
const personEmailFieldWasMigratedButHasDuplicate =
|
|
||||||
deprecatedPersonEmailFieldsMetadata.length > 0 &&
|
|
||||||
isDefined(migratedEmailFieldMetadata);
|
|
||||||
|
|
||||||
if (!personEmailFieldWasMigratedButHasDuplicate) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.yellow('No fields to migrate for workspace ' + workspaceId),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const deprecatedEmailFieldMetadata of deprecatedPersonEmailFieldsMetadata) {
|
|
||||||
await this.fieldMetadataService.deleteOneField(
|
|
||||||
{ id: deprecatedEmailFieldMetadata.id },
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
this.logger.log(
|
|
||||||
chalk.green(`Deleted email field for workspace ${workspaceId}.`),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const personObjectMetadaIdForWorkspace =
|
|
||||||
migratedEmailFieldMetadata.objectMetadataId;
|
|
||||||
|
|
||||||
if (!isDefined(personObjectMetadaIdForWorkspace)) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Could not find person object for workspace ${workspaceId}. Could not add emails to person view`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const personViewsIds =
|
|
||||||
await this.viewService.getViewsIdsForObjectMetadataId({
|
|
||||||
workspaceId,
|
|
||||||
objectMetadataId: personObjectMetadaIdForWorkspace as string,
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.viewService.addFieldToViews({
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
fieldId: migratedEmailFieldMetadata.id,
|
|
||||||
viewsIds: personViewsIds,
|
|
||||||
positions: personViewsIds.reduce((acc, personView) => {
|
|
||||||
if (!personView.id) {
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
acc[personView.id] = 4;
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
}, []),
|
|
||||||
});
|
|
||||||
this.logger.log(chalk.green(`Added emails to view ${workspaceId}.`));
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
} finally {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.green(`Finished running command for workspace ${workspaceId}.`),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(chalk.green(`Command completed!`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,110 +0,0 @@
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import { Command } from 'nest-commander';
|
|
||||||
import { Any, Repository } from 'typeorm';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ActiveWorkspacesCommandOptions,
|
|
||||||
ActiveWorkspacesCommandRunner,
|
|
||||||
} from 'src/database/commands/active-workspaces.command';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
|
||||||
import {
|
|
||||||
FieldMetadataEntity,
|
|
||||||
FieldMetadataType,
|
|
||||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
|
||||||
import { ViewFilterWorkspaceEntity } from 'src/modules/view/standard-objects/view-filter.workspace-entity';
|
|
||||||
|
|
||||||
@Command({
|
|
||||||
name: 'upgrade-0.30:fix-view-filter-operand-for-date-time',
|
|
||||||
description: 'Fix the view filter operand for date time fields',
|
|
||||||
})
|
|
||||||
export class FixViewFilterOperandForDateTimeCommand extends ActiveWorkspacesCommandRunner {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Workspace, 'core')
|
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
|
||||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
|
||||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
|
||||||
private readonly dataSourceService: DataSourceService,
|
|
||||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
|
||||||
) {
|
|
||||||
super(workspaceRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeActiveWorkspacesCommand(
|
|
||||||
_passedParam: string[],
|
|
||||||
_options: ActiveWorkspacesCommandOptions,
|
|
||||||
workspaceIds: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
for (const workspaceId of workspaceIds) {
|
|
||||||
try {
|
|
||||||
const dataSourceMetadata =
|
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!dataSourceMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const viewFilterRepository =
|
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewFilterWorkspaceEntity>(
|
|
||||||
workspaceId,
|
|
||||||
'viewFilter',
|
|
||||||
);
|
|
||||||
|
|
||||||
const dateTimeFieldMetadata = await this.fieldMetadataRepository.find({
|
|
||||||
where: {
|
|
||||||
workspaceId,
|
|
||||||
type: FieldMetadataType.DATE_TIME,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const dateTimeFieldMetadataIds = dateTimeFieldMetadata.map(
|
|
||||||
(fieldMetadata) => fieldMetadata.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
const lessThanUpdatedResult = await viewFilterRepository.update(
|
|
||||||
{
|
|
||||||
operand: 'lessThan',
|
|
||||||
fieldMetadataId: Any(dateTimeFieldMetadataIds),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
operand: 'isBefore',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const greaterThanUpdatedResult = await viewFilterRepository.update(
|
|
||||||
{
|
|
||||||
operand: 'greaterThan',
|
|
||||||
fieldMetadataId: Any(dateTimeFieldMetadataIds),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
operand: 'isAfter',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
this.logger.log(
|
|
||||||
`Updated ${(lessThanUpdatedResult.affected ?? 0) + (greaterThanUpdatedResult.affected ?? 0)} view filters for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Error running command for workspace ${workspaceId}: ${error}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
} finally {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.green(`Finished running command for workspace ${workspaceId}.`),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(chalk.green(`Command completed!`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,360 +0,0 @@
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import { Command } from 'nest-commander';
|
|
||||||
import { QueryRunner, Repository } from 'typeorm';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ActiveWorkspacesCommandOptions,
|
|
||||||
ActiveWorkspacesCommandRunner,
|
|
||||||
} from 'src/database/commands/active-workspaces.command';
|
|
||||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { DataSourceEntity } from 'src/engine/metadata-modules/data-source/data-source.entity';
|
|
||||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
|
||||||
import { CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
|
||||||
import {
|
|
||||||
FieldMetadataEntity,
|
|
||||||
FieldMetadataType,
|
|
||||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
|
||||||
import { computeTableName } from 'src/engine/utils/compute-table-name.util';
|
|
||||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
||||||
import { ViewService } from 'src/modules/view/services/view.service';
|
|
||||||
import { ViewFieldWorkspaceEntity } from 'src/modules/view/standard-objects/view-field.workspace-entity';
|
|
||||||
@Command({
|
|
||||||
name: 'upgrade-0.30:migrate-email-fields-to-emails',
|
|
||||||
description: 'Migrating fields of deprecated type EMAIL to type EMAILS',
|
|
||||||
})
|
|
||||||
export class MigrateEmailFieldsToEmailsCommand extends ActiveWorkspacesCommandRunner {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Workspace, 'core')
|
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
|
||||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
|
||||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
|
||||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
|
||||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
|
||||||
private readonly fieldMetadataService: FieldMetadataService,
|
|
||||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
|
||||||
private readonly typeORMService: TypeORMService,
|
|
||||||
private readonly dataSourceService: DataSourceService,
|
|
||||||
private readonly viewService: ViewService,
|
|
||||||
) {
|
|
||||||
super(workspaceRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeActiveWorkspacesCommand(
|
|
||||||
_passedParam: string[],
|
|
||||||
_options: ActiveWorkspacesCommandOptions,
|
|
||||||
workspaceIds: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
this.logger.log(
|
|
||||||
'Running command to migrate email type fields to emails type',
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const workspaceId of workspaceIds) {
|
|
||||||
let dataSourceMetadata;
|
|
||||||
let workspaceQueryRunner;
|
|
||||||
|
|
||||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
|
||||||
try {
|
|
||||||
dataSourceMetadata =
|
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!dataSourceMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const workspaceDataSource =
|
|
||||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
|
||||||
|
|
||||||
if (!workspaceDataSource) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not connect to dataSource for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
workspaceQueryRunner = workspaceDataSource.createQueryRunner();
|
|
||||||
|
|
||||||
await workspaceQueryRunner.connect();
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Could not connect to workspace data source for workspace ${workspaceId}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.migratePersonEmailFieldToEmailsField(
|
|
||||||
workspaceId,
|
|
||||||
workspaceQueryRunner,
|
|
||||||
dataSourceMetadata,
|
|
||||||
);
|
|
||||||
|
|
||||||
const customFieldsWithEmailType =
|
|
||||||
await this.fieldMetadataRepository.find({
|
|
||||||
where: {
|
|
||||||
workspaceId,
|
|
||||||
type: FieldMetadataType.EMAIL,
|
|
||||||
isCustom: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const customFieldWithEmailType of customFieldsWithEmailType) {
|
|
||||||
const objectMetadata = await this.objectMetadataRepository.findOne({
|
|
||||||
where: { id: customFieldWithEmailType.objectMetadataId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!objectMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find objectMetadata for field ${customFieldWithEmailType.name}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(
|
|
||||||
`Attempting to migrate custom field ${customFieldWithEmailType.name} on ${objectMetadata.nameSingular}.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
const fieldName = customFieldWithEmailType.name;
|
|
||||||
const { id: _id, ...fieldWithEmailTypeWithoutId } =
|
|
||||||
customFieldWithEmailType;
|
|
||||||
|
|
||||||
const emailDefaultValue = fieldWithEmailTypeWithoutId.defaultValue;
|
|
||||||
|
|
||||||
const defaultValueForEmailsField = {
|
|
||||||
primaryEmail: emailDefaultValue,
|
|
||||||
additionalEmails: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const tmpNewEmailsField = await this.fieldMetadataService.createOne(
|
|
||||||
{
|
|
||||||
...fieldWithEmailTypeWithoutId,
|
|
||||||
type: FieldMetadataType.EMAILS,
|
|
||||||
defaultValue: defaultValueForEmailsField,
|
|
||||||
name: `${fieldName}Tmp`,
|
|
||||||
} satisfies CreateFieldInput,
|
|
||||||
);
|
|
||||||
|
|
||||||
const tableName = computeTableName(
|
|
||||||
objectMetadata.nameSingular,
|
|
||||||
objectMetadata.isCustom,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Migrate data from email to emails.primaryEmail
|
|
||||||
await this.migrateDataWithinTable({
|
|
||||||
sourceColumnName: `${customFieldWithEmailType.name}`,
|
|
||||||
targetColumnName: `${tmpNewEmailsField.name}PrimaryEmail`,
|
|
||||||
tableName,
|
|
||||||
workspaceQueryRunner,
|
|
||||||
dataSourceMetadata,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Duplicate email field's views behaviour for new emails field
|
|
||||||
await this.viewService.removeFieldFromViews({
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
fieldId: tmpNewEmailsField.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
const viewFieldRepository =
|
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewFieldWorkspaceEntity>(
|
|
||||||
workspaceId,
|
|
||||||
'viewField',
|
|
||||||
);
|
|
||||||
const viewFieldsWithDeprecatedField =
|
|
||||||
await viewFieldRepository.find({
|
|
||||||
where: {
|
|
||||||
fieldMetadataId: customFieldWithEmailType.id,
|
|
||||||
isVisible: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.viewService.addFieldToViews({
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
fieldId: tmpNewEmailsField.id,
|
|
||||||
viewsIds: viewFieldsWithDeprecatedField
|
|
||||||
.filter((viewField) => viewField.viewId !== null)
|
|
||||||
.map((viewField) => viewField.viewId as string),
|
|
||||||
positions: viewFieldsWithDeprecatedField.reduce(
|
|
||||||
(acc, viewField) => {
|
|
||||||
if (!viewField.viewId) {
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
acc[viewField.viewId] = viewField.position;
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Delete email field
|
|
||||||
await this.fieldMetadataService.deleteOneField(
|
|
||||||
{ id: customFieldWithEmailType.id },
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Rename temporary emails field
|
|
||||||
await this.fieldMetadataService.updateOne(tmpNewEmailsField.id, {
|
|
||||||
id: tmpNewEmailsField.id,
|
|
||||||
workspaceId: tmpNewEmailsField.workspaceId,
|
|
||||||
name: `${fieldName}`,
|
|
||||||
isCustom: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.log(
|
|
||||||
`Migration of ${customFieldWithEmailType.name} on ${objectMetadata.nameSingular} done!`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
`Failed to migrate field ${customFieldWithEmailType.name} on ${objectMetadata.nameSingular}, rolling back.`,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Re-create initial field if it was deleted
|
|
||||||
const initialField =
|
|
||||||
await this.fieldMetadataService.findOneWithinWorkspace(
|
|
||||||
workspaceId,
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
name: `${customFieldWithEmailType.name}`,
|
|
||||||
objectMetadataId: customFieldWithEmailType.objectMetadataId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const tmpNewEmailsField =
|
|
||||||
await this.fieldMetadataService.findOneWithinWorkspace(
|
|
||||||
workspaceId,
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
name: `${customFieldWithEmailType.name}Tmp`,
|
|
||||||
objectMetadataId: customFieldWithEmailType.objectMetadataId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!initialField) {
|
|
||||||
this.logger.log(
|
|
||||||
`Re-creating initial Email field ${customFieldWithEmailType.name} but of type emails`, // Cannot create email fields anymore
|
|
||||||
);
|
|
||||||
const restoredField = await this.fieldMetadataService.createOne({
|
|
||||||
...customFieldWithEmailType,
|
|
||||||
defaultValue: defaultValueForEmailsField,
|
|
||||||
type: FieldMetadataType.EMAILS,
|
|
||||||
});
|
|
||||||
const tableName = computeTableName(
|
|
||||||
objectMetadata.nameSingular,
|
|
||||||
objectMetadata.isCustom,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (tmpNewEmailsField) {
|
|
||||||
this.logger.log(
|
|
||||||
`Restoring data in field ${customFieldWithEmailType.name}`,
|
|
||||||
);
|
|
||||||
await this.migrateDataWithinTable({
|
|
||||||
sourceColumnName: `${tmpNewEmailsField.name}PrimaryEmail`,
|
|
||||||
targetColumnName: `${restoredField.name}PrimaryEmail`,
|
|
||||||
tableName,
|
|
||||||
workspaceQueryRunner,
|
|
||||||
dataSourceMetadata,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.logger.log(
|
|
||||||
`Failed to restore data in link field ${customFieldWithEmailType.name}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tmpNewEmailsField) {
|
|
||||||
await this.fieldMetadataService.deleteOneField(
|
|
||||||
{ id: tmpNewEmailsField.id },
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
await workspaceQueryRunner.release();
|
|
||||||
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
} finally {
|
|
||||||
await workspaceQueryRunner.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(chalk.green(`Command completed!`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async migratePersonEmailFieldToEmailsField(
|
|
||||||
workspaceId: string,
|
|
||||||
workspaceQueryRunner: any,
|
|
||||||
dataSourceMetadata: any,
|
|
||||||
) {
|
|
||||||
this.logger.log(`Migrating person email field of type EMAIL to EMAILS`);
|
|
||||||
|
|
||||||
const personEmailFieldMetadata = await this.fieldMetadataRepository.findOne(
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
workspaceId,
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.email,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!personEmailFieldMetadata) {
|
|
||||||
this.logger.log(
|
|
||||||
`Could not find person email field with standardId ${PERSON_STANDARD_FIELD_IDS.email}, skipping migration`,
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.migrateDataWithinTable({
|
|
||||||
sourceColumnName: 'email',
|
|
||||||
targetColumnName: 'emailsPrimaryEmail',
|
|
||||||
tableName: 'person',
|
|
||||||
workspaceQueryRunner,
|
|
||||||
dataSourceMetadata,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (personEmailFieldMetadata) {
|
|
||||||
await this.fieldMetadataService.deleteOneField(
|
|
||||||
{
|
|
||||||
id: personEmailFieldMetadata.id,
|
|
||||||
},
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async migrateDataWithinTable({
|
|
||||||
sourceColumnName,
|
|
||||||
targetColumnName,
|
|
||||||
tableName,
|
|
||||||
workspaceQueryRunner,
|
|
||||||
dataSourceMetadata,
|
|
||||||
}: {
|
|
||||||
sourceColumnName: string;
|
|
||||||
targetColumnName: string;
|
|
||||||
tableName: string;
|
|
||||||
workspaceQueryRunner: QueryRunner;
|
|
||||||
dataSourceMetadata: DataSourceEntity;
|
|
||||||
}) {
|
|
||||||
await workspaceQueryRunner.query(
|
|
||||||
`UPDATE "${dataSourceMetadata.schema}"."${tableName}" SET "${targetColumnName}" = "${sourceColumnName}"`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,366 +0,0 @@
|
|||||||
import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import { isDefined, isEmpty } from 'class-validator';
|
|
||||||
import { parsePhoneNumber } from 'libphonenumber-js';
|
|
||||||
import { Command } from 'nest-commander';
|
|
||||||
import { DataSource, QueryRunner, Repository } from 'typeorm';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ActiveWorkspacesCommandOptions,
|
|
||||||
ActiveWorkspacesCommandRunner,
|
|
||||||
} from 'src/database/commands/active-workspaces.command';
|
|
||||||
import { TypeORMService } from 'src/database/typeorm/typeorm.service';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-source.service';
|
|
||||||
import { CreateFieldInput } from 'src/engine/metadata-modules/field-metadata/dtos/create-field.input';
|
|
||||||
import {
|
|
||||||
FieldMetadataEntity,
|
|
||||||
FieldMetadataType,
|
|
||||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
|
||||||
import { computeColumnName } from 'src/engine/metadata-modules/field-metadata/utils/compute-column-name.util';
|
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
|
||||||
import { computeTableName } from 'src/engine/utils/compute-table-name.util';
|
|
||||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
||||||
import { ViewService } from 'src/modules/view/services/view.service';
|
|
||||||
import { ViewFieldWorkspaceEntity } from 'src/modules/view/standard-objects/view-field.workspace-entity';
|
|
||||||
|
|
||||||
type MigratePhoneFieldsToPhonesCommandOptions = ActiveWorkspacesCommandOptions;
|
|
||||||
@Command({
|
|
||||||
name: 'upgrade-0.30:migrate-phone-fields-to-phones',
|
|
||||||
description: 'Migrating fields of deprecated type PHONE to type PHONES',
|
|
||||||
})
|
|
||||||
export class MigratePhoneFieldsToPhonesCommand extends ActiveWorkspacesCommandRunner {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Workspace, 'core')
|
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
|
||||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
|
||||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
|
||||||
@InjectRepository(ObjectMetadataEntity, 'metadata')
|
|
||||||
private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>,
|
|
||||||
@InjectDataSource('metadata')
|
|
||||||
private readonly metadataDataSource: DataSource,
|
|
||||||
private readonly fieldMetadataService: FieldMetadataService,
|
|
||||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
|
||||||
private readonly typeORMService: TypeORMService,
|
|
||||||
private readonly dataSourceService: DataSourceService,
|
|
||||||
private readonly viewService: ViewService,
|
|
||||||
) {
|
|
||||||
super(workspaceRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeActiveWorkspacesCommand(
|
|
||||||
_passedParam: string[],
|
|
||||||
_options: MigratePhoneFieldsToPhonesCommandOptions,
|
|
||||||
workspaceIds: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
this.logger.log(
|
|
||||||
'Running command to migrate phone type fields to phones type',
|
|
||||||
);
|
|
||||||
for (const workspaceId of workspaceIds) {
|
|
||||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
|
||||||
try {
|
|
||||||
const dataSourceMetadata =
|
|
||||||
await this.dataSourceService.getLastDataSourceMetadataFromWorkspaceId(
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!dataSourceMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find dataSourceMetadata for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const workspaceDataSource =
|
|
||||||
await this.typeORMService.connectToDataSource(dataSourceMetadata);
|
|
||||||
|
|
||||||
if (!workspaceDataSource) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not connect to dataSource for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const standardPersonPhoneFieldWithTextType =
|
|
||||||
await this.fieldMetadataRepository.findOneBy({
|
|
||||||
workspaceId,
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.phone,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!standardPersonPhoneFieldWithTextType) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find standard phone field on person for workspace ${workspaceId}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.migrateStandardPersonPhoneField({
|
|
||||||
standardPersonPhoneField: standardPersonPhoneFieldWithTextType,
|
|
||||||
workspaceDataSource,
|
|
||||||
workspaceSchemaName: dataSourceMetadata.schema,
|
|
||||||
});
|
|
||||||
|
|
||||||
const fieldsWithPhoneType = await this.fieldMetadataRepository.find({
|
|
||||||
where: {
|
|
||||||
workspaceId,
|
|
||||||
type: FieldMetadataType.PHONE,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
for (const deprecatedPhoneField of fieldsWithPhoneType) {
|
|
||||||
await this.migrateCustomPhoneField({
|
|
||||||
phoneField: deprecatedPhoneField,
|
|
||||||
workspaceDataSource,
|
|
||||||
workspaceSchemaName: dataSourceMetadata.schema,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Field migration on workspace ${workspaceId} failed with error: ${error}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
this.logger.log(chalk.green(`Command completed!`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async migrateStandardPersonPhoneField({
|
|
||||||
standardPersonPhoneField,
|
|
||||||
workspaceDataSource,
|
|
||||||
workspaceSchemaName,
|
|
||||||
}: {
|
|
||||||
standardPersonPhoneField: FieldMetadataEntity;
|
|
||||||
workspaceDataSource: DataSource;
|
|
||||||
workspaceSchemaName: string;
|
|
||||||
}) {
|
|
||||||
const personObjectMetadata = await this.objectMetadataRepository.findOne({
|
|
||||||
where: { id: standardPersonPhoneField.objectMetadataId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!personObjectMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find Person objectMetadata (id ${standardPersonPhoneField.objectMetadataId})`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(`Attempting to migrate standard person phone field.`);
|
|
||||||
const workspaceQueryRunner = workspaceDataSource.createQueryRunner();
|
|
||||||
|
|
||||||
await workspaceQueryRunner.connect();
|
|
||||||
const { id: _id, ...deprecatedPhoneFieldWithoutId } =
|
|
||||||
standardPersonPhoneField;
|
|
||||||
|
|
||||||
const workspaceId = standardPersonPhoneField.workspaceId;
|
|
||||||
|
|
||||||
try {
|
|
||||||
let standardPersonPhonesField =
|
|
||||||
await this.fieldMetadataRepository.findOneBy({
|
|
||||||
workspaceId,
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.phones,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!standardPersonPhonesField) {
|
|
||||||
standardPersonPhonesField = await this.fieldMetadataService.createOne({
|
|
||||||
...deprecatedPhoneFieldWithoutId,
|
|
||||||
label: 'Phones',
|
|
||||||
type: FieldMetadataType.PHONES,
|
|
||||||
defaultValue: null,
|
|
||||||
name: 'phones',
|
|
||||||
} satisfies CreateFieldInput);
|
|
||||||
|
|
||||||
// StandardId and isCustom are not exposed in CreateFieldInput
|
|
||||||
await this.metadataDataSource.query(
|
|
||||||
`UPDATE "metadata"."fieldMetadata" SET "standardId" = $1, "isCustom" = $2 where "id"=$3`,
|
|
||||||
[
|
|
||||||
PERSON_STANDARD_FIELD_IDS.phones,
|
|
||||||
'false',
|
|
||||||
standardPersonPhonesField.id,
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.viewService.removeFieldFromViews({
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
fieldId: standardPersonPhonesField.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy phone data from Text type to Phones type
|
|
||||||
await this.copyAndParseDeprecatedPhoneFieldDataIntoNewPhonesField({
|
|
||||||
workspaceQueryRunner,
|
|
||||||
workspaceSchemaName,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add (deprecated) to Phone field label
|
|
||||||
await this.metadataDataSource.query(
|
|
||||||
`UPDATE "metadata"."fieldMetadata" SET "label" = $1 where "id"=$2`,
|
|
||||||
['Phone (deprecated)', standardPersonPhoneField.id],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add new phones field to views and hide deprecated phone field
|
|
||||||
const viewFieldRepository =
|
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<ViewFieldWorkspaceEntity>(
|
|
||||||
workspaceId,
|
|
||||||
'viewField',
|
|
||||||
);
|
|
||||||
const viewFieldsWithDeprecatedPhoneField = await viewFieldRepository.find(
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
fieldMetadataId: standardPersonPhoneField.id,
|
|
||||||
isVisible: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.viewService.addFieldToViews({
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
fieldId: standardPersonPhonesField.id,
|
|
||||||
viewsIds: viewFieldsWithDeprecatedPhoneField
|
|
||||||
.filter((viewField) => viewField.viewId !== null)
|
|
||||||
.map((viewField) => viewField.viewId as string),
|
|
||||||
positions: viewFieldsWithDeprecatedPhoneField.reduce(
|
|
||||||
(acc, viewField) => {
|
|
||||||
if (!viewField.viewId) {
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
acc[viewField.viewId] = viewField.position;
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
[],
|
|
||||||
),
|
|
||||||
size: 150,
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.viewService.removeFieldFromViews({
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
fieldId: standardPersonPhoneField.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.logger.log(
|
|
||||||
`Migration of standard person phone field to phones is done!`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Failed to migrate field standard person phone field to phones, rolling back. (Error: ${error})`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete new phones field if it was created
|
|
||||||
const newPhonesField =
|
|
||||||
await this.fieldMetadataService.findOneWithinWorkspace(workspaceId, {
|
|
||||||
where: {
|
|
||||||
name: 'phones',
|
|
||||||
objectMetadataId: standardPersonPhoneField.objectMetadataId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (newPhonesField) {
|
|
||||||
this.logger.log(
|
|
||||||
`Deleting phones field of type Phone as part of rolling back.`,
|
|
||||||
);
|
|
||||||
await this.fieldMetadataService.deleteOneField(
|
|
||||||
{ id: newPhonesField.id },
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Revert Phone field label (remove (deprecated))
|
|
||||||
await this.metadataDataSource.query(
|
|
||||||
`UPDATE "metadata"."fieldMetadata" SET "label" = $1 where "id"=$2`,
|
|
||||||
['Phone', standardPersonPhoneField.id],
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
await workspaceQueryRunner.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async migrateCustomPhoneField({
|
|
||||||
phoneField,
|
|
||||||
workspaceDataSource,
|
|
||||||
workspaceSchemaName,
|
|
||||||
}: {
|
|
||||||
phoneField: FieldMetadataEntity;
|
|
||||||
workspaceDataSource: DataSource;
|
|
||||||
workspaceSchemaName: string;
|
|
||||||
}) {
|
|
||||||
if (!phoneField) return;
|
|
||||||
const objectMetadata = await this.objectMetadataRepository.findOne({
|
|
||||||
where: { id: phoneField.objectMetadataId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!objectMetadata) {
|
|
||||||
throw new Error(
|
|
||||||
`Could not find objectMetadata for field ${phoneField.name}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
this.logger.log(
|
|
||||||
`Attempting to migrate field ${phoneField.name} on ${objectMetadata.nameSingular} from Phone to Text.`,
|
|
||||||
);
|
|
||||||
const workspaceQueryRunner = workspaceDataSource.createQueryRunner();
|
|
||||||
|
|
||||||
await workspaceQueryRunner.connect();
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.metadataDataSource.query(
|
|
||||||
`UPDATE "metadata"."fieldMetadata" SET "type" = $1 where "id"=$2`,
|
|
||||||
[FieldMetadataType.TEXT, phoneField.id],
|
|
||||||
);
|
|
||||||
|
|
||||||
await workspaceQueryRunner.query(
|
|
||||||
`ALTER TABLE "${workspaceSchemaName}"."${computeTableName(objectMetadata.nameSingular, objectMetadata.isCustom)}" ALTER COLUMN "${computeColumnName(phoneField.name)}" TYPE TEXT`,
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Failed to migrate field ${phoneField.name} on ${objectMetadata.nameSingular} from Phone to Text.`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
await workspaceQueryRunner.release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async copyAndParseDeprecatedPhoneFieldDataIntoNewPhonesField({
|
|
||||||
workspaceQueryRunner,
|
|
||||||
workspaceSchemaName,
|
|
||||||
}: {
|
|
||||||
workspaceQueryRunner: QueryRunner;
|
|
||||||
workspaceSchemaName: string;
|
|
||||||
}) {
|
|
||||||
const deprecatedPhoneFieldRows = await workspaceQueryRunner.query(
|
|
||||||
`SELECT id, phone FROM "${workspaceSchemaName}"."person" WHERE
|
|
||||||
phone IS NOT null`,
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const row of deprecatedPhoneFieldRows) {
|
|
||||||
const phoneColumnValue = row['phone'];
|
|
||||||
|
|
||||||
if (isDefined(phoneColumnValue) && !isEmpty(phoneColumnValue)) {
|
|
||||||
const query = `UPDATE "${workspaceSchemaName}"."person" SET "phonesPrimaryPhoneCountryCode" = $1,"phonesPrimaryPhoneNumber" = $2 where "id"=$3 AND ("phonesPrimaryPhoneCountryCode" IS NULL OR "phonesPrimaryPhoneCountryCode" = '');`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const parsedPhoneColumnValue = parsePhoneNumber(phoneColumnValue);
|
|
||||||
|
|
||||||
await workspaceQueryRunner.query(query, [
|
|
||||||
`+${parsedPhoneColumnValue.countryCallingCode}`,
|
|
||||||
parsedPhoneColumnValue.nationalNumber,
|
|
||||||
row.id,
|
|
||||||
]);
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Could not save phone number ${phoneColumnValue}, will try again storing value as is without parsing, with default country code.`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Store the invalid string for invalid phone numbers
|
|
||||||
await workspaceQueryRunner.query(query, [
|
|
||||||
'',
|
|
||||||
phoneColumnValue,
|
|
||||||
row.id,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,90 +0,0 @@
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import chalk from 'chalk';
|
|
||||||
import { Command } from 'nest-commander';
|
|
||||||
import { IsNull, Repository } from 'typeorm';
|
|
||||||
|
|
||||||
import {
|
|
||||||
ActiveWorkspacesCommandOptions,
|
|
||||||
ActiveWorkspacesCommandRunner,
|
|
||||||
} from 'src/database/commands/active-workspaces.command';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
|
||||||
import {
|
|
||||||
MessageChannelSyncStage,
|
|
||||||
MessageChannelWorkspaceEntity,
|
|
||||||
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
|
|
||||||
@Command({
|
|
||||||
name: 'upgrade-0.30:set-stale-message-sync-back-to-pending',
|
|
||||||
description: 'Set stale message sync back to pending',
|
|
||||||
})
|
|
||||||
export class SetStaleMessageSyncBackToPendingCommand extends ActiveWorkspacesCommandRunner {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Workspace, 'core')
|
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
|
||||||
private readonly twentyORMGlobalManager: TwentyORMGlobalManager,
|
|
||||||
) {
|
|
||||||
super(workspaceRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeActiveWorkspacesCommand(
|
|
||||||
_passedParam: string[],
|
|
||||||
_options: ActiveWorkspacesCommandOptions,
|
|
||||||
workspaceIds: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
this.logger.log(
|
|
||||||
'Running command to set stale message sync back to pending',
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const workspaceId of workspaceIds) {
|
|
||||||
this.logger.log(`Running command for workspace ${workspaceId}`);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const dataSource =
|
|
||||||
await this.twentyORMGlobalManager.getDataSourceForWorkspace(
|
|
||||||
workspaceId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const messageChannelRepository =
|
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace<MessageChannelWorkspaceEntity>(
|
|
||||||
workspaceId,
|
|
||||||
'messageChannel',
|
|
||||||
);
|
|
||||||
|
|
||||||
dataSource.transaction(async (entityManager) => {
|
|
||||||
await messageChannelRepository.update(
|
|
||||||
{
|
|
||||||
syncStage: MessageChannelSyncStage.MESSAGES_IMPORT_ONGOING,
|
|
||||||
syncStageStartedAt: IsNull(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
syncStage: MessageChannelSyncStage.MESSAGES_IMPORT_PENDING,
|
|
||||||
},
|
|
||||||
entityManager,
|
|
||||||
);
|
|
||||||
|
|
||||||
await messageChannelRepository.update(
|
|
||||||
{
|
|
||||||
syncStage: MessageChannelSyncStage.MESSAGE_LIST_FETCH_ONGOING,
|
|
||||||
syncStageStartedAt: IsNull(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
syncStage:
|
|
||||||
MessageChannelSyncStage.PARTIAL_MESSAGE_LIST_FETCH_PENDING,
|
|
||||||
},
|
|
||||||
entityManager,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
this.logger.log(
|
|
||||||
chalk.red(
|
|
||||||
`Running command on workspace ${workspaceId} failed with error: ${error}`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.logger.log(chalk.green(`Command completed!`));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,76 +0,0 @@
|
|||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import { Command } from 'nest-commander';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
|
|
||||||
import { ActiveWorkspacesCommandRunner } from 'src/database/commands/active-workspaces.command';
|
|
||||||
import { FixEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-email-field-migration.command';
|
|
||||||
import { FixViewFilterOperandForDateTimeCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-view-filter-operand-for-date-time.command';
|
|
||||||
import { MigrateEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command';
|
|
||||||
import { MigratePhoneFieldsToPhonesCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-phone-fields-to-phones.command';
|
|
||||||
import { SetStaleMessageSyncBackToPendingCommand } from 'src/database/commands/upgrade-version/0-30/0-30-set-stale-message-sync-back-to-pending';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { SyncWorkspaceMetadataCommand } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/sync-workspace-metadata.command';
|
|
||||||
|
|
||||||
interface UpdateTo0_30CommandOptions {
|
|
||||||
workspaceId?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Command({
|
|
||||||
name: 'upgrade-0.30',
|
|
||||||
description: 'Upgrade to 0.30',
|
|
||||||
})
|
|
||||||
export class UpgradeTo0_30Command extends ActiveWorkspacesCommandRunner {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Workspace, 'core')
|
|
||||||
protected readonly workspaceRepository: Repository<Workspace>,
|
|
||||||
private readonly syncWorkspaceMetadataCommand: SyncWorkspaceMetadataCommand,
|
|
||||||
private readonly migrateEmailFieldsToEmails: MigrateEmailFieldsToEmailsCommand,
|
|
||||||
private readonly setStaleMessageSyncBackToPendingCommand: SetStaleMessageSyncBackToPendingCommand,
|
|
||||||
private readonly fixEmailFieldsToEmailsCommand: FixEmailFieldsToEmailsCommand,
|
|
||||||
private readonly migratePhoneFieldsToPhones: MigratePhoneFieldsToPhonesCommand,
|
|
||||||
private readonly fixViewFilterOperandForDateTimeCommand: FixViewFilterOperandForDateTimeCommand,
|
|
||||||
) {
|
|
||||||
super(workspaceRepository);
|
|
||||||
}
|
|
||||||
|
|
||||||
async executeActiveWorkspacesCommand(
|
|
||||||
passedParam: string[],
|
|
||||||
options: UpdateTo0_30CommandOptions,
|
|
||||||
workspaceIds: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
await this.syncWorkspaceMetadataCommand.executeActiveWorkspacesCommand(
|
|
||||||
passedParam,
|
|
||||||
{
|
|
||||||
...options,
|
|
||||||
force: true,
|
|
||||||
},
|
|
||||||
workspaceIds,
|
|
||||||
);
|
|
||||||
await this.migrateEmailFieldsToEmails.executeActiveWorkspacesCommand(
|
|
||||||
passedParam,
|
|
||||||
options,
|
|
||||||
workspaceIds,
|
|
||||||
);
|
|
||||||
await this.setStaleMessageSyncBackToPendingCommand.executeActiveWorkspacesCommand(
|
|
||||||
passedParam,
|
|
||||||
options,
|
|
||||||
workspaceIds,
|
|
||||||
);
|
|
||||||
await this.fixEmailFieldsToEmailsCommand.executeActiveWorkspacesCommand(
|
|
||||||
passedParam,
|
|
||||||
options,
|
|
||||||
workspaceIds,
|
|
||||||
);
|
|
||||||
await this.migratePhoneFieldsToPhones.executeActiveWorkspacesCommand(
|
|
||||||
passedParam,
|
|
||||||
options,
|
|
||||||
workspaceIds,
|
|
||||||
);
|
|
||||||
await this.fixViewFilterOperandForDateTimeCommand.executeActiveWorkspacesCommand(
|
|
||||||
passedParam,
|
|
||||||
options,
|
|
||||||
workspaceIds,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,43 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
|
|
||||||
import { FixEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-email-field-migration.command';
|
|
||||||
import { FixViewFilterOperandForDateTimeCommand } from 'src/database/commands/upgrade-version/0-30/0-30-fix-view-filter-operand-for-date-time.command';
|
|
||||||
import { MigrateEmailFieldsToEmailsCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-email-fields-to-emails.command';
|
|
||||||
import { MigratePhoneFieldsToPhonesCommand } from 'src/database/commands/upgrade-version/0-30/0-30-migrate-phone-fields-to-phones.command';
|
|
||||||
import { SetStaleMessageSyncBackToPendingCommand } from 'src/database/commands/upgrade-version/0-30/0-30-set-stale-message-sync-back-to-pending';
|
|
||||||
import { UpgradeTo0_30Command } from 'src/database/commands/upgrade-version/0-30/0-30-upgrade-version.command';
|
|
||||||
import { TypeORMModule } from 'src/database/typeorm/typeorm.module';
|
|
||||||
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
|
||||||
import { DataSourceModule } from 'src/engine/metadata-modules/data-source/data-source.module';
|
|
||||||
import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
import { FieldMetadataModule } from 'src/engine/metadata-modules/field-metadata/field-metadata.module';
|
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
|
||||||
import { WorkspaceMetadataVersionModule } from 'src/engine/metadata-modules/workspace-metadata-version/workspace-metadata-version.module';
|
|
||||||
import { WorkspaceSyncMetadataCommandsModule } from 'src/engine/workspace-manager/workspace-sync-metadata/commands/workspace-sync-metadata-commands.module';
|
|
||||||
import { ViewModule } from 'src/modules/view/view.module';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
imports: [
|
|
||||||
TypeOrmModule.forFeature([Workspace], 'core'),
|
|
||||||
WorkspaceSyncMetadataCommandsModule,
|
|
||||||
DataSourceModule,
|
|
||||||
WorkspaceMetadataVersionModule,
|
|
||||||
FieldMetadataModule,
|
|
||||||
TypeOrmModule.forFeature(
|
|
||||||
[FieldMetadataEntity, ObjectMetadataEntity],
|
|
||||||
'metadata',
|
|
||||||
),
|
|
||||||
TypeORMModule,
|
|
||||||
ViewModule,
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
UpgradeTo0_30Command,
|
|
||||||
MigrateEmailFieldsToEmailsCommand,
|
|
||||||
SetStaleMessageSyncBackToPendingCommand,
|
|
||||||
FixEmailFieldsToEmailsCommand,
|
|
||||||
MigratePhoneFieldsToPhonesCommand,
|
|
||||||
FixViewFilterOperandForDateTimeCommand,
|
|
||||||
],
|
|
||||||
})
|
|
||||||
export class UpgradeTo0_30CommandModule {}
|
|
||||||
@ -104,20 +104,6 @@ const fieldUuidMock = {
|
|||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const fieldPhoneMock = {
|
|
||||||
name: 'fieldPhone',
|
|
||||||
type: FieldMetadataType.PHONE,
|
|
||||||
isNullable: true,
|
|
||||||
defaultValue: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const fieldEmailMock = {
|
|
||||||
name: 'fieldEmail',
|
|
||||||
type: FieldMetadataType.EMAIL,
|
|
||||||
isNullable: true,
|
|
||||||
defaultValue: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
const fieldDateTimeMock = {
|
const fieldDateTimeMock = {
|
||||||
name: 'fieldDateTime',
|
name: 'fieldDateTime',
|
||||||
type: FieldMetadataType.DATE_TIME,
|
type: FieldMetadataType.DATE_TIME,
|
||||||
@ -253,9 +239,7 @@ const fieldPhonesMock = {
|
|||||||
export const fields = [
|
export const fields = [
|
||||||
fieldUuidMock,
|
fieldUuidMock,
|
||||||
fieldTextMock,
|
fieldTextMock,
|
||||||
fieldPhoneMock,
|
|
||||||
fieldPhonesMock,
|
fieldPhonesMock,
|
||||||
fieldEmailMock,
|
|
||||||
fieldEmailsMock,
|
fieldEmailsMock,
|
||||||
fieldDateTimeMock,
|
fieldDateTimeMock,
|
||||||
fieldDateMock,
|
fieldDateMock,
|
||||||
|
|||||||
@ -61,8 +61,6 @@ export class TypeMapperService {
|
|||||||
const typeScalarMapping = new Map<FieldMetadataType, GraphQLScalarType>([
|
const typeScalarMapping = new Map<FieldMetadataType, GraphQLScalarType>([
|
||||||
[FieldMetadataType.UUID, UUIDScalarType],
|
[FieldMetadataType.UUID, UUIDScalarType],
|
||||||
[FieldMetadataType.TEXT, GraphQLString],
|
[FieldMetadataType.TEXT, GraphQLString],
|
||||||
[FieldMetadataType.PHONE, GraphQLString],
|
|
||||||
[FieldMetadataType.EMAIL, GraphQLString],
|
|
||||||
[FieldMetadataType.DATE_TIME, GraphQLISODateTime],
|
[FieldMetadataType.DATE_TIME, GraphQLISODateTime],
|
||||||
[FieldMetadataType.DATE, GraphQLISODateTime],
|
[FieldMetadataType.DATE, GraphQLISODateTime],
|
||||||
[FieldMetadataType.BOOLEAN, GraphQLBoolean],
|
[FieldMetadataType.BOOLEAN, GraphQLBoolean],
|
||||||
@ -101,8 +99,6 @@ export class TypeMapperService {
|
|||||||
>([
|
>([
|
||||||
[FieldMetadataType.UUID, IDFilterType],
|
[FieldMetadataType.UUID, IDFilterType],
|
||||||
[FieldMetadataType.TEXT, StringFilterType],
|
[FieldMetadataType.TEXT, StringFilterType],
|
||||||
[FieldMetadataType.PHONE, StringFilterType],
|
|
||||||
[FieldMetadataType.EMAIL, StringFilterType],
|
|
||||||
[FieldMetadataType.DATE_TIME, DateFilterType],
|
[FieldMetadataType.DATE_TIME, DateFilterType],
|
||||||
[FieldMetadataType.DATE, DateFilterType],
|
[FieldMetadataType.DATE, DateFilterType],
|
||||||
[FieldMetadataType.BOOLEAN, BooleanFilterType],
|
[FieldMetadataType.BOOLEAN, BooleanFilterType],
|
||||||
@ -129,8 +125,6 @@ export class TypeMapperService {
|
|||||||
const typeOrderByMapping = new Map<FieldMetadataType, GraphQLEnumType>([
|
const typeOrderByMapping = new Map<FieldMetadataType, GraphQLEnumType>([
|
||||||
[FieldMetadataType.UUID, OrderByDirectionType],
|
[FieldMetadataType.UUID, OrderByDirectionType],
|
||||||
[FieldMetadataType.TEXT, OrderByDirectionType],
|
[FieldMetadataType.TEXT, OrderByDirectionType],
|
||||||
[FieldMetadataType.PHONE, OrderByDirectionType],
|
|
||||||
[FieldMetadataType.EMAIL, OrderByDirectionType],
|
|
||||||
[FieldMetadataType.DATE_TIME, OrderByDirectionType],
|
[FieldMetadataType.DATE_TIME, OrderByDirectionType],
|
||||||
[FieldMetadataType.DATE, OrderByDirectionType],
|
[FieldMetadataType.DATE, OrderByDirectionType],
|
||||||
[FieldMetadataType.BOOLEAN, OrderByDirectionType],
|
[FieldMetadataType.BOOLEAN, OrderByDirectionType],
|
||||||
|
|||||||
@ -18,8 +18,6 @@ export const mapFieldMetadataToGraphqlQuery = (
|
|||||||
const fieldIsSimpleValue = [
|
const fieldIsSimpleValue = [
|
||||||
FieldMetadataType.UUID,
|
FieldMetadataType.UUID,
|
||||||
FieldMetadataType.TEXT,
|
FieldMetadataType.TEXT,
|
||||||
FieldMetadataType.PHONE,
|
|
||||||
FieldMetadataType.EMAIL,
|
|
||||||
FieldMetadataType.DATE_TIME,
|
FieldMetadataType.DATE_TIME,
|
||||||
FieldMetadataType.DATE,
|
FieldMetadataType.DATE,
|
||||||
FieldMetadataType.BOOLEAN,
|
FieldMetadataType.BOOLEAN,
|
||||||
@ -89,14 +87,6 @@ export const mapFieldMetadataToGraphqlQuery = (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
} else if (fieldType === FieldMetadataType.LINK) {
|
|
||||||
return `
|
|
||||||
${field.name}
|
|
||||||
{
|
|
||||||
label
|
|
||||||
url
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
} else if (fieldType === FieldMetadataType.LINKS) {
|
} else if (fieldType === FieldMetadataType.LINKS) {
|
||||||
return `
|
return `
|
||||||
${field.name}
|
${field.name}
|
||||||
|
|||||||
@ -1,20 +1,8 @@
|
|||||||
import {
|
import { objectMetadataItemMock } from 'src/engine/api/__mocks__/object-metadata-item.mock';
|
||||||
fields,
|
|
||||||
objectMetadataItemMock,
|
|
||||||
} from 'src/engine/api/__mocks__/object-metadata-item.mock';
|
|
||||||
import { computeSchemaComponents } from 'src/engine/core-modules/open-api/utils/components.utils';
|
import { computeSchemaComponents } from 'src/engine/core-modules/open-api/utils/components.utils';
|
||||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
|
||||||
|
|
||||||
describe('computeSchemaComponents', () => {
|
describe('computeSchemaComponents', () => {
|
||||||
it('should test all non-deprecated field types', () => {
|
|
||||||
expect(fields.map((field) => field.type)).toEqual(
|
|
||||||
Object.keys(FieldMetadataType).filter(
|
|
||||||
(key) =>
|
|
||||||
key !== FieldMetadataType.LINK && key !== FieldMetadataType.TS_VECTOR,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
it('should compute schema components', () => {
|
it('should compute schema components', () => {
|
||||||
expect(
|
expect(
|
||||||
computeSchemaComponents([
|
computeSchemaComponents([
|
||||||
@ -32,9 +20,6 @@ describe('computeSchemaComponents', () => {
|
|||||||
fieldText: {
|
fieldText: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
fieldPhone: {
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
fieldPhones: {
|
fieldPhones: {
|
||||||
properties: {
|
properties: {
|
||||||
additionalPhones: {
|
additionalPhones: {
|
||||||
@ -49,10 +34,6 @@ describe('computeSchemaComponents', () => {
|
|||||||
},
|
},
|
||||||
type: 'object',
|
type: 'object',
|
||||||
},
|
},
|
||||||
fieldEmail: {
|
|
||||||
type: 'string',
|
|
||||||
format: 'email',
|
|
||||||
},
|
|
||||||
fieldEmails: {
|
fieldEmails: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@ -216,9 +197,6 @@ describe('computeSchemaComponents', () => {
|
|||||||
fieldText: {
|
fieldText: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
fieldPhone: {
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
fieldPhones: {
|
fieldPhones: {
|
||||||
properties: {
|
properties: {
|
||||||
additionalPhones: {
|
additionalPhones: {
|
||||||
@ -233,10 +211,6 @@ describe('computeSchemaComponents', () => {
|
|||||||
},
|
},
|
||||||
type: 'object',
|
type: 'object',
|
||||||
},
|
},
|
||||||
fieldEmail: {
|
|
||||||
type: 'string',
|
|
||||||
format: 'email',
|
|
||||||
},
|
|
||||||
fieldEmails: {
|
fieldEmails: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
@ -399,9 +373,6 @@ describe('computeSchemaComponents', () => {
|
|||||||
fieldText: {
|
fieldText: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
fieldPhone: {
|
|
||||||
type: 'string',
|
|
||||||
},
|
|
||||||
fieldPhones: {
|
fieldPhones: {
|
||||||
properties: {
|
properties: {
|
||||||
additionalPhones: {
|
additionalPhones: {
|
||||||
@ -416,10 +387,6 @@ describe('computeSchemaComponents', () => {
|
|||||||
},
|
},
|
||||||
type: 'object',
|
type: 'object',
|
||||||
},
|
},
|
||||||
fieldEmail: {
|
|
||||||
type: 'string',
|
|
||||||
format: 'email',
|
|
||||||
},
|
|
||||||
fieldEmails: {
|
fieldEmails: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
|
|||||||
@ -56,11 +56,8 @@ const getFieldProperties = (
|
|||||||
case FieldMetadataType.UUID:
|
case FieldMetadataType.UUID:
|
||||||
return { type: 'string', format: 'uuid' };
|
return { type: 'string', format: 'uuid' };
|
||||||
case FieldMetadataType.TEXT:
|
case FieldMetadataType.TEXT:
|
||||||
case FieldMetadataType.PHONE:
|
|
||||||
case FieldMetadataType.RICH_TEXT:
|
case FieldMetadataType.RICH_TEXT:
|
||||||
return { type: 'string' };
|
return { type: 'string' };
|
||||||
case FieldMetadataType.EMAIL:
|
|
||||||
return { type: 'string', format: 'email' };
|
|
||||||
case FieldMetadataType.DATE_TIME:
|
case FieldMetadataType.DATE_TIME:
|
||||||
return { type: 'string', format: 'date-time' };
|
return { type: 'string', format: 'date-time' };
|
||||||
case FieldMetadataType.DATE:
|
case FieldMetadataType.DATE:
|
||||||
@ -139,7 +136,6 @@ const getSchemaComponentsProperties = ({
|
|||||||
enum: field.options.map((option: { value: string }) => option.value),
|
enum: field.options.map((option: { value: string }) => option.value),
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case FieldMetadataType.LINK:
|
|
||||||
case FieldMetadataType.LINKS:
|
case FieldMetadataType.LINKS:
|
||||||
case FieldMetadataType.CURRENCY:
|
case FieldMetadataType.CURRENCY:
|
||||||
case FieldMetadataType.FULL_NAME:
|
case FieldMetadataType.FULL_NAME:
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import { addressCompositeType } from 'src/engine/metadata-modules/field-metadata
|
|||||||
import { currencyCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/currency.composite-type';
|
import { currencyCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/currency.composite-type';
|
||||||
import { emailsCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/emails.composite-type';
|
import { emailsCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/emails.composite-type';
|
||||||
import { fullNameCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/full-name.composite-type';
|
import { fullNameCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/full-name.composite-type';
|
||||||
import { linkCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/link.composite-type';
|
|
||||||
import { linksCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/links.composite-type';
|
import { linksCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/links.composite-type';
|
||||||
import { phonesCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/phones.composite-type';
|
import { phonesCompositeType } from 'src/engine/metadata-modules/field-metadata/composite-types/phones.composite-type';
|
||||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||||
@ -14,7 +13,6 @@ export const compositeTypeDefinitions = new Map<
|
|||||||
FieldMetadataType,
|
FieldMetadataType,
|
||||||
CompositeType
|
CompositeType
|
||||||
>([
|
>([
|
||||||
[FieldMetadataType.LINK, linkCompositeType],
|
|
||||||
[FieldMetadataType.LINKS, linksCompositeType],
|
[FieldMetadataType.LINKS, linksCompositeType],
|
||||||
[FieldMetadataType.CURRENCY, currencyCompositeType],
|
[FieldMetadataType.CURRENCY, currencyCompositeType],
|
||||||
[FieldMetadataType.FULL_NAME, fullNameCompositeType],
|
[FieldMetadataType.FULL_NAME, fullNameCompositeType],
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
import { CompositeType } from 'src/engine/metadata-modules/field-metadata/interfaces/composite-type.interface';
|
|
||||||
|
|
||||||
import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
|
||||||
|
|
||||||
export const linkCompositeType: CompositeType = {
|
|
||||||
type: FieldMetadataType.LINK,
|
|
||||||
properties: [
|
|
||||||
{
|
|
||||||
name: 'label',
|
|
||||||
type: FieldMetadataType.TEXT,
|
|
||||||
hidden: false,
|
|
||||||
isRequired: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'url',
|
|
||||||
type: FieldMetadataType.TEXT,
|
|
||||||
hidden: false,
|
|
||||||
isRequired: false,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
export type LinkMetadata = {
|
|
||||||
label: string;
|
|
||||||
url: string;
|
|
||||||
};
|
|
||||||
@ -71,16 +71,6 @@ export class FieldMetadataDefaultValueDate {
|
|||||||
value: Date | null;
|
value: Date | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FieldMetadataDefaultValueLink {
|
|
||||||
@ValidateIf((object, value) => value !== null)
|
|
||||||
@IsQuotedString()
|
|
||||||
label: string | null;
|
|
||||||
|
|
||||||
@ValidateIf((object, value) => value !== null)
|
|
||||||
@IsQuotedString()
|
|
||||||
url: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class FieldMetadataDefaultValueCurrency {
|
export class FieldMetadataDefaultValueCurrency {
|
||||||
@ValidateIf((object, value) => value !== null)
|
@ValidateIf((object, value) => value !== null)
|
||||||
@IsNumberString()
|
@IsNumberString()
|
||||||
|
|||||||
@ -24,16 +24,13 @@ import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-met
|
|||||||
export enum FieldMetadataType {
|
export enum FieldMetadataType {
|
||||||
UUID = 'UUID',
|
UUID = 'UUID',
|
||||||
TEXT = 'TEXT',
|
TEXT = 'TEXT',
|
||||||
PHONE = 'PHONE',
|
|
||||||
PHONES = 'PHONES',
|
PHONES = 'PHONES',
|
||||||
EMAIL = 'EMAIL',
|
|
||||||
EMAILS = 'EMAILS',
|
EMAILS = 'EMAILS',
|
||||||
DATE_TIME = 'DATE_TIME',
|
DATE_TIME = 'DATE_TIME',
|
||||||
DATE = 'DATE',
|
DATE = 'DATE',
|
||||||
BOOLEAN = 'BOOLEAN',
|
BOOLEAN = 'BOOLEAN',
|
||||||
NUMBER = 'NUMBER',
|
NUMBER = 'NUMBER',
|
||||||
NUMERIC = 'NUMERIC',
|
NUMERIC = 'NUMERIC',
|
||||||
LINK = 'LINK',
|
|
||||||
LINKS = 'LINKS',
|
LINKS = 'LINKS',
|
||||||
CURRENCY = 'CURRENCY',
|
CURRENCY = 'CURRENCY',
|
||||||
FULL_NAME = 'FULL_NAME',
|
FULL_NAME = 'FULL_NAME',
|
||||||
|
|||||||
@ -145,20 +145,6 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
|||||||
fieldMetadataInput.options = generateRatingOptions();
|
fieldMetadataInput.options = generateRatingOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldMetadataInput.type === FieldMetadataType.LINK) {
|
|
||||||
throw new FieldMetadataException(
|
|
||||||
'"Link" field types are being deprecated, please use Links type instead',
|
|
||||||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fieldMetadataInput.type === FieldMetadataType.EMAIL) {
|
|
||||||
throw new FieldMetadataException(
|
|
||||||
'"Email" field types are being deprecated, please use Emails type instead',
|
|
||||||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fieldMetadataForCreate = {
|
const fieldMetadataForCreate = {
|
||||||
id: v4(),
|
id: v4(),
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import {
|
|||||||
FieldMetadataDefaultValueDateTime,
|
FieldMetadataDefaultValueDateTime,
|
||||||
FieldMetadataDefaultValueEmails,
|
FieldMetadataDefaultValueEmails,
|
||||||
FieldMetadataDefaultValueFullName,
|
FieldMetadataDefaultValueFullName,
|
||||||
FieldMetadataDefaultValueLink,
|
|
||||||
FieldMetadataDefaultValueLinks,
|
FieldMetadataDefaultValueLinks,
|
||||||
FieldMetadataDefaultValueNowFunction,
|
FieldMetadataDefaultValueNowFunction,
|
||||||
FieldMetadataDefaultValueNumber,
|
FieldMetadataDefaultValueNumber,
|
||||||
@ -27,9 +26,7 @@ type FieldMetadataDefaultValueMapping = {
|
|||||||
| FieldMetadataDefaultValueString
|
| FieldMetadataDefaultValueString
|
||||||
| FieldMetadataDefaultValueUuidFunction;
|
| FieldMetadataDefaultValueUuidFunction;
|
||||||
[FieldMetadataType.TEXT]: FieldMetadataDefaultValueString;
|
[FieldMetadataType.TEXT]: FieldMetadataDefaultValueString;
|
||||||
[FieldMetadataType.PHONE]: FieldMetadataDefaultValueString;
|
|
||||||
[FieldMetadataType.PHONES]: FieldMetadataDefaultValuePhones;
|
[FieldMetadataType.PHONES]: FieldMetadataDefaultValuePhones;
|
||||||
[FieldMetadataType.EMAIL]: FieldMetadataDefaultValueString;
|
|
||||||
[FieldMetadataType.EMAILS]: FieldMetadataDefaultValueEmails;
|
[FieldMetadataType.EMAILS]: FieldMetadataDefaultValueEmails;
|
||||||
[FieldMetadataType.DATE_TIME]:
|
[FieldMetadataType.DATE_TIME]:
|
||||||
| FieldMetadataDefaultValueDateTime
|
| FieldMetadataDefaultValueDateTime
|
||||||
@ -41,7 +38,6 @@ type FieldMetadataDefaultValueMapping = {
|
|||||||
[FieldMetadataType.NUMBER]: FieldMetadataDefaultValueNumber;
|
[FieldMetadataType.NUMBER]: FieldMetadataDefaultValueNumber;
|
||||||
[FieldMetadataType.POSITION]: FieldMetadataDefaultValueNumber;
|
[FieldMetadataType.POSITION]: FieldMetadataDefaultValueNumber;
|
||||||
[FieldMetadataType.NUMERIC]: FieldMetadataDefaultValueString;
|
[FieldMetadataType.NUMERIC]: FieldMetadataDefaultValueString;
|
||||||
[FieldMetadataType.LINK]: FieldMetadataDefaultValueLink;
|
|
||||||
[FieldMetadataType.LINKS]: FieldMetadataDefaultValueLinks;
|
[FieldMetadataType.LINKS]: FieldMetadataDefaultValueLinks;
|
||||||
[FieldMetadataType.CURRENCY]: FieldMetadataDefaultValueCurrency;
|
[FieldMetadataType.CURRENCY]: FieldMetadataDefaultValueCurrency;
|
||||||
[FieldMetadataType.FULL_NAME]: FieldMetadataDefaultValueFullName;
|
[FieldMetadataType.FULL_NAME]: FieldMetadataDefaultValueFullName;
|
||||||
|
|||||||
@ -4,16 +4,10 @@ import { generateNullable } from 'src/engine/metadata-modules/field-metadata/uti
|
|||||||
describe('generateNullable', () => {
|
describe('generateNullable', () => {
|
||||||
it('should generate a nullable value false for TEXT, EMAIL, PHONE no matter what the input is', () => {
|
it('should generate a nullable value false for TEXT, EMAIL, PHONE no matter what the input is', () => {
|
||||||
expect(generateNullable(FieldMetadataType.TEXT, false)).toEqual(false);
|
expect(generateNullable(FieldMetadataType.TEXT, false)).toEqual(false);
|
||||||
expect(generateNullable(FieldMetadataType.PHONE, false)).toEqual(false);
|
|
||||||
expect(generateNullable(FieldMetadataType.EMAIL, false)).toEqual(false);
|
|
||||||
|
|
||||||
expect(generateNullable(FieldMetadataType.TEXT, true)).toEqual(false);
|
expect(generateNullable(FieldMetadataType.TEXT, true)).toEqual(false);
|
||||||
expect(generateNullable(FieldMetadataType.PHONE, true)).toEqual(false);
|
|
||||||
expect(generateNullable(FieldMetadataType.EMAIL, true)).toEqual(false);
|
|
||||||
|
|
||||||
expect(generateNullable(FieldMetadataType.TEXT)).toEqual(false);
|
expect(generateNullable(FieldMetadataType.TEXT)).toEqual(false);
|
||||||
expect(generateNullable(FieldMetadataType.PHONE)).toEqual(false);
|
|
||||||
expect(generateNullable(FieldMetadataType.EMAIL)).toEqual(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should should return true if no input is given', () => {
|
it('should should return true if no input is given', () => {
|
||||||
|
|||||||
@ -40,32 +40,6 @@ describe('validateDefaultValueForType', () => {
|
|||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should validate string default value for PHONE type', () => {
|
|
||||||
expect(
|
|
||||||
validateDefaultValueForType(FieldMetadataType.PHONE, "'+123456789'")
|
|
||||||
.isValid,
|
|
||||||
).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false for invalid string default value for PHONE type', () => {
|
|
||||||
expect(
|
|
||||||
validateDefaultValueForType(FieldMetadataType.PHONE, 123).isValid,
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should validate string default value for EMAIL type', () => {
|
|
||||||
expect(
|
|
||||||
validateDefaultValueForType(FieldMetadataType.EMAIL, "'test@example.com'")
|
|
||||||
.isValid,
|
|
||||||
).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false for invalid string default value for EMAIL type', () => {
|
|
||||||
expect(
|
|
||||||
validateDefaultValueForType(FieldMetadataType.EMAIL, 123).isValid,
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should validate number default value for NUMBER type', () => {
|
it('should validate number default value for NUMBER type', () => {
|
||||||
expect(
|
expect(
|
||||||
validateDefaultValueForType(FieldMetadataType.NUMBER, 100).isValid,
|
validateDefaultValueForType(FieldMetadataType.NUMBER, 100).isValid,
|
||||||
@ -90,27 +64,6 @@ describe('validateDefaultValueForType', () => {
|
|||||||
).toBe(false);
|
).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
// LINK type
|
|
||||||
it('should validate LINK default value', () => {
|
|
||||||
expect(
|
|
||||||
validateDefaultValueForType(FieldMetadataType.LINK, {
|
|
||||||
label: "'http://example.com'",
|
|
||||||
url: "'Example'",
|
|
||||||
}).isValid,
|
|
||||||
).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false for invalid LINK default value', () => {
|
|
||||||
expect(
|
|
||||||
validateDefaultValueForType(
|
|
||||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
||||||
// @ts-expect-error Just for testing purposes
|
|
||||||
{ label: 123, url: {} },
|
|
||||||
FieldMetadataType.LINK,
|
|
||||||
).isValid,
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
// CURRENCY type
|
// CURRENCY type
|
||||||
it('should validate CURRENCY default value', () => {
|
it('should validate CURRENCY default value', () => {
|
||||||
expect(
|
expect(
|
||||||
|
|||||||
@ -7,8 +7,6 @@ export function generateDefaultValue(
|
|||||||
): FieldMetadataDefaultValue {
|
): FieldMetadataDefaultValue {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FieldMetadataType.TEXT:
|
case FieldMetadataType.TEXT:
|
||||||
case FieldMetadataType.PHONE:
|
|
||||||
case FieldMetadataType.EMAIL:
|
|
||||||
return "''";
|
return "''";
|
||||||
case FieldMetadataType.EMAILS:
|
case FieldMetadataType.EMAILS:
|
||||||
return {
|
return {
|
||||||
@ -31,11 +29,6 @@ export function generateDefaultValue(
|
|||||||
addressLat: null,
|
addressLat: null,
|
||||||
addressLng: null,
|
addressLng: null,
|
||||||
};
|
};
|
||||||
case FieldMetadataType.LINK:
|
|
||||||
return {
|
|
||||||
url: "''",
|
|
||||||
label: "''",
|
|
||||||
};
|
|
||||||
case FieldMetadataType.CURRENCY:
|
case FieldMetadataType.CURRENCY:
|
||||||
return {
|
return {
|
||||||
amountMicros: null,
|
amountMicros: null,
|
||||||
|
|||||||
@ -11,8 +11,6 @@ export function generateNullable(
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case FieldMetadataType.TEXT:
|
case FieldMetadataType.TEXT:
|
||||||
case FieldMetadataType.PHONE:
|
|
||||||
case FieldMetadataType.EMAIL:
|
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return inputNullableValue ?? true;
|
return inputNullableValue ?? true;
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import { FieldMetadataType } from 'src/engine/metadata-modules/field-metadata/fi
|
|||||||
export const isCompositeFieldMetadataType = (
|
export const isCompositeFieldMetadataType = (
|
||||||
type: FieldMetadataType,
|
type: FieldMetadataType,
|
||||||
): type is
|
): type is
|
||||||
| FieldMetadataType.LINK
|
|
||||||
| FieldMetadataType.CURRENCY
|
| FieldMetadataType.CURRENCY
|
||||||
| FieldMetadataType.FULL_NAME
|
| FieldMetadataType.FULL_NAME
|
||||||
| FieldMetadataType.ADDRESS
|
| FieldMetadataType.ADDRESS
|
||||||
@ -12,7 +11,6 @@ export const isCompositeFieldMetadataType = (
|
|||||||
| FieldMetadataType.EMAILS
|
| FieldMetadataType.EMAILS
|
||||||
| FieldMetadataType.PHONES => {
|
| FieldMetadataType.PHONES => {
|
||||||
return [
|
return [
|
||||||
FieldMetadataType.LINK,
|
|
||||||
FieldMetadataType.CURRENCY,
|
FieldMetadataType.CURRENCY,
|
||||||
FieldMetadataType.FULL_NAME,
|
FieldMetadataType.FULL_NAME,
|
||||||
FieldMetadataType.ADDRESS,
|
FieldMetadataType.ADDRESS,
|
||||||
|
|||||||
@ -15,7 +15,6 @@ import {
|
|||||||
FieldMetadataDefaultValueDateTime,
|
FieldMetadataDefaultValueDateTime,
|
||||||
FieldMetadataDefaultValueEmails,
|
FieldMetadataDefaultValueEmails,
|
||||||
FieldMetadataDefaultValueFullName,
|
FieldMetadataDefaultValueFullName,
|
||||||
FieldMetadataDefaultValueLink,
|
|
||||||
FieldMetadataDefaultValueLinks,
|
FieldMetadataDefaultValueLinks,
|
||||||
FieldMetadataDefaultValueNowFunction,
|
FieldMetadataDefaultValueNowFunction,
|
||||||
FieldMetadataDefaultValueNumber,
|
FieldMetadataDefaultValueNumber,
|
||||||
@ -34,8 +33,6 @@ export const defaultValueValidatorsMap = {
|
|||||||
FieldMetadataDefaultValueUuidFunction,
|
FieldMetadataDefaultValueUuidFunction,
|
||||||
],
|
],
|
||||||
[FieldMetadataType.TEXT]: [FieldMetadataDefaultValueString],
|
[FieldMetadataType.TEXT]: [FieldMetadataDefaultValueString],
|
||||||
[FieldMetadataType.PHONE]: [FieldMetadataDefaultValueString],
|
|
||||||
[FieldMetadataType.EMAIL]: [FieldMetadataDefaultValueString],
|
|
||||||
[FieldMetadataType.DATE_TIME]: [
|
[FieldMetadataType.DATE_TIME]: [
|
||||||
FieldMetadataDefaultValueDateTime,
|
FieldMetadataDefaultValueDateTime,
|
||||||
FieldMetadataDefaultValueNowFunction,
|
FieldMetadataDefaultValueNowFunction,
|
||||||
@ -44,7 +41,6 @@ export const defaultValueValidatorsMap = {
|
|||||||
[FieldMetadataType.BOOLEAN]: [FieldMetadataDefaultValueBoolean],
|
[FieldMetadataType.BOOLEAN]: [FieldMetadataDefaultValueBoolean],
|
||||||
[FieldMetadataType.NUMBER]: [FieldMetadataDefaultValueNumber],
|
[FieldMetadataType.NUMBER]: [FieldMetadataDefaultValueNumber],
|
||||||
[FieldMetadataType.NUMERIC]: [FieldMetadataDefaultValueString],
|
[FieldMetadataType.NUMERIC]: [FieldMetadataDefaultValueString],
|
||||||
[FieldMetadataType.LINK]: [FieldMetadataDefaultValueLink],
|
|
||||||
[FieldMetadataType.CURRENCY]: [FieldMetadataDefaultValueCurrency],
|
[FieldMetadataType.CURRENCY]: [FieldMetadataDefaultValueCurrency],
|
||||||
[FieldMetadataType.FULL_NAME]: [FieldMetadataDefaultValueFullName],
|
[FieldMetadataType.FULL_NAME]: [FieldMetadataDefaultValueFullName],
|
||||||
[FieldMetadataType.RATING]: [FieldMetadataDefaultValueString],
|
[FieldMetadataType.RATING]: [FieldMetadataDefaultValueString],
|
||||||
|
|||||||
@ -21,8 +21,6 @@ import {
|
|||||||
export type BasicFieldMetadataType =
|
export type BasicFieldMetadataType =
|
||||||
| FieldMetadataType.UUID
|
| FieldMetadataType.UUID
|
||||||
| FieldMetadataType.TEXT
|
| FieldMetadataType.TEXT
|
||||||
| FieldMetadataType.PHONE
|
|
||||||
| FieldMetadataType.EMAIL
|
|
||||||
| FieldMetadataType.NUMERIC
|
| FieldMetadataType.NUMERIC
|
||||||
| FieldMetadataType.NUMBER
|
| FieldMetadataType.NUMBER
|
||||||
| FieldMetadataType.BOOLEAN
|
| FieldMetadataType.BOOLEAN
|
||||||
|
|||||||
@ -23,7 +23,6 @@ export type CompositeFieldMetadataType =
|
|||||||
| FieldMetadataType.ADDRESS
|
| FieldMetadataType.ADDRESS
|
||||||
| FieldMetadataType.CURRENCY
|
| FieldMetadataType.CURRENCY
|
||||||
| FieldMetadataType.FULL_NAME
|
| FieldMetadataType.FULL_NAME
|
||||||
| FieldMetadataType.LINK
|
|
||||||
| FieldMetadataType.LINKS
|
| FieldMetadataType.LINKS
|
||||||
| FieldMetadataType.EMAILS
|
| FieldMetadataType.EMAILS
|
||||||
| FieldMetadataType.PHONES;
|
| FieldMetadataType.PHONES;
|
||||||
|
|||||||
@ -18,9 +18,6 @@ export const fieldMetadataTypeToColumnType = <Type extends FieldMetadataType>(
|
|||||||
case FieldMetadataType.RICH_TEXT:
|
case FieldMetadataType.RICH_TEXT:
|
||||||
case FieldMetadataType.ARRAY:
|
case FieldMetadataType.ARRAY:
|
||||||
return 'text';
|
return 'text';
|
||||||
case FieldMetadataType.PHONE:
|
|
||||||
case FieldMetadataType.EMAIL:
|
|
||||||
return 'varchar';
|
|
||||||
case FieldMetadataType.NUMERIC:
|
case FieldMetadataType.NUMERIC:
|
||||||
return 'numeric';
|
return 'numeric';
|
||||||
case FieldMetadataType.NUMBER:
|
case FieldMetadataType.NUMBER:
|
||||||
|
|||||||
@ -52,24 +52,6 @@ export class WorkspaceMigrationFactory {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[
|
|
||||||
FieldMetadataType.PHONE,
|
|
||||||
{
|
|
||||||
factory: this.basicColumnActionFactory,
|
|
||||||
options: {
|
|
||||||
defaultValue: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[
|
|
||||||
FieldMetadataType.EMAIL,
|
|
||||||
{
|
|
||||||
factory: this.basicColumnActionFactory,
|
|
||||||
options: {
|
|
||||||
defaultValue: '',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[FieldMetadataType.NUMERIC, { factory: this.basicColumnActionFactory }],
|
[FieldMetadataType.NUMERIC, { factory: this.basicColumnActionFactory }],
|
||||||
[FieldMetadataType.NUMBER, { factory: this.basicColumnActionFactory }],
|
[FieldMetadataType.NUMBER, { factory: this.basicColumnActionFactory }],
|
||||||
[FieldMetadataType.POSITION, { factory: this.basicColumnActionFactory }],
|
[FieldMetadataType.POSITION, { factory: this.basicColumnActionFactory }],
|
||||||
@ -84,7 +66,6 @@ export class WorkspaceMigrationFactory {
|
|||||||
FieldMetadataType.MULTI_SELECT,
|
FieldMetadataType.MULTI_SELECT,
|
||||||
{ factory: this.enumColumnActionFactory },
|
{ factory: this.enumColumnActionFactory },
|
||||||
],
|
],
|
||||||
[FieldMetadataType.LINK, { factory: this.compositeColumnActionFactory }],
|
|
||||||
[
|
[
|
||||||
FieldMetadataType.CURRENCY,
|
FieldMetadataType.CURRENCY,
|
||||||
{ factory: this.compositeColumnActionFactory },
|
{ factory: this.compositeColumnActionFactory },
|
||||||
|
|||||||
@ -32,10 +32,7 @@ export class CalendarEventParticipantPersonListener {
|
|||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
for (const eventPayload of payload.events) {
|
for (const eventPayload of payload.events) {
|
||||||
if (
|
if (eventPayload.properties.after.emails?.primaryEmail === null) {
|
||||||
eventPayload.properties.after.emails?.primaryEmail === null &&
|
|
||||||
eventPayload.properties.after.email === null
|
|
||||||
) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,9 +41,7 @@ export class CalendarEventParticipantPersonListener {
|
|||||||
CalendarEventParticipantMatchParticipantJob.name,
|
CalendarEventParticipantMatchParticipantJob.name,
|
||||||
{
|
{
|
||||||
workspaceId: payload.workspaceId,
|
workspaceId: payload.workspaceId,
|
||||||
email:
|
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||||
eventPayload.properties.after.emails?.primaryEmail ??
|
|
||||||
eventPayload.properties.after.email, // TODO
|
|
||||||
personId: eventPayload.recordId,
|
personId: eventPayload.recordId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -64,16 +59,14 @@ export class CalendarEventParticipantPersonListener {
|
|||||||
objectRecordUpdateEventChangedProperties(
|
objectRecordUpdateEventChangedProperties(
|
||||||
eventPayload.properties.before,
|
eventPayload.properties.before,
|
||||||
eventPayload.properties.after,
|
eventPayload.properties.after,
|
||||||
).includes('email')
|
).includes('emails')
|
||||||
) {
|
) {
|
||||||
// TODO: modify this job to take an array of participants to match
|
// TODO: modify this job to take an array of participants to match
|
||||||
await this.messageQueueService.add<CalendarEventParticipantUnmatchParticipantJobData>(
|
await this.messageQueueService.add<CalendarEventParticipantUnmatchParticipantJobData>(
|
||||||
CalendarEventParticipantUnmatchParticipantJob.name,
|
CalendarEventParticipantUnmatchParticipantJob.name,
|
||||||
{
|
{
|
||||||
workspaceId: payload.workspaceId,
|
workspaceId: payload.workspaceId,
|
||||||
email:
|
email: eventPayload.properties.before.emails?.primaryEmail,
|
||||||
eventPayload.properties.before.emails?.primaryEmail ??
|
|
||||||
eventPayload.properties.before.email,
|
|
||||||
personId: eventPayload.recordId,
|
personId: eventPayload.recordId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -82,9 +75,7 @@ export class CalendarEventParticipantPersonListener {
|
|||||||
CalendarEventParticipantMatchParticipantJob.name,
|
CalendarEventParticipantMatchParticipantJob.name,
|
||||||
{
|
{
|
||||||
workspaceId: payload.workspaceId,
|
workspaceId: payload.workspaceId,
|
||||||
email:
|
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||||
eventPayload.properties.after.emails?.primaryEmail ??
|
|
||||||
eventPayload.properties.after.email,
|
|
||||||
personId: eventPayload.recordId,
|
personId: eventPayload.recordId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
import { isDefined } from 'class-validator';
|
|
||||||
import chunk from 'lodash.chunk';
|
import chunk from 'lodash.chunk';
|
||||||
import compact from 'lodash.compact';
|
import compact from 'lodash.compact';
|
||||||
import { Any, EntityManager, Repository } from 'typeorm';
|
import { Any, EntityManager, Repository } from 'typeorm';
|
||||||
@ -13,7 +12,6 @@ import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadat
|
|||||||
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
|
||||||
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
|
||||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
||||||
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
|
||||||
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
import { ConnectedAccountWorkspaceEntity } from 'src/modules/connected-account/standard-objects/connected-account.workspace-entity';
|
||||||
import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/contact-creation-manager/constants/contacts-creation-batch-size.constant';
|
import { CONTACTS_CREATION_BATCH_SIZE } from 'src/modules/contact-creation-manager/constants/contacts-creation-batch-size.constant';
|
||||||
@ -54,13 +52,6 @@ export class CreateCompanyAndContactService {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const emailsFieldMetadata = await this.fieldMetadataRepository.findOne({
|
|
||||||
where: {
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const personRepository =
|
const personRepository =
|
||||||
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
|
||||||
workspaceId,
|
workspaceId,
|
||||||
@ -89,16 +80,14 @@ export class CreateCompanyAndContactService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const alreadyCreatedContacts = await personRepository.find({
|
const alreadyCreatedContacts = await personRepository.find({
|
||||||
where: isDefined(emailsFieldMetadata)
|
where: {
|
||||||
? {
|
emails: { primaryEmail: Any(uniqueHandles) },
|
||||||
emails: { primaryEmail: Any(uniqueHandles) },
|
},
|
||||||
}
|
|
||||||
: { email: Any(uniqueHandles) },
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const alreadyCreatedContactEmails: string[] = isDefined(emailsFieldMetadata)
|
const alreadyCreatedContactEmails: string[] = alreadyCreatedContacts?.map(
|
||||||
? alreadyCreatedContacts?.map(({ emails }) => emails?.primaryEmail)
|
({ emails }) => emails?.primaryEmail,
|
||||||
: alreadyCreatedContacts?.map(({ email }) => email);
|
);
|
||||||
|
|
||||||
const filteredContactsToCreate = uniqueContacts.filter(
|
const filteredContactsToCreate = uniqueContacts.filter(
|
||||||
(participant) =>
|
(participant) =>
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import { FieldMetadataEntity } from 'src/engine/metadata-modules/field-metadata/
|
|||||||
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
import { ScopedWorkspaceContextFactory } from 'src/engine/twenty-orm/factories/scoped-workspace-context.factory';
|
||||||
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
import { TwentyORMManager } from 'src/engine/twenty-orm/twenty-orm.manager';
|
||||||
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
import { WorkspaceEventEmitter } from 'src/engine/workspace-event-emitter/workspace-event-emitter';
|
||||||
import { PERSON_STANDARD_FIELD_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-field-ids';
|
|
||||||
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
|
import { CalendarEventParticipantWorkspaceEntity } from 'src/modules/calendar/common/standard-objects/calendar-event-participant.workspace-entity';
|
||||||
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
|
||||||
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
|
||||||
@ -60,35 +59,19 @@ export class MatchParticipantService<
|
|||||||
...new Set(participants.map((participant) => participant.handle)),
|
...new Set(participants.map((participant) => participant.handle)),
|
||||||
];
|
];
|
||||||
|
|
||||||
const emailsFieldMetadata = await this.fieldMetadataRepository.findOne({
|
|
||||||
where: {
|
|
||||||
workspaceId: workspaceId,
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const personRepository =
|
const personRepository =
|
||||||
await this.twentyORMManager.getRepository<PersonWorkspaceEntity>(
|
await this.twentyORMManager.getRepository<PersonWorkspaceEntity>(
|
||||||
'person',
|
'person',
|
||||||
);
|
);
|
||||||
|
|
||||||
const people = emailsFieldMetadata
|
const people = await personRepository.find(
|
||||||
? await personRepository.find(
|
{
|
||||||
{
|
where: {
|
||||||
where: {
|
emails: Any(uniqueParticipantsHandles),
|
||||||
emails: Any(uniqueParticipantsHandles),
|
},
|
||||||
},
|
},
|
||||||
},
|
transactionManager,
|
||||||
transactionManager,
|
);
|
||||||
)
|
|
||||||
: await personRepository.find(
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
email: Any(uniqueParticipantsHandles),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
transactionManager,
|
|
||||||
);
|
|
||||||
|
|
||||||
const workspaceMemberRepository =
|
const workspaceMemberRepository =
|
||||||
await this.twentyORMManager.getRepository<WorkspaceMemberWorkspaceEntity>(
|
await this.twentyORMManager.getRepository<WorkspaceMemberWorkspaceEntity>(
|
||||||
@ -105,10 +88,8 @@ export class MatchParticipantService<
|
|||||||
);
|
);
|
||||||
|
|
||||||
for (const handle of uniqueParticipantsHandles) {
|
for (const handle of uniqueParticipantsHandles) {
|
||||||
const person = people.find((person) =>
|
const person = people.find(
|
||||||
emailsFieldMetadata
|
(person) => person.emails?.primaryEmail === handle,
|
||||||
? person.emails?.primaryEmail === handle
|
|
||||||
: person.email === handle,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const workspaceMember = workspaceMembers.find(
|
const workspaceMember = workspaceMembers.find(
|
||||||
|
|||||||
@ -32,10 +32,7 @@ export class MessageParticipantPersonListener {
|
|||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
for (const eventPayload of payload.events) {
|
for (const eventPayload of payload.events) {
|
||||||
if (
|
if (!eventPayload.properties.after.emails?.primaryEmail) {
|
||||||
!eventPayload.properties.after.emails?.primaryEmail &&
|
|
||||||
!eventPayload.properties.after.email
|
|
||||||
) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,9 +40,7 @@ export class MessageParticipantPersonListener {
|
|||||||
MessageParticipantMatchParticipantJob.name,
|
MessageParticipantMatchParticipantJob.name,
|
||||||
{
|
{
|
||||||
workspaceId: payload.workspaceId,
|
workspaceId: payload.workspaceId,
|
||||||
email:
|
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||||
eventPayload.properties.after.emails?.primaryEmail ??
|
|
||||||
eventPayload.properties.after.email,
|
|
||||||
personId: eventPayload.recordId,
|
personId: eventPayload.recordId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -60,10 +55,6 @@ export class MessageParticipantPersonListener {
|
|||||||
) {
|
) {
|
||||||
for (const eventPayload of payload.events) {
|
for (const eventPayload of payload.events) {
|
||||||
if (
|
if (
|
||||||
objectRecordUpdateEventChangedProperties(
|
|
||||||
eventPayload.properties.before,
|
|
||||||
eventPayload.properties.after,
|
|
||||||
).includes('email') ||
|
|
||||||
objectRecordUpdateEventChangedProperties(
|
objectRecordUpdateEventChangedProperties(
|
||||||
eventPayload.properties.before,
|
eventPayload.properties.before,
|
||||||
eventPayload.properties.after,
|
eventPayload.properties.after,
|
||||||
@ -73,9 +64,7 @@ export class MessageParticipantPersonListener {
|
|||||||
MessageParticipantUnmatchParticipantJob.name,
|
MessageParticipantUnmatchParticipantJob.name,
|
||||||
{
|
{
|
||||||
workspaceId: payload.workspaceId,
|
workspaceId: payload.workspaceId,
|
||||||
email:
|
email: eventPayload.properties.before.emails?.primaryEmail,
|
||||||
eventPayload.properties.before.emails?.primaryEmail ??
|
|
||||||
eventPayload.properties.before.email,
|
|
||||||
personId: eventPayload.recordId,
|
personId: eventPayload.recordId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -84,9 +73,7 @@ export class MessageParticipantPersonListener {
|
|||||||
MessageParticipantMatchParticipantJob.name,
|
MessageParticipantMatchParticipantJob.name,
|
||||||
{
|
{
|
||||||
workspaceId: payload.workspaceId,
|
workspaceId: payload.workspaceId,
|
||||||
email:
|
email: eventPayload.properties.after.emails?.primaryEmail,
|
||||||
eventPayload.properties.after.emails?.primaryEmail ??
|
|
||||||
eventPayload.properties.after.email,
|
|
||||||
personId: eventPayload.recordId,
|
personId: eventPayload.recordId,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@ -63,16 +63,6 @@ export class PersonWorkspaceEntity extends BaseWorkspaceEntity {
|
|||||||
@WorkspaceIsNullable()
|
@WorkspaceIsNullable()
|
||||||
[NAME_FIELD_NAME]: FullNameMetadata | null;
|
[NAME_FIELD_NAME]: FullNameMetadata | null;
|
||||||
|
|
||||||
@WorkspaceField({
|
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.email,
|
|
||||||
type: FieldMetadataType.EMAIL,
|
|
||||||
label: 'Email',
|
|
||||||
description: 'Contact’s Email',
|
|
||||||
icon: 'IconMail',
|
|
||||||
})
|
|
||||||
@WorkspaceIsDeprecated()
|
|
||||||
email: string;
|
|
||||||
|
|
||||||
@WorkspaceField({
|
@WorkspaceField({
|
||||||
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
standardId: PERSON_STANDARD_FIELD_IDS.emails,
|
||||||
type: FieldMetadataType.EMAILS,
|
type: FieldMetadataType.EMAILS,
|
||||||
|
|||||||
Reference in New Issue
Block a user