Skip to content

Commit

Permalink
Improve performance on TableBody but disable shadow on first column f…
Browse files Browse the repository at this point in the history
…reeze
  • Loading branch information
charlesBochet committed Apr 18, 2024
1 parent c402631 commit c42fcf4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { useRecoilValue } from 'recoil';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { RecordTableBody } from '@/object-record/record-table/components/RecordTableBody';
Expand All @@ -23,12 +22,9 @@ import { MoveFocusDirection } from '@/object-record/record-table/types/MoveFocus
import { TableCellPosition } from '@/object-record/record-table/types/TableCellPosition';
import { MOBILE_VIEWPORT } from '@/ui/theme/constants/MobileViewport';
import { RGBA } from '@/ui/theme/constants/Rgba';
import { scrollLeftState } from '@/ui/utilities/scroll/states/scrollLeftState';
import { scrollTopState } from '@/ui/utilities/scroll/states/scrollTopState';

const StyledTable = styled.table<{
freezeFirstColumns?: boolean;
freezeHeaders?: boolean;
}>`
border-radius: ${({ theme }) => theme.border.radius.sm};
border-spacing: 0;
Expand Down Expand Up @@ -150,8 +146,6 @@ export const RecordTable = ({
createRecord,
}: RecordTableProps) => {
const { scopeId } = useRecordTableStates(recordTableId);
const scrollLeft = useRecoilValue(scrollLeftState);
const scrollTop = useRecoilValue(scrollTopState);

const { objectMetadataItem } = useObjectMetadataItem({
objectNameSingular,
Expand Down Expand Up @@ -228,11 +222,7 @@ export const RecordTable = ({
onCellMouseEnter: handleContainerMouseEnter,
}}
>
<StyledTable
freezeFirstColumns={scrollLeft > 0}
freezeHeaders={scrollTop > 0}
className="entity-table-cell"
>
<StyledTable className="entity-table-cell">
<RecordTableHeader createRecord={createRecord} />
<RecordTableBodyEffect objectNameSingular={objectNameSingular} />
<RecordTableBody objectNameSingular={objectNameSingular} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const RecordTableRow = ({ recordId, rowIndex }: RecordTableRowProps) => {
const scrollWrapperRef = useContext(ScrollWrapperContext);

const { ref: elementRef, inView } = useInView({
root: scrollWrapperRef.current,
root: scrollWrapperRef.current?.querySelector(
'[data-overlayscrollbars-viewport="scrollbarHidden"]',
),
rootMargin: '1000px',
});

Expand All @@ -58,21 +60,21 @@ export const RecordTableRow = ({ recordId, rowIndex }: RecordTableRowProps) => {
<StyledTd>
<CheckboxCell />
</StyledTd>
{visibleTableColumns.map((column, columnIndex) =>
inView ? (
<RecordTableCellContext.Provider
value={{
columnDefinition: column,
columnIndex,
}}
key={column.fieldMetadataId}
>
<RecordTableCellFieldContextWrapper />
</RecordTableCellContext.Provider>
) : (
<td key={column.fieldMetadataId}></td>
),
)}
{inView
? visibleTableColumns.map((column, columnIndex) => (
<RecordTableCellContext.Provider
value={{
columnDefinition: column,
columnIndex,
}}
key={column.fieldMetadataId}
>
<RecordTableCellFieldContextWrapper />
</RecordTableCellContext.Provider>
))
: visibleTableColumns.map((column, columnIndex) => (
<td key={column.fieldMetadataId}></td>
))}
<td></td>
</tr>
</RecordTableRowContext.Provider>
Expand Down

0 comments on commit c42fcf4

Please sign in to comment.