-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Showing
14 changed files
with
419 additions
and
102 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
...ules/object-record/record-group/states/selectors/hiddenRecordGroupIdsComponentSelector.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
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
50 changes: 50 additions & 0 deletions
50
...t/src/modules/object-record/record-table/record-table-body/components/RecordTableBody.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,50 @@ | ||
import styled from '@emotion/styled'; | ||
import { MOBILE_VIEWPORT } from 'twenty-ui'; | ||
|
||
const StyledTbody = styled.tbody` | ||
&.first-columns-sticky { | ||
td:nth-of-type(1) { | ||
position: sticky; | ||
left: 0; | ||
z-index: 5; | ||
transition: 0.3s ease; | ||
} | ||
td:nth-of-type(2) { | ||
position: sticky; | ||
left: 11px; | ||
z-index: 5; | ||
transition: 0.3s ease; | ||
} | ||
td:nth-of-type(3) { | ||
position: sticky; | ||
left: 43px; | ||
z-index: 5; | ||
transition: 0.3s ease; | ||
@media (max-width: ${MOBILE_VIEWPORT}px) { | ||
& [data-testid='editable-cell-display-mode'] { | ||
[data-testid='tooltip'] { | ||
display: none; | ||
} | ||
[data-testid='chip'] { | ||
gap: 0; | ||
} | ||
} | ||
} | ||
&::after { | ||
content: ''; | ||
position: absolute; | ||
top: -1px; | ||
height: calc(100% + 2px); | ||
width: 4px; | ||
right: 0px; | ||
box-shadow: ${({ theme }) => theme.boxShadow.light}; | ||
clip-path: inset(0px -4px 0px 0px); | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const RecordTableBody = StyledTbody; |
78 changes: 17 additions & 61 deletions
78
...ules/object-record/record-table/record-table-body/components/RecordTableBodyDroppable.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
108 changes: 108 additions & 0 deletions
108
...d/record-table/record-table-body/components/RecordTableBodyRecordGroupDragDropContext.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,108 @@ | ||
import { DragDropContext, DropResult } from '@hello-pangea/dnd'; | ||
import { ReactNode, useContext } from 'react'; | ||
import { useRecoilCallback, useSetRecoilState } from 'recoil'; | ||
|
||
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord'; | ||
import { recordGroupDefinitionFamilyState } from '@/object-record/record-group/states/recordGroupDefinitionFamilyState'; | ||
import { recordIndexAllRowIdsComponentState } from '@/object-record/record-index/states/recordIndexAllRowIdsComponentState'; | ||
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext'; | ||
import { useComputeNewRowPosition } from '@/object-record/record-table/hooks/useComputeNewRowPosition'; | ||
import { isRemoveSortingModalOpenState } from '@/object-record/record-table/states/isRemoveSortingModalOpenState'; | ||
import { useRecoilComponentCallbackStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackStateV2'; | ||
import { getSnapshotValue } from '@/ui/utilities/state/utils/getSnapshotValue'; | ||
import { useGetCurrentView } from '@/views/hooks/useGetCurrentView'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const RecordTableBodyRecordGroupDragDropContext = ({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) => { | ||
const { objectNameSingular, recordTableId, objectMetadataItem } = | ||
useContext(RecordTableContext); | ||
|
||
const { updateOneRecord: updateOneRow } = useUpdateOneRecord({ | ||
objectNameSingular, | ||
}); | ||
|
||
const recordIndexAllRowIdsState = useRecoilComponentCallbackStateV2( | ||
recordIndexAllRowIdsComponentState, | ||
); | ||
|
||
const { currentViewWithCombinedFiltersAndSorts } = | ||
useGetCurrentView(recordTableId); | ||
|
||
const viewSorts = currentViewWithCombinedFiltersAndSorts?.viewSorts || []; | ||
|
||
const setIsRemoveSortingModalOpenState = useSetRecoilState( | ||
isRemoveSortingModalOpenState, | ||
); | ||
|
||
const computeNewRowPosition = useComputeNewRowPosition(); | ||
|
||
const handleDragEnd = useRecoilCallback( | ||
({ snapshot }) => | ||
(result: DropResult) => { | ||
const tableAllRowIds = getSnapshotValue( | ||
snapshot, | ||
recordIndexAllRowIdsState, | ||
); | ||
|
||
const recordGroupId = result.destination?.droppableId; | ||
|
||
if (!isDefined(recordGroupId)) { | ||
throw new Error('Record group id is not defined'); | ||
} | ||
|
||
const recordGroup = getSnapshotValue( | ||
snapshot, | ||
recordGroupDefinitionFamilyState(recordGroupId), | ||
); | ||
|
||
if (!isDefined(recordGroup)) { | ||
throw new Error('Record group is not defined'); | ||
} | ||
|
||
const fieldMetadata = objectMetadataItem.fields.find( | ||
(field) => field.id === recordGroup.fieldMetadataId, | ||
); | ||
|
||
if (!isDefined(fieldMetadata)) { | ||
throw new Error('Field metadata is not defined'); | ||
} | ||
|
||
if (viewSorts.length > 0) { | ||
setIsRemoveSortingModalOpenState(true); | ||
return; | ||
} | ||
|
||
console.log('DRAP - DROP: ', result, recordGroup); | ||
|
||
const computeResult = computeNewRowPosition(result, tableAllRowIds); | ||
|
||
if (!isDefined(computeResult)) { | ||
return; | ||
} | ||
|
||
updateOneRow({ | ||
idToUpdate: computeResult.draggedRecordId, | ||
updateOneRecordInput: { | ||
position: computeResult.newPosition, | ||
[fieldMetadata.name]: recordGroup.value, | ||
}, | ||
}); | ||
}, | ||
[ | ||
objectMetadataItem, | ||
computeNewRowPosition, | ||
setIsRemoveSortingModalOpenState, | ||
recordIndexAllRowIdsState, | ||
updateOneRow, | ||
viewSorts.length, | ||
], | ||
); | ||
|
||
return ( | ||
<DragDropContext onDragEnd={handleDragEnd}>{children}</DragDropContext> | ||
); | ||
}; |
Oops, something went wrong.