-
Notifications
You must be signed in to change notification settings - Fork 5.7k
fix: show disabled file chip when file no longer exists in timeline #19045
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| import { useEffect } from 'react'; | ||
| import { useContext, useEffect } from 'react'; | ||
|
|
||
| import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
| import { TimelineActivityContext } from '@/activities/timeline-activities/contexts/TimelineActivityContext'; | ||
| import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem'; | ||
| import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
| import { type FieldFilesValue } from '@/object-record/record-field/ui/types/FieldMetadata'; | ||
| import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; | ||
| import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue'; | ||
| import { useSetAtomFamilyState } from '@/ui/utilities/state/jotai/hooks/useSetAtomFamilyState'; | ||
| import { FieldMetadataType } from 'twenty-shared/types'; | ||
| import { isDefined } from 'twenty-shared/utils'; | ||
|
|
||
| export const EventFieldDiffValueEffect = ({ | ||
|
|
@@ -22,22 +26,50 @@ export const EventFieldDiffValueEffect = ({ | |
| diffArtificialRecordStoreId, | ||
| ); | ||
|
|
||
| const { recordId } = useContext(TimelineActivityContext); | ||
| const recordStore = useAtomFamilyStateValue(recordStoreFamilyState, recordId); | ||
|
|
||
| useEffect(() => { | ||
| if (!isDefined(diffRecord)) return; | ||
|
|
||
| let fieldValue: typeof diffRecord = diffRecord; | ||
|
|
||
| if ( | ||
| fieldMetadataItem.type === FieldMetadataType.FILES && | ||
| isDefined(recordStore) && | ||
| Array.isArray(diffRecord) | ||
| ) { | ||
| const currentFiles = Array.isArray(recordStore[fieldMetadataItem.name]) | ||
| ? (recordStore[fieldMetadataItem.name] as FieldFilesValue[]) | ||
| : []; | ||
| const currentFileMap = new Map( | ||
| currentFiles.map((file) => [file.fileId, file]), | ||
| ); | ||
|
|
||
| fieldValue = (diffRecord as FieldFilesValue[]).map((file) => { | ||
| const currentFile = currentFileMap.get(file.fileId); | ||
| if (isDefined(currentFile)) { | ||
| return currentFile; | ||
| } | ||
| return { ...file, isDeleted: true, url: undefined }; | ||
| }); | ||
| } | ||
|
|
||
| const forgedObjectRecord = { | ||
| __typename: mainObjectMetadataItem.nameSingular, | ||
| id: diffArtificialRecordStoreId, | ||
| [fieldMetadataItem.name]: diffRecord, | ||
| [fieldMetadataItem.name]: fieldValue, | ||
| }; | ||
|
|
||
| setRecordStore(forgedObjectRecord); | ||
| }, [ | ||
| diffRecord, | ||
| diffArtificialRecordStoreId, | ||
| fieldMetadataItem.name, | ||
| fieldMetadataItem.type, | ||
| mainObjectMetadataItem.nameSingular, | ||
| setRecordStore, | ||
| recordStore, | ||
| ]); | ||
|
Comment on lines
+37
to
73
|
||
|
|
||
| return <></>; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,37 @@ | ||
| import { styled } from '@linaria/react'; | ||
| import { t } from '@lingui/core/macro'; | ||
| import { useId, useState } from 'react'; | ||
| import { createPortal } from 'react-dom'; | ||
|
|
||
| import { FileIcon } from '@/file/components/FileIcon'; | ||
| import { type FieldFilesValue } from '@/object-record/record-field/ui/types/FieldMetadata'; | ||
| import { getFileCategoryFromExtension } from '@/object-record/record-field/ui/utils/getFileCategoryFromExtension'; | ||
| import { Chip, ChipVariant } from 'twenty-ui/components'; | ||
| import { AppTooltip, TooltipDelay, TooltipPosition } from 'twenty-ui/display'; | ||
| import { themeCssVariables } from 'twenty-ui/theme-constants'; | ||
|
|
||
| const MAX_WIDTH = 120; | ||
|
|
||
| const StyledClickableContainer = styled.div<{ clickable: boolean }>` | ||
| cursor: ${({ clickable }) => (clickable ? 'pointer' : 'inherit')}; | ||
| const StyledClickableContainer = styled.div<{ | ||
| clickable: boolean; | ||
| isDeleted: boolean; | ||
| }>` | ||
| cursor: ${({ clickable, isDeleted }) => | ||
| isDeleted ? 'not-allowed' : clickable ? 'pointer' : 'inherit'}; | ||
| display: inline-flex; | ||
| min-width: 0; | ||
| `; | ||
|
|
||
| const StyledDeletedLabel = styled.span` | ||
| color: ${themeCssVariables.font.color.secondary}; | ||
| font-size: inherit; | ||
| max-width: ${MAX_WIDTH}px; | ||
| overflow: hidden; | ||
| text-decoration: line-through; | ||
| text-overflow: ellipsis; | ||
| white-space: nowrap; | ||
| `; | ||
|
|
||
| type FileChipProps = { | ||
| file: FieldFilesValue; | ||
| onClick: (file: FieldFilesValue) => void; | ||
|
|
@@ -24,7 +43,11 @@ export const FileChip = ({ | |
| onClick, | ||
| forceDisableClick, | ||
| }: FileChipProps) => { | ||
| const isClickable = forceDisableClick !== true; | ||
| const isDeleted = file.isDeleted === true; | ||
| const isClickable = forceDisableClick !== true && !isDeleted; | ||
| const tooltipAnchorId = useId(); | ||
| const tooltipAnchorSelect = `[data-tooltip-anchor="${tooltipAnchorId}"]`; | ||
| const [shouldShowTooltip, setShouldShowTooltip] = useState(false); | ||
|
|
||
| const handleMouseDown = (event: React.MouseEvent): void => { | ||
| if (!isClickable) { | ||
|
|
@@ -45,17 +68,43 @@ export const FileChip = ({ | |
| ); | ||
|
|
||
| return ( | ||
| <StyledClickableContainer | ||
| clickable={isClickable} | ||
| onMouseDown={handleMouseDown} | ||
| > | ||
| <Chip | ||
| label={file.label ?? ''} | ||
| maxWidth={MAX_WIDTH} | ||
| leftComponent={fileIcon} | ||
| variant={ChipVariant.Highlighted} | ||
| <> | ||
| <StyledClickableContainer | ||
| data-tooltip-anchor={tooltipAnchorId} | ||
| clickable={isClickable} | ||
| /> | ||
| </StyledClickableContainer> | ||
| isDeleted={isDeleted} | ||
| onMouseDown={handleMouseDown} | ||
| onMouseEnter={() => isDeleted && setShouldShowTooltip(true)} | ||
| onMouseLeave={() => setShouldShowTooltip(false)} | ||
| > | ||
| <Chip | ||
| label={isDeleted ? '' : (file.label ?? '')} | ||
| isLabelHidden={isDeleted} | ||
| maxWidth={isDeleted ? undefined : MAX_WIDTH} | ||
| leftComponent={fileIcon} | ||
| rightComponent={ | ||
| isDeleted ? ( | ||
| <StyledDeletedLabel>{file.label}</StyledDeletedLabel> | ||
| ) : undefined | ||
| } | ||
| variant={ChipVariant.Highlighted} | ||
| clickable={isClickable} | ||
| /> | ||
| </StyledClickableContainer> | ||
| {isDeleted && | ||
| shouldShowTooltip && | ||
| createPortal( | ||
| <AppTooltip | ||
| anchorSelect={tooltipAnchorSelect} | ||
| content={t`File no longer exists`} | ||
| delay={TooltipDelay.shortDelay} | ||
| isOpen={true} | ||
| noArrow | ||
| place={TooltipPosition.Top} | ||
| positionStrategy="fixed" | ||
| />, | ||
| document.body, | ||
| )} | ||
|
Comment on lines
+94
to
+107
|
||
| </> | ||
| ); | ||
| }; | ||
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.
This code path handles
Array.isArray(diffRecord)(FILES diffs), butdiffRecordis still typed asRecord<string, any> | undefined, which doesn’t reflect arrays and forces repeated casts. Consider widening thediffRecordprop type (e.g.,unknown/anyor a union includingFieldFilesValue[]) so TypeScript matches the shapes this effect supports.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.
It was previous-exsiting. It depends on maintainer.