forked from twentyhq/twenty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Used query fields for record table and record board (twentyhq#4857)
- Added two hooks for computing query keys for index table and index board. - Using query keys for findManyRecords on index table and index board
- Loading branch information
1 parent
a95972f
commit a3184dc
Showing
7 changed files
with
109 additions
and
8 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/twenty-front/src/modules/object-metadata/utils/getObjectMetadataIdentifierFields.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,20 @@ | ||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { getLabelIdentifierFieldMetadataItem } from '@/object-metadata/utils/getLabelIdentifierFieldMetadataItem'; | ||
|
||
export const getObjectMetadataIdentifierFields = ({ | ||
objectMetadataItem, | ||
}: { | ||
objectMetadataItem: ObjectMetadataItem; | ||
}) => { | ||
const labelIdentifierFieldMetadataItem = | ||
getLabelIdentifierFieldMetadataItem(objectMetadataItem); | ||
|
||
const imageIdentifierFieldMetadataItem = objectMetadataItem.fields.find( | ||
(field) => field.id === objectMetadataItem.imageIdentifierFieldMetadataId, | ||
); | ||
|
||
return { | ||
labelIdentifierFieldMetadataItem, | ||
imageIdentifierFieldMetadataItem, | ||
}; | ||
}; |
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
52 changes: 52 additions & 0 deletions
52
...es/twenty-front/src/modules/object-record/record-index/hooks/useRecordBoardQueryFields.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,52 @@ | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { getObjectMetadataIdentifierFields } from '@/object-metadata/utils/getObjectMetadataIdentifierFields'; | ||
import { useRecordBoardStates } from '@/object-record/record-board/hooks/internal/useRecordBoardStates'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const useRecordBoardQueryFields = ({ | ||
objectMetadataItem, | ||
recordBoardId, | ||
}: { | ||
recordBoardId: string; | ||
objectMetadataItem: ObjectMetadataItem; | ||
}) => { | ||
const { kanbanFieldMetadataNameState, visibleFieldDefinitionsState } = | ||
useRecordBoardStates(recordBoardId); | ||
|
||
const { imageIdentifierFieldMetadataItem, labelIdentifierFieldMetadataItem } = | ||
getObjectMetadataIdentifierFields({ objectMetadataItem }); | ||
|
||
const kanbanFieldMetadataName = useRecoilValue(kanbanFieldMetadataNameState); | ||
const visibleFieldDefinitions = useRecoilValue( | ||
visibleFieldDefinitionsState(), | ||
); | ||
|
||
const identifierQueryFields: Record<string, boolean> = {}; | ||
|
||
if (isDefined(labelIdentifierFieldMetadataItem)) { | ||
identifierQueryFields[labelIdentifierFieldMetadataItem.name] = true; | ||
} | ||
|
||
if (isDefined(imageIdentifierFieldMetadataItem)) { | ||
identifierQueryFields[imageIdentifierFieldMetadataItem.name] = true; | ||
} | ||
|
||
const queryFields: Record<string, any> = { | ||
id: true, | ||
...Object.fromEntries( | ||
visibleFieldDefinitions.map((visibleFieldDefinition) => [ | ||
visibleFieldDefinition.metadata.fieldName, | ||
true, | ||
]), | ||
), | ||
...identifierQueryFields, | ||
}; | ||
|
||
if (isDefined(kanbanFieldMetadataName)) { | ||
queryFields[kanbanFieldMetadataName] = true; | ||
} | ||
|
||
return queryFields; | ||
}; |
18 changes: 18 additions & 0 deletions
18
...es/twenty-front/src/modules/object-record/record-index/hooks/useRecordTableQueryFields.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,18 @@ | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates'; | ||
|
||
export const useRecordTableQueryFields = () => { | ||
const { visibleTableColumnsSelector } = useRecordTableStates(); | ||
|
||
const visibleTableColumns = useRecoilValue(visibleTableColumnsSelector()); | ||
|
||
const queryFields: Record<string, any> = { | ||
id: true, | ||
...Object.fromEntries( | ||
visibleTableColumns.map((column) => [column.metadata.fieldName, true]), | ||
), | ||
}; | ||
|
||
return queryFields; | ||
}; |