-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add composite Emails field and forbid creation of Email field type (#…
…6689) ### Description 1. - We are introducing new field type(Emails) - We are Forbiding creation of Email field - We Added support for filtering and sorting on Emails field - We are using the same display mode as used on the Links field type (chips), check the Domain field of the Company object - We are also using the same logic of the link when editing the field \ How To Test\ Follow the below steps for testing locally:\ 1. Checkout to TWENTY-6261\ 2. Reset database using "npx nx database:reset twenty-server" command\ 3. Run both the backend and frontend app\ 4. Go to Settings/Data model and choose one of the standard objects like people\ 5. Click on Add Field button and choose Emails as the field type \ ### Refs #6261\ \ ### Demo \ <https://www.loom.com/share/22979acac8134ed390fef93cc56fe07c?sid=adafba94-840d-4f01-872c-dc9ec256d987> Co-authored-by: gitstart-twenty <[email protected]>
- Loading branch information
1 parent
c87ccfa
commit 7a9a43b
Showing
52 changed files
with
866 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ export type FilterType = | |
| 'TEXT' | ||
| 'PHONE' | ||
| 'EMAIL' | ||
| 'EMAILS' | ||
| 'DATE_TIME' | ||
| 'DATE' | ||
| 'NUMBER' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...c/modules/object-record/record-field/meta-types/display/components/EmailsFieldDisplay.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { useEmailsField } from '@/object-record/record-field/meta-types/hooks/useEmailsField'; | ||
import { EmailsDisplay } from '@/ui/field/display/components/EmailsDisplay'; | ||
|
||
export const EmailsFieldDisplay = () => { | ||
const { fieldValue } = useEmailsField(); | ||
|
||
return <EmailsDisplay value={fieldValue} />; | ||
}; |
53 changes: 53 additions & 0 deletions
53
...es/twenty-front/src/modules/object-record/record-field/meta-types/hooks/useEmailsField.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useContext } from 'react'; | ||
import { useRecoilState, useRecoilValue } from 'recoil'; | ||
|
||
import { usePersistField } from '@/object-record/record-field/hooks/usePersistField'; | ||
import { useRecordFieldInput } from '@/object-record/record-field/hooks/useRecordFieldInput'; | ||
import { FieldEmailsValue } from '@/object-record/record-field/types/FieldMetadata'; | ||
import { isFieldEmails } from '@/object-record/record-field/types/guards/isFieldEmails'; | ||
import { emailsSchema } from '@/object-record/record-field/types/guards/isFieldEmailsValue'; | ||
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'; | ||
|
||
export const useEmailsField = () => { | ||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext); | ||
|
||
assertFieldMetadata(FieldMetadataType.Emails, isFieldEmails, fieldDefinition); | ||
|
||
const fieldName = fieldDefinition.metadata.fieldName; | ||
|
||
const [fieldValue, setFieldValue] = useRecoilState<FieldEmailsValue>( | ||
recordStoreFamilySelector({ | ||
recordId, | ||
fieldName: fieldName, | ||
}), | ||
); | ||
|
||
const { setDraftValue, getDraftValueSelector } = | ||
useRecordFieldInput<FieldEmailsValue>(`${recordId}-${fieldName}`); | ||
|
||
const draftValue = useRecoilValue(getDraftValueSelector()); | ||
|
||
const persistField = usePersistField(); | ||
|
||
const persistEmailsField = (nextValue: FieldEmailsValue) => { | ||
try { | ||
persistField(emailsSchema.parse(nextValue)); | ||
} catch { | ||
return; | ||
} | ||
}; | ||
|
||
return { | ||
fieldDefinition, | ||
fieldValue, | ||
draftValue, | ||
setDraftValue, | ||
setFieldValue, | ||
hotkeyScope, | ||
persistEmailsField, | ||
}; | ||
}; |
23 changes: 23 additions & 0 deletions
23
...ty-front/src/modules/object-record/record-field/meta-types/hooks/useEmailsFieldDisplay.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useContext } from 'react'; | ||
|
||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext'; | ||
|
||
import { FieldEmailsValue } from '@/object-record/record-field/types/FieldMetadata'; | ||
import { FieldContext } from '../../contexts/FieldContext'; | ||
|
||
export const useEmailsFieldDisplay = () => { | ||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext); | ||
|
||
const fieldName = fieldDefinition.metadata.fieldName; | ||
|
||
const fieldValue = useRecordFieldValue<FieldEmailsValue | undefined>( | ||
recordId, | ||
fieldName, | ||
); | ||
|
||
return { | ||
fieldDefinition, | ||
fieldValue, | ||
hotkeyScope, | ||
}; | ||
}; |
57 changes: 57 additions & 0 deletions
57
...t/src/modules/object-record/record-field/meta-types/input/components/EmailsFieldInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useEmailsField } from '@/object-record/record-field/meta-types/hooks/useEmailsField'; | ||
import { EmailsFieldMenuItem } from '@/object-record/record-field/meta-types/input/components/EmailsFieldMenuItem'; | ||
import { useMemo } from 'react'; | ||
import { isDefined } from 'twenty-ui'; | ||
import { MultiItemFieldInput } from './MultiItemFieldInput'; | ||
|
||
type EmailsFieldInputProps = { | ||
onCancel?: () => void; | ||
}; | ||
|
||
export const EmailsFieldInput = ({ onCancel }: EmailsFieldInputProps) => { | ||
const { persistEmailsField, hotkeyScope, fieldValue } = useEmailsField(); | ||
|
||
const emails = useMemo<string[]>( | ||
() => | ||
[ | ||
fieldValue?.primaryEmail ? fieldValue?.primaryEmail : null, | ||
...(fieldValue?.additionalEmails ?? []), | ||
].filter(isDefined), | ||
[fieldValue?.primaryEmail, fieldValue?.additionalEmails], | ||
); | ||
|
||
const handlePersistEmails = (updatedEmails: string[]) => { | ||
const [nextPrimaryEmail, ...nextAdditionalEmails] = updatedEmails; | ||
persistEmailsField({ | ||
primaryEmail: nextPrimaryEmail ?? '', | ||
additionalEmails: nextAdditionalEmails, | ||
}); | ||
}; | ||
|
||
return ( | ||
<MultiItemFieldInput | ||
items={emails} | ||
onPersist={handlePersistEmails} | ||
onCancel={onCancel} | ||
placeholder="Email" | ||
renderItem={({ | ||
value: email, | ||
index, | ||
handleEdit, | ||
handleSetPrimary, | ||
handleDelete, | ||
}) => ( | ||
<EmailsFieldMenuItem | ||
key={index} | ||
dropdownId={`${hotkeyScope}-emails-${index}`} | ||
isPrimary={index === 0} | ||
email={email} | ||
onEdit={handleEdit} | ||
onSetAsPrimary={handleSetPrimary} | ||
onDelete={handleDelete} | ||
/> | ||
)} | ||
hotkeyScope={hotkeyScope} | ||
/> | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
...rc/modules/object-record/record-field/meta-types/input/components/EmailsFieldMenuItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { EmailDisplay } from '@/ui/field/display/components/EmailDisplay'; | ||
import { MultiItemFieldMenuItem } from './MultiItemFieldMenuItem'; | ||
|
||
type EmailsFieldMenuItemProps = { | ||
dropdownId: string; | ||
isPrimary?: boolean; | ||
onEdit?: () => void; | ||
onSetAsPrimary?: () => void; | ||
onDelete?: () => void; | ||
email: string; | ||
}; | ||
|
||
export const EmailsFieldMenuItem = ({ | ||
dropdownId, | ||
isPrimary, | ||
onEdit, | ||
onSetAsPrimary, | ||
onDelete, | ||
email, | ||
}: EmailsFieldMenuItemProps) => { | ||
return ( | ||
<MultiItemFieldMenuItem | ||
dropdownId={dropdownId} | ||
isPrimary={isPrimary} | ||
value={email} | ||
onEdit={onEdit} | ||
onSetAsPrimary={onSetAsPrimary} | ||
onDelete={onDelete} | ||
DisplayComponent={EmailDisplay} | ||
/> | ||
); | ||
}; |
Oops, something went wrong.