-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Issue-5772] Add sort feature on settings tables #5787
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e378ecf
Add sort feature in settings page
Anand-Krishnan-M-J 1c933eb
Add new family state for table sort, remove sort click logic from cus…
Anand-Krishnan-M-J 53f3513
Remove unwanted reordering
Anand-Krishnan-M-J 25da00f
Typo
FelixMalfait 2a9e255
Merge branch 'main' into issue-5772
lucasbordeau 14f7ee5
WIP
lucasbordeau 51fba43
Merge branch 'main' into issue-5772
lucasbordeau bf00663
Refactor order by
lucasbordeau ebb1f29
Refactored object settings and object settings detail page with new g…
lucasbordeau e3559cb
Fixed tests
lucasbordeau 3a6d509
Fixed tests for useSortedArray
lucasbordeau 4d855e6
Finished refactor
lucasbordeau 4e0a5a8
Cleaned
lucasbordeau 3f5a16c
Fix
lucasbordeau 14d4897
Fixed initial sort and page container
lucasbordeau c5d7431
Fix
lucasbordeau 7644f9a
Fix
lucasbordeau 8e7ffad
Fix
lucasbordeau 2a76f93
Removed unused contexts
lucasbordeau 56a7993
Fix lint
lucasbordeau c3dc498
Fix ci
lucasbordeau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion
2
packages/twenty-front/src/modules/apollo/optimistic-effect/utils/sortCachedObjectEdges.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
3 changes: 2 additions & 1 deletion
3
packages/twenty-front/src/modules/object-metadata/hooks/useGetObjectOrderByField.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
3 changes: 2 additions & 1 deletion
3
packages/twenty-front/src/modules/object-metadata/utils/getObjectOrderByField.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
3 changes: 2 additions & 1 deletion
3
packages/twenty-front/src/modules/object-metadata/utils/getOrderByForFieldMetadataType.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
2 changes: 1 addition & 1 deletion
2
packages/twenty-front/src/modules/object-record/graphql/types/RecordGqlOperationOrderBy.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
48 changes: 48 additions & 0 deletions
48
...twenty-front/src/modules/object-record/multiple-objects/hooks/useCombinedGetTotalCount.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,48 @@ | ||
import { useQuery } from '@apollo/client'; | ||
|
||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; | ||
import { EMPTY_QUERY } from '@/object-record/constants/EmptyQuery'; | ||
import { RecordGqlOperationSignature } from '@/object-record/graphql/types/RecordGqlOperationSignature'; | ||
import { useGenerateCombinedFindManyRecordsQuery } from '@/object-record/multiple-objects/hooks/useGenerateCombinedFindManyRecordsQuery'; | ||
import { MultiObjectRecordQueryResult } from '@/object-record/relation-picker/hooks/useMultiObjectRecordsQueryResultFormattedAsObjectRecordForSelectArray'; | ||
|
||
export const useCombinedGetTotalCount = ({ | ||
objectMetadataItems, | ||
skip = false, | ||
}: { | ||
objectMetadataItems: ObjectMetadataItem[]; | ||
skip?: boolean; | ||
}) => { | ||
const operationSignatures = objectMetadataItems.map( | ||
(objectMetadataItem) => | ||
({ | ||
objectNameSingular: objectMetadataItem.nameSingular, | ||
variables: {}, | ||
fields: { | ||
id: true, | ||
}, | ||
}) satisfies RecordGqlOperationSignature, | ||
); | ||
|
||
const findManyQuery = useGenerateCombinedFindManyRecordsQuery({ | ||
operationSignatures, | ||
}); | ||
|
||
const { data } = useQuery<MultiObjectRecordQueryResult>( | ||
findManyQuery ?? EMPTY_QUERY, | ||
{ | ||
skip, | ||
}, | ||
); | ||
|
||
const totalCountByObjectMetadataItemNamePlural = Object.fromEntries( | ||
Object.entries(data ?? {}).map(([namePlural, objectRecordConnection]) => [ | ||
namePlural, | ||
objectRecordConnection.totalCount, | ||
]), | ||
); | ||
|
||
return { | ||
totalCountByObjectMetadataItemNamePlural, | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,28 +1,36 @@ | ||
import { useTheme } from '@emotion/react'; | ||
import styled from '@emotion/styled'; | ||
import { ReactNode, useMemo } from 'react'; | ||
import { Nullable, useIcons } from 'twenty-ui'; | ||
import { useMemo } from 'react'; | ||
import { IconMinus, IconPlus, isDefined, useIcons } from 'twenty-ui'; | ||
|
||
import { useGetRelationMetadata } from '@/object-metadata/hooks/useGetRelationMetadata'; | ||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { getObjectSlug } from '@/object-metadata/utils/getObjectSlug'; | ||
import { FieldIdentifierType } from '@/settings/data-model/types/FieldIdentifierType'; | ||
import { isFieldTypeSupportedInSettings } from '@/settings/data-model/utils/isFieldTypeSupportedInSettings'; | ||
import { TableCell } from '@/ui/layout/table/components/TableCell'; | ||
import { TableRow } from '@/ui/layout/table/components/TableRow'; | ||
|
||
import { RELATION_TYPES } from '../../constants/RelationTypes'; | ||
|
||
import { LABEL_IDENTIFIER_FIELD_METADATA_TYPES } from '@/object-metadata/constants/LabelIdentifierFieldMetadataTypes'; | ||
import { useFieldMetadataItem } from '@/object-metadata/hooks/useFieldMetadataItem'; | ||
import { useUpdateOneObjectMetadataItem } from '@/object-metadata/hooks/useUpdateOneObjectMetadataItem'; | ||
import { getFieldSlug } from '@/object-metadata/utils/getFieldSlug'; | ||
import { isLabelIdentifierField } from '@/object-metadata/utils/isLabelIdentifierField'; | ||
import { SettingsObjectFieldActiveActionDropdown } from '@/settings/data-model/object-details/components/SettingsObjectFieldActiveActionDropdown'; | ||
import { SettingsObjectFieldInactiveActionDropdown } from '@/settings/data-model/object-details/components/SettingsObjectFieldDisabledActionDropdown'; | ||
import { settingsObjectFieldsFamilyState } from '@/settings/data-model/object-details/states/settingsObjectFieldsFamilyState'; | ||
import { LightIconButton } from '@/ui/input/button/components/LightIconButton'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useRecoilState } from 'recoil'; | ||
import { RelationMetadataType } from '~/generated-metadata/graphql'; | ||
import { SettingsObjectDetailTableItem } from '~/pages/settings/data-model/types/SettingsObjectDetailTableItem'; | ||
import { SettingsObjectFieldDataType } from './SettingsObjectFieldDataType'; | ||
|
||
type SettingsObjectFieldItemTableRowProps = { | ||
ActionIcon: ReactNode; | ||
fieldMetadataItem: FieldMetadataItem; | ||
identifierType?: Nullable<FieldIdentifierType>; | ||
variant?: 'field-type' | 'identifier'; | ||
isRemoteObjectField?: boolean; | ||
to?: string; | ||
settingsObjectDetailTableItem: SettingsObjectDetailTableItem; | ||
status: 'active' | 'disabled'; | ||
mode: 'view' | 'new-field'; | ||
}; | ||
|
||
export const StyledObjectFieldTableRow = styled(TableRow)` | ||
|
@@ -40,13 +48,19 @@ const StyledIconTableCell = styled(TableCell)` | |
`; | ||
|
||
export const SettingsObjectFieldItemTableRow = ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a default value or error handling for |
||
ActionIcon, | ||
fieldMetadataItem, | ||
identifierType, | ||
variant = 'field-type', | ||
isRemoteObjectField, | ||
to, | ||
settingsObjectDetailTableItem, | ||
mode, | ||
status, | ||
}: SettingsObjectFieldItemTableRowProps) => { | ||
const { fieldMetadataItem, identifierType, objectMetadataItem } = | ||
settingsObjectDetailTableItem; | ||
|
||
const isRemoteObjectField = objectMetadataItem.isRemote; | ||
|
||
const variant = objectMetadataItem.isCustom ? 'identifier' : 'field-type'; | ||
|
||
const navigate = useNavigate(); | ||
|
||
const theme = useTheme(); | ||
const { getIcon } = useIcons(); | ||
const Icon = getIcon(fieldMetadataItem.icon); | ||
|
@@ -62,31 +76,94 @@ export const SettingsObjectFieldItemTableRow = ({ | |
const fieldType = fieldMetadataItem.type; | ||
const isFieldTypeSupported = isFieldTypeSupportedInSettings(fieldType); | ||
|
||
if (!isFieldTypeSupported) return null; | ||
|
||
const RelationIcon = relationType | ||
? RELATION_TYPES[relationType].Icon | ||
: undefined; | ||
|
||
const isLabelIdentifier = isLabelIdentifierField({ | ||
fieldMetadataItem, | ||
objectMetadataItem, | ||
}); | ||
|
||
const canToggleField = !isLabelIdentifier; | ||
|
||
const canBeSetAsLabelIdentifier = | ||
objectMetadataItem.isCustom && | ||
!isLabelIdentifier && | ||
LABEL_IDENTIFIER_FIELD_METADATA_TYPES.includes(fieldMetadataItem.type); | ||
|
||
const linkToNavigate = `./${getFieldSlug(fieldMetadataItem)}`; | ||
|
||
const { | ||
activateMetadataField, | ||
deactivateMetadataField, | ||
deleteMetadataField, | ||
} = useFieldMetadataItem(); | ||
|
||
const handleDisableField = (activeFieldMetadatItem: FieldMetadataItem) => { | ||
deactivateMetadataField(activeFieldMetadatItem); | ||
}; | ||
|
||
const { updateOneObjectMetadataItem } = useUpdateOneObjectMetadataItem(); | ||
|
||
const handleSetLabelIdentifierField = ( | ||
activeFieldMetadatItem: FieldMetadataItem, | ||
) => | ||
updateOneObjectMetadataItem({ | ||
idToUpdate: objectMetadataItem.id, | ||
updatePayload: { | ||
labelIdentifierFieldMetadataId: activeFieldMetadatItem.id, | ||
}, | ||
}); | ||
|
||
const [, setActiveSettingsObjectFields] = useRecoilState( | ||
settingsObjectFieldsFamilyState({ | ||
objectMetadataItemId: objectMetadataItem.id, | ||
}), | ||
); | ||
|
||
const handleToggleField = () => { | ||
setActiveSettingsObjectFields((previousFields) => { | ||
const newFields = isDefined(previousFields) | ||
? previousFields?.map((field) => | ||
field.id === fieldMetadataItem.id | ||
? { ...field, isActive: !field.isActive } | ||
: field, | ||
) | ||
: null; | ||
|
||
return newFields; | ||
}); | ||
}; | ||
|
||
const typeLabel = | ||
variant === 'field-type' | ||
? isRemoteObjectField | ||
? 'Remote' | ||
: fieldMetadataItem.isCustom | ||
? 'Custom' | ||
: 'Standard' | ||
: variant === 'identifier' | ||
? isDefined(identifierType) | ||
? identifierType === 'label' | ||
? 'Record text' | ||
: 'Record image' | ||
: '' | ||
: ''; | ||
|
||
if (!isFieldTypeSupported) return null; | ||
|
||
return ( | ||
<StyledObjectFieldTableRow to={to}> | ||
<StyledObjectFieldTableRow | ||
to={mode === 'view' ? linkToNavigate : undefined} | ||
> | ||
<StyledNameTableCell> | ||
{!!Icon && ( | ||
<Icon size={theme.icon.size.md} stroke={theme.icon.stroke.sm} /> | ||
)} | ||
{fieldMetadataItem.label} | ||
</StyledNameTableCell> | ||
<TableCell> | ||
{variant === 'field-type' && | ||
(isRemoteObjectField | ||
? 'Remote' | ||
: fieldMetadataItem.isCustom | ||
? 'Custom' | ||
: 'Standard')} | ||
{variant === 'identifier' && | ||
!!identifierType && | ||
(identifierType === 'label' ? 'Record text' : 'Record image')} | ||
</TableCell> | ||
<TableCell>{typeLabel}</TableCell> | ||
<TableCell> | ||
<SettingsObjectFieldDataType | ||
Icon={RelationIcon} | ||
|
@@ -105,7 +182,48 @@ export const SettingsObjectFieldItemTableRow = ({ | |
value={fieldType} | ||
/> | ||
</TableCell> | ||
<StyledIconTableCell>{ActionIcon}</StyledIconTableCell> | ||
<StyledIconTableCell> | ||
{status === 'active' ? ( | ||
mode === 'view' ? ( | ||
<SettingsObjectFieldActiveActionDropdown | ||
isCustomField={fieldMetadataItem.isCustom === true} | ||
scopeKey={fieldMetadataItem.id} | ||
onEdit={() => navigate(linkToNavigate)} | ||
onSetAsLabelIdentifier={ | ||
canBeSetAsLabelIdentifier | ||
? () => handleSetLabelIdentifierField(fieldMetadataItem) | ||
: undefined | ||
} | ||
onDeactivate={ | ||
isLabelIdentifier | ||
? undefined | ||
: () => handleDisableField(fieldMetadataItem) | ||
} | ||
/> | ||
) : ( | ||
canToggleField && ( | ||
<LightIconButton | ||
Icon={IconMinus} | ||
accent="tertiary" | ||
onClick={handleToggleField} | ||
/> | ||
) | ||
) | ||
) : mode === 'view' ? ( | ||
<SettingsObjectFieldInactiveActionDropdown | ||
isCustomField={fieldMetadataItem.isCustom === true} | ||
scopeKey={fieldMetadataItem.id} | ||
onActivate={() => activateMetadataField(fieldMetadataItem)} | ||
onDelete={() => deleteMetadataField(fieldMetadataItem)} | ||
/> | ||
) : ( | ||
<LightIconButton | ||
Icon={IconPlus} | ||
accent="tertiary" | ||
onClick={handleToggleField} | ||
/> | ||
)} | ||
</StyledIconTableCell> | ||
</StyledObjectFieldTableRow> | ||
); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure
fieldType
is correctly populated in all instances offieldMetadataItem
.