-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cddc92c
commit 10d86ee
Showing
41 changed files
with
454 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
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 |
---|---|---|
|
@@ -15,4 +15,5 @@ export type FilterType = | |
| 'SELECT' | ||
| 'RATING' | ||
| 'MULTI_SELECT' | ||
| 'ACTOR'; | ||
| 'ACTOR' | ||
| 'ARRAY'; |
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
34 changes: 34 additions & 0 deletions
34
...rc/modules/object-record/record-field/meta-types/display/components/ArrayFieldDisplay.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,34 @@ | ||
import { THEME_COMMON } from 'twenty-ui'; | ||
|
||
import { useFieldFocus } from '@/object-record/record-field/hooks/useFieldFocus'; | ||
import { useArrayFieldDisplay } from '@/object-record/record-field/meta-types/hooks/useArrayFieldDisplay'; | ||
import { ArrayDisplay } from '@/ui/field/display/components/ArrayDisplay'; | ||
import styled from '@emotion/styled'; | ||
|
||
const spacing1 = THEME_COMMON.spacing(1); | ||
|
||
const StyledContainer = styled.div` | ||
align-items: center; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: ${spacing1}; | ||
justify-content: flex-start; | ||
max-width: 100%; | ||
overflow: hidden; | ||
`; | ||
|
||
export const ArrayFieldDisplay = () => { | ||
const { fieldValue } = useArrayFieldDisplay(); | ||
|
||
const { isFocused } = useFieldFocus(); | ||
|
||
if (!Array.isArray(fieldValue)) { | ||
return <></>; | ||
} | ||
|
||
return ( | ||
<StyledContainer> | ||
<ArrayDisplay value={fieldValue} isFocused={isFocused} /> | ||
</StyledContainer> | ||
); | ||
}; |
44 changes: 44 additions & 0 deletions
44
...ges/twenty-front/src/modules/object-record/record-field/meta-types/hooks/useArrayField.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,44 @@ | ||
import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; | ||
import { usePersistField } from '@/object-record/record-field/hooks/usePersistField'; | ||
import { FieldArrayValue } from '@/object-record/record-field/types/FieldMetadata'; | ||
import { assertFieldMetadata } from '@/object-record/record-field/types/guards/assertFieldMetadata'; | ||
import { isFieldArray } from '@/object-record/record-field/types/guards/isFieldArray'; | ||
import { arraySchema } from '@/object-record/record-field/types/guards/isFieldArrayValue'; | ||
import { recordStoreFamilySelector } from '@/object-record/record-store/states/selectors/recordStoreFamilySelector'; | ||
import { useContext } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
|
||
export const useArrayField = () => { | ||
const { recordId, fieldDefinition, hotkeyScope } = useContext(FieldContext); | ||
|
||
assertFieldMetadata(FieldMetadataType.Array, isFieldArray, fieldDefinition); | ||
|
||
const fieldName = fieldDefinition.metadata.fieldName; | ||
|
||
const [fieldValue, setFieldValue] = useRecoilState<FieldArrayValue>( | ||
recordStoreFamilySelector({ | ||
recordId, | ||
fieldName, | ||
}), | ||
); | ||
|
||
const persistField = usePersistField(); | ||
|
||
const persistArrayField = (nextValue: string[]) => { | ||
if (!nextValue) persistField(null); | ||
|
||
try { | ||
persistField(arraySchema.parse(nextValue)); | ||
} catch { | ||
return; | ||
} | ||
}; | ||
|
||
return { | ||
fieldValue, | ||
setFieldValue, | ||
persistArrayField, | ||
hotkeyScope, | ||
}; | ||
}; |
24 changes: 24 additions & 0 deletions
24
...nty-front/src/modules/object-record/record-field/meta-types/hooks/useArrayFieldDisplay.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,24 @@ | ||
import { FieldContext } from '@/object-record/record-field/contexts/FieldContext'; | ||
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition'; | ||
import { | ||
FieldArrayMetadata, | ||
FieldArrayValue, | ||
} from '@/object-record/record-field/types/FieldMetadata'; | ||
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext'; | ||
import { useContext } from 'react'; | ||
|
||
export const useArrayFieldDisplay = () => { | ||
const { recordId, fieldDefinition } = useContext(FieldContext); | ||
|
||
const { fieldName } = fieldDefinition.metadata; | ||
|
||
const fieldValue = useRecordFieldValue<FieldArrayValue | undefined>( | ||
recordId, | ||
fieldName, | ||
); | ||
|
||
return { | ||
fieldDefinition: fieldDefinition as FieldDefinition<FieldArrayMetadata>, | ||
fieldValue, | ||
}; | ||
}; |
37 changes: 37 additions & 0 deletions
37
...nt/src/modules/object-record/record-field/meta-types/input/components/ArrayFieldInput.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,37 @@ | ||
import { useArrayField } from '@/object-record/record-field/meta-types/hooks/useArrayField'; | ||
import { ArrayFieldMenuItem } from '@/object-record/record-field/meta-types/input/components/ArrayFieldMenuItem'; | ||
import { MultiItemFieldInput } from '@/object-record/record-field/meta-types/input/components/MultiItemFieldInput'; | ||
import { useMemo } from 'react'; | ||
|
||
type ArrayFieldInputProps = { | ||
onCancel?: () => void; | ||
}; | ||
|
||
export const ArrayFieldInput = ({ onCancel }: ArrayFieldInputProps) => { | ||
const { persistArrayField, hotkeyScope, fieldValue } = useArrayField(); | ||
|
||
const arrayItems = useMemo<Array<string>>( | ||
() => (Array.isArray(fieldValue) ? fieldValue : []), | ||
[fieldValue], | ||
); | ||
|
||
return ( | ||
<MultiItemFieldInput | ||
hotkeyScope={hotkeyScope} | ||
newItemLabel="Add Item" | ||
items={arrayItems} | ||
onPersist={persistArrayField} | ||
onCancel={onCancel} | ||
placeholder="Enter value" | ||
renderItem={({ value, index, handleEdit, handleDelete }) => ( | ||
<ArrayFieldMenuItem | ||
key={index} | ||
dropdownId={`${hotkeyScope}-array-${index}`} | ||
value={value} | ||
onEdit={handleEdit} | ||
onDelete={handleDelete} | ||
/> | ||
)} | ||
></MultiItemFieldInput> | ||
); | ||
}; |
27 changes: 27 additions & 0 deletions
27
...src/modules/object-record/record-field/meta-types/input/components/ArrayFieldMenuItem.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,27 @@ | ||
import { MultiItemFieldMenuItem } from '@/object-record/record-field/meta-types/input/components/MultiItemFieldMenuItem'; | ||
import { ArrayDisplay } from '@/ui/field/display/components/ArrayDisplay'; | ||
|
||
type ArrayFieldMenuItemProps = { | ||
dropdownId: string; | ||
onEdit?: () => void; | ||
onDelete?: () => void; | ||
value: string; | ||
}; | ||
|
||
export const ArrayFieldMenuItem = ({ | ||
dropdownId, | ||
onEdit, | ||
onDelete, | ||
value, | ||
}: ArrayFieldMenuItemProps) => { | ||
return ( | ||
<MultiItemFieldMenuItem | ||
dropdownId={dropdownId} | ||
value={value} | ||
onEdit={onEdit} | ||
onDelete={onDelete} | ||
DisplayComponent={() => <ArrayDisplay value={[value]} isInputDisplay />} | ||
hasPrimaryButton={false} | ||
/> | ||
); | ||
}; |
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.