-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
332 additions
and
14 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
8 changes: 8 additions & 0 deletions
8
...c/modules/object-record/record-field/meta-types/display/components/DomainFieldDisplay.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 { useDomainField } from '@/object-record/record-field/meta-types/hooks/useDomainField'; | ||
import { DomainDisplay } from '@/ui/field/display/components/DomainDisplay'; | ||
|
||
export const DomainFieldDisplay = () => { | ||
const { fieldValue } = useDomainField(); | ||
|
||
return <DomainDisplay value={fieldValue} />; | ||
}; |
51 changes: 51 additions & 0 deletions
51
...es/twenty-front/src/modules/object-record/record-field/meta-types/hooks/useDomainField.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,51 @@ | ||
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 { FieldDomainValue } from '@/object-record/record-field/types/FieldMetadata'; | ||
import { isFieldDomain } from '@/object-record/record-field/types/guards/isFieldDomain'; | ||
import { isFieldDomainValue } from '@/object-record/record-field/types/guards/isFieldDomainValue'; | ||
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 useDomainField = () => { | ||
const { entityId, fieldDefinition, hotkeyScope } = useContext(FieldContext); | ||
|
||
assertFieldMetadata(FieldMetadataType.Domain, isFieldDomain, fieldDefinition); | ||
|
||
const fieldName = fieldDefinition.metadata.fieldName; | ||
|
||
const [fieldValue, setFieldValue] = useRecoilState<FieldDomainValue>( | ||
recordStoreFamilySelector({ | ||
recordId: entityId, | ||
fieldName: fieldName, | ||
}), | ||
); | ||
|
||
const { setDraftValue, getDraftValueSelector } = | ||
useRecordFieldInput<FieldDomainValue>(`${entityId}-${fieldName}`); | ||
|
||
const draftValue = useRecoilValue(getDraftValueSelector()); | ||
|
||
const persistField = usePersistField(); | ||
|
||
const persistDomainField = (newValue: FieldDomainValue) => { | ||
if (!isFieldDomainValue(newValue)) return; | ||
|
||
persistField(newValue); | ||
}; | ||
|
||
return { | ||
fieldDefinition, | ||
fieldValue, | ||
draftValue, | ||
setDraftValue, | ||
setFieldValue, | ||
hotkeyScope, | ||
persistDomainField, | ||
}; | ||
}; |
90 changes: 90 additions & 0 deletions
90
...t/src/modules/object-record/record-field/meta-types/input/components/DomainFieldInput.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,90 @@ | ||
import { useDomainField } from '@/object-record/record-field/meta-types/hooks/useDomainField'; | ||
import { FieldInputOverlay } from '@/ui/field/input/components/FieldInputOverlay'; | ||
import { TextInput } from '@/ui/field/input/components/TextInput'; | ||
|
||
import { FieldInputEvent } from './DateTimeFieldInput'; | ||
|
||
export type DomainFieldInputProps = { | ||
onClickOutside?: FieldInputEvent; | ||
onEnter?: FieldInputEvent; | ||
onEscape?: FieldInputEvent; | ||
onTab?: FieldInputEvent; | ||
onShiftTab?: FieldInputEvent; | ||
}; | ||
|
||
export const DomainFieldInput = ({ | ||
onEnter, | ||
onEscape, | ||
onClickOutside, | ||
onTab, | ||
onShiftTab, | ||
}: DomainFieldInputProps) => { | ||
const { draftValue, setDraftValue, hotkeyScope, persistDomainField } = | ||
useDomainField(); | ||
|
||
const handleEnter = (domain: string) => { | ||
onEnter?.(() => | ||
persistDomainField({ | ||
primaryLink: domain, | ||
}), | ||
); | ||
}; | ||
|
||
const handleEscape = (domain: string) => { | ||
onEscape?.(() => | ||
persistDomainField({ | ||
primaryLink: domain, | ||
}), | ||
); | ||
}; | ||
|
||
const handleClickOutside = ( | ||
event: MouseEvent | TouchEvent, | ||
domain: string, | ||
) => { | ||
onClickOutside?.(() => | ||
persistDomainField({ | ||
primaryLink: domain, | ||
}), | ||
); | ||
}; | ||
|
||
const handleTab = (domain: string) => { | ||
onTab?.(() => | ||
persistDomainField({ | ||
primaryLink: domain, | ||
}), | ||
); | ||
}; | ||
|
||
const handleShiftTab = (domain: string) => { | ||
onShiftTab?.(() => | ||
persistDomainField({ | ||
primaryLink: domain, | ||
}), | ||
); | ||
}; | ||
|
||
const handleChange = (domain: string) => { | ||
setDraftValue({ | ||
primaryLink: domain, | ||
}); | ||
}; | ||
|
||
return ( | ||
<FieldInputOverlay> | ||
<TextInput | ||
value={draftValue?.primaryLink ?? ''} | ||
autoFocus | ||
placeholder="Domain" | ||
hotkeyScope={hotkeyScope} | ||
onClickOutside={handleClickOutside} | ||
onEnter={handleEnter} | ||
onEscape={handleEscape} | ||
onTab={handleTab} | ||
onShiftTab={handleShiftTab} | ||
onChange={handleChange} | ||
/> | ||
</FieldInputOverlay> | ||
); | ||
}; |
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
9 changes: 9 additions & 0 deletions
9
packages/twenty-front/src/modules/object-record/record-field/types/guards/isFieldDomain.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,9 @@ | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
|
||
import { FieldDefinition } from '../FieldDefinition'; | ||
import { FieldDomainMetadata, FieldMetadata } from '../FieldMetadata'; | ||
|
||
export const isFieldDomain = ( | ||
field: Pick<FieldDefinition<FieldMetadata>, 'type'>, | ||
): field is FieldDefinition<FieldDomainMetadata> => | ||
field.type === FieldMetadataType.Domain; |
12 changes: 12 additions & 0 deletions
12
...es/twenty-front/src/modules/object-record/record-field/types/guards/isFieldDomainValue.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,12 @@ | ||
import { z } from 'zod'; | ||
|
||
import { FieldDomainValue } from '../FieldMetadata'; | ||
|
||
const domainSchema = z.object({ | ||
primaryLink: z.string(), | ||
secondaryLinks: z.array(z.string()).optional().nullable(), | ||
}) satisfies z.ZodType<FieldDomainValue>; | ||
|
||
export const isFieldDomainValue = ( | ||
fieldValue: unknown, | ||
): fieldValue is FieldDomainValue => domainSchema.safeParse(fieldValue).success; |
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
Oops, something went wrong.