|
| 1 | +import { RecordTableCellPortalWrapper } from '@/object-record/record-table/record-table-cell/components/RecordTableCellPortalWrapper'; |
| 2 | +import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue'; |
| 3 | + |
| 4 | +import { hasRecordGroupsComponentSelector } from '@/object-record/record-group/states/selectors/hasRecordGroupsComponentSelector'; |
| 5 | +import { TABLE_Z_INDEX } from '@/object-record/record-table/constants/TableZIndex'; |
| 6 | +import { RecordTableCellFocusedPortalContent } from '@/object-record/record-table/record-table-cell/components/RecordTableCellFocusedPortalContent'; |
| 7 | +import { RecordTableCellPortalRootContainer } from '@/object-record/record-table/record-table-cell/components/RecordTableCellPortalRootContainer'; |
| 8 | +import { isRecordTableScrolledHorizontallyComponentState } from '@/object-record/record-table/states/isRecordTableScrolledHorizontallyComponentState'; |
| 9 | +import { isRecordTableScrolledVerticallyComponentState } from '@/object-record/record-table/states/isRecordTableScrolledVerticallyComponentState'; |
| 10 | +import { recordTableFocusPositionComponentState } from '@/object-record/record-table/states/recordTableFocusPositionComponentState'; |
| 11 | +import { recordTableHoverPositionComponentState } from '@/object-record/record-table/states/recordTableHoverPositionComponentState'; |
| 12 | +import { isDefined } from 'twenty-shared/utils'; |
| 13 | + |
| 14 | +export const RecordTableCellFocusedPortal = () => { |
| 15 | + const focusPosition = useRecoilComponentValue( |
| 16 | + recordTableFocusPositionComponentState, |
| 17 | + ); |
| 18 | + |
| 19 | + const isRecordTableScrolledVertically = useRecoilComponentValue( |
| 20 | + isRecordTableScrolledVerticallyComponentState, |
| 21 | + ); |
| 22 | + |
| 23 | + const isRecordTableScrolledHorizontally = useRecoilComponentValue( |
| 24 | + isRecordTableScrolledHorizontallyComponentState, |
| 25 | + ); |
| 26 | + |
| 27 | + const hasRecordGroups = useRecoilComponentValue( |
| 28 | + hasRecordGroupsComponentSelector, |
| 29 | + ); |
| 30 | + |
| 31 | + const hoverPosition = useRecoilComponentValue( |
| 32 | + recordTableHoverPositionComponentState, |
| 33 | + ); |
| 34 | + |
| 35 | + const isUnderHoveredPortal = |
| 36 | + isDefined(hoverPosition) && |
| 37 | + isDefined(focusPosition) && |
| 38 | + hoverPosition.column === focusPosition.column && |
| 39 | + hoverPosition.row === focusPosition.row; |
| 40 | + |
| 41 | + if (!isDefined(focusPosition) || isUnderHoveredPortal) { |
| 42 | + return null; |
| 43 | + } |
| 44 | + |
| 45 | + const isOnFirstScrollableColumn = focusPosition.column === 1; |
| 46 | + const isOnLabelIdentifierStickyColumn = focusPosition.column === 0; |
| 47 | + |
| 48 | + const zIndexForHoveredPortalOnFirstScrollableColumnWithoutGroups = |
| 49 | + isRecordTableScrolledHorizontally && isRecordTableScrolledVertically |
| 50 | + ? TABLE_Z_INDEX.withoutGroups.scrolledBothVerticallyAndHorizontally |
| 51 | + .hoverPortalCellOnFirstScrollableColumn |
| 52 | + : isRecordTableScrolledHorizontally |
| 53 | + ? TABLE_Z_INDEX.withoutGroups.scrolledHorizontallyOnly |
| 54 | + .hoverPortalCellOnFirstScrollableColumn |
| 55 | + : isRecordTableScrolledVertically |
| 56 | + ? TABLE_Z_INDEX.withoutGroups.scrolledVerticallyOnly |
| 57 | + .hoverPortalCellOnFirstScrollableColumn |
| 58 | + : TABLE_Z_INDEX.withoutGroups.noScrollAtAll |
| 59 | + .hoverPortalCellOnFirstScrollableColumn; |
| 60 | + |
| 61 | + const zIndexForHoveredPortalOnLabelIdentifierStickyColumnWithoutGroups = |
| 62 | + isRecordTableScrolledHorizontally && isRecordTableScrolledVertically |
| 63 | + ? TABLE_Z_INDEX.withoutGroups.scrolledBothVerticallyAndHorizontally |
| 64 | + .hoverPortalCellOnLabelIdentifierColumn |
| 65 | + : isRecordTableScrolledHorizontally |
| 66 | + ? TABLE_Z_INDEX.withoutGroups.scrolledHorizontallyOnly |
| 67 | + .hoverPortalCellOnLabelIdentifierColumn |
| 68 | + : isRecordTableScrolledVertically |
| 69 | + ? TABLE_Z_INDEX.withoutGroups.scrolledVerticallyOnly |
| 70 | + .hoverPortalCellOnLabelIdentifierColumn |
| 71 | + : TABLE_Z_INDEX.withoutGroups.noScrollAtAll |
| 72 | + .hoverPortalCellOnLabelIdentifierColumn; |
| 73 | + |
| 74 | + const zIndexForHoveredPortalOnNormalColumnWithoutGroups = |
| 75 | + isRecordTableScrolledHorizontally && isRecordTableScrolledVertically |
| 76 | + ? TABLE_Z_INDEX.withoutGroups.scrolledBothVerticallyAndHorizontally |
| 77 | + .hoverPortalCellOnNormalColumn |
| 78 | + : isRecordTableScrolledHorizontally |
| 79 | + ? TABLE_Z_INDEX.withoutGroups.scrolledHorizontallyOnly |
| 80 | + .hoverPortalCellOnNormalColumn |
| 81 | + : isRecordTableScrolledVertically |
| 82 | + ? TABLE_Z_INDEX.withoutGroups.scrolledVerticallyOnly |
| 83 | + .hoverPortalCellOnNormalColumn |
| 84 | + : TABLE_Z_INDEX.withoutGroups.noScrollAtAll |
| 85 | + .hoverPortalCellOnNormalColumn; |
| 86 | + |
| 87 | + const zIndexForHoveredPortalWithoutGroups = isOnFirstScrollableColumn |
| 88 | + ? zIndexForHoveredPortalOnFirstScrollableColumnWithoutGroups |
| 89 | + : isOnLabelIdentifierStickyColumn |
| 90 | + ? zIndexForHoveredPortalOnLabelIdentifierStickyColumnWithoutGroups |
| 91 | + : zIndexForHoveredPortalOnNormalColumnWithoutGroups; |
| 92 | + |
| 93 | + const zIndexForHoveredPortalOnFirstScrollableColumnWithGroups = |
| 94 | + isRecordTableScrolledHorizontally && isRecordTableScrolledVertically |
| 95 | + ? TABLE_Z_INDEX.withGroups.scrolledBothVerticallyAndHorizontally |
| 96 | + .hoverPortalCellOnFirstScrollableColumn |
| 97 | + : isRecordTableScrolledHorizontally |
| 98 | + ? TABLE_Z_INDEX.withGroups.scrolledHorizontallyOnly |
| 99 | + .hoverPortalCellOnFirstScrollableColumn |
| 100 | + : isRecordTableScrolledVertically |
| 101 | + ? TABLE_Z_INDEX.withGroups.scrolledVerticallyOnly |
| 102 | + .hoverPortalCellOnFirstScrollableColumn |
| 103 | + : TABLE_Z_INDEX.withGroups.noScrollAtAll |
| 104 | + .hoverPortalCellOnFirstScrollableColumn; |
| 105 | + |
| 106 | + const zIndexForHoveredPortalOnLabelIdentifierStickyColumnWithGroups = |
| 107 | + isRecordTableScrolledHorizontally && isRecordTableScrolledVertically |
| 108 | + ? TABLE_Z_INDEX.withGroups.scrolledBothVerticallyAndHorizontally |
| 109 | + .hoverPortalCellOnLabelIdentifierColumn |
| 110 | + : isRecordTableScrolledHorizontally |
| 111 | + ? TABLE_Z_INDEX.withGroups.scrolledHorizontallyOnly |
| 112 | + .hoverPortalCellOnLabelIdentifierColumn |
| 113 | + : isRecordTableScrolledVertically |
| 114 | + ? TABLE_Z_INDEX.withGroups.scrolledVerticallyOnly |
| 115 | + .hoverPortalCellOnLabelIdentifierColumn |
| 116 | + : TABLE_Z_INDEX.withGroups.noScrollAtAll |
| 117 | + .hoverPortalCellOnLabelIdentifierColumn; |
| 118 | + |
| 119 | + const zIndexForHoveredPortalOnNormalColumnWithGroups = |
| 120 | + isRecordTableScrolledHorizontally && isRecordTableScrolledVertically |
| 121 | + ? TABLE_Z_INDEX.withGroups.scrolledBothVerticallyAndHorizontally |
| 122 | + .hoverPortalCellOnNormalColumn |
| 123 | + : isRecordTableScrolledHorizontally |
| 124 | + ? TABLE_Z_INDEX.withGroups.scrolledHorizontallyOnly |
| 125 | + .hoverPortalCellOnNormalColumn |
| 126 | + : isRecordTableScrolledVertically |
| 127 | + ? TABLE_Z_INDEX.withGroups.scrolledVerticallyOnly |
| 128 | + .hoverPortalCellOnNormalColumn |
| 129 | + : TABLE_Z_INDEX.withGroups.noScrollAtAll |
| 130 | + .hoverPortalCellOnNormalColumn; |
| 131 | + |
| 132 | + const zIndexForHoveredPortalWithGroups = isOnFirstScrollableColumn |
| 133 | + ? zIndexForHoveredPortalOnFirstScrollableColumnWithGroups |
| 134 | + : isOnLabelIdentifierStickyColumn |
| 135 | + ? zIndexForHoveredPortalOnLabelIdentifierStickyColumnWithGroups |
| 136 | + : zIndexForHoveredPortalOnNormalColumnWithGroups; |
| 137 | + |
| 138 | + const zIndex = hasRecordGroups |
| 139 | + ? zIndexForHoveredPortalWithGroups |
| 140 | + : zIndexForHoveredPortalWithoutGroups; |
| 141 | + |
| 142 | + return ( |
| 143 | + <RecordTableCellPortalWrapper position={focusPosition}> |
| 144 | + <RecordTableCellPortalRootContainer zIndex={zIndex}> |
| 145 | + <RecordTableCellFocusedPortalContent /> |
| 146 | + </RecordTableCellPortalRootContainer> |
| 147 | + </RecordTableCellPortalWrapper> |
| 148 | + ); |
| 149 | +}; |
0 commit comments