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.
4900 multi select field front implement expanded cells (twentyhq#5151)
Add expanded cell https://github.com/twentyhq/twenty/assets/29927851/363f2b44-7b3c-4771-a651-dfc4014da6ac ![image](https://github.com/twentyhq/twenty/assets/29927851/741bb0f9-fd1e-4a38-8b0e-71e144376876)
- Loading branch information
1 parent
089164b
commit 726d5d1
Showing
51 changed files
with
687 additions
and
405 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
102 changes: 29 additions & 73 deletions
102
packages/twenty-front/src/modules/activities/components/ActivityTargetChips.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 |
---|---|---|
@@ -1,91 +1,47 @@ | ||
import { useMemo } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { Chip, ChipVariant } from 'twenty-ui'; | ||
import { v4 } from 'uuid'; | ||
|
||
import { ActivityTargetWithTargetRecord } from '@/activities/types/ActivityTargetObject'; | ||
import { RecordChip } from '@/object-record/components/RecordChip'; | ||
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; | ||
import { | ||
ExpandableList, | ||
ExpandableListProps, | ||
} from '@/ui/layout/expandable-list/components/ExpandableList'; | ||
|
||
const MAX_RECORD_CHIPS_DISPLAY = 2; | ||
|
||
const StyledContainer = styled.div` | ||
const StyledContainer = styled.div<{ maxWidth?: number }>` | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: ${({ theme }) => theme.spacing(1)}; | ||
max-width: ${({ maxWidth }) => `${maxWidth}px` || 'none'}; | ||
`; | ||
|
||
const StyledRelationsListContainer = styled(StyledContainer)` | ||
padding: ${({ theme }) => theme.spacing(2)}; | ||
border-radius: ${({ theme }) => theme.spacing(1)}; | ||
background-color: ${({ theme }) => theme.background.secondary}; | ||
box-shadow: '0px 2px 4px ${({ theme }) => | ||
theme.boxShadow.light}, 2px 4px 16px ${({ theme }) => | ||
theme.boxShadow.strong}'; | ||
backdrop-filter: ${({ theme }) => theme.blur.strong}; | ||
`; | ||
|
||
const showMoreRelationsHandler = (event?: React.MouseEvent<HTMLDivElement>) => { | ||
event?.preventDefault(); | ||
event?.stopPropagation(); | ||
}; | ||
|
||
export const ActivityTargetChips = ({ | ||
activityTargetObjectRecords, | ||
isHovered, | ||
reference, | ||
maxWidth, | ||
}: { | ||
activityTargetObjectRecords: ActivityTargetWithTargetRecord[]; | ||
}) => { | ||
const dropdownId = useMemo(() => `multiple-relations-dropdown-${v4()}`, []); | ||
|
||
maxWidth?: number; | ||
} & ExpandableListProps) => { | ||
return ( | ||
<StyledContainer> | ||
{activityTargetObjectRecords | ||
?.slice(0, MAX_RECORD_CHIPS_DISPLAY) | ||
.map((activityTargetObjectRecord) => ( | ||
<RecordChip | ||
key={activityTargetObjectRecord.targetObject.id} | ||
record={activityTargetObjectRecord.targetObject} | ||
objectNameSingular={ | ||
activityTargetObjectRecord.targetObjectMetadataItem.nameSingular | ||
} | ||
/> | ||
))} | ||
|
||
{activityTargetObjectRecords.length > MAX_RECORD_CHIPS_DISPLAY && ( | ||
<div onClick={showMoreRelationsHandler}> | ||
<Dropdown | ||
dropdownId={dropdownId} | ||
dropdownHotkeyScope={{ | ||
scope: dropdownId, | ||
}} | ||
clickableComponent={ | ||
<Chip | ||
label={`+${ | ||
activityTargetObjectRecords.length - MAX_RECORD_CHIPS_DISPLAY | ||
}`} | ||
variant={ChipVariant.Highlighted} | ||
/> | ||
} | ||
dropdownOffset={{ x: 0, y: -20 }} | ||
dropdownComponents={ | ||
<StyledRelationsListContainer> | ||
{activityTargetObjectRecords.map( | ||
(activityTargetObjectRecord) => ( | ||
<RecordChip | ||
key={activityTargetObjectRecord.targetObject.id} | ||
record={activityTargetObjectRecord.targetObject} | ||
objectNameSingular={ | ||
activityTargetObjectRecord.targetObjectMetadataItem | ||
.nameSingular | ||
} | ||
/> | ||
), | ||
)} | ||
</StyledRelationsListContainer> | ||
} | ||
/> | ||
</div> | ||
)} | ||
<StyledContainer maxWidth={maxWidth}> | ||
<ExpandableList | ||
isHovered={isHovered} | ||
reference={reference} | ||
forceDisplayHiddenCount | ||
> | ||
{activityTargetObjectRecords.map( | ||
(activityTargetObjectRecord, index) => ( | ||
<RecordChip | ||
key={index} | ||
record={activityTargetObjectRecord.targetObject} | ||
objectNameSingular={ | ||
activityTargetObjectRecord.targetObjectMetadataItem.nameSingular | ||
} | ||
/> | ||
), | ||
)} | ||
</ExpandableList> | ||
</StyledContainer> | ||
); | ||
}; |
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.