Skip to content

Commit

Permalink
fix: Dropdown Overlapping Sidebar on Column Header Click in Horizonta…
Browse files Browse the repository at this point in the history
…l Table When Scrolling
  • Loading branch information
Vardhaman619 committed Nov 2, 2024
1 parent 558cc68 commit 3db6985
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from '@emotion/styled';
import { useRef } from 'react';
import { useRef, useState } from 'react';
import { useRecoilCallback } from 'recoil';

import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord';
Expand All @@ -15,6 +15,7 @@ import { mapColumnDefinitionsToViewFields } from '@/views/utils/mapColumnDefinit
import { RecordUpdateContext } from '../contexts/EntityUpdateMutationHookContext';
import { useRecordTable } from '../hooks/useRecordTable';

import { RecordTableScrollContext } from '@/object-record/record-table/contexts/RecordTableScrollContext';
import { RecordTableInternalEffect } from './RecordTableInternalEffect';

const StyledTableWithHeader = styled.div`
Expand Down Expand Up @@ -45,6 +46,8 @@ export const RecordTableWithWrappers = ({
recordTableId,
viewBarId,
}: RecordTableWithWrappersProps) => {
const [enableXScroll, setEnableXScroll] = useState(true);
const [enableYScroll, setEnableYScroll] = useState(true);
const tableBodyRef = useRef<HTMLDivElement>(null);

const { resetTableRowSelection, setRowSelected } = useRecordTable({
Expand All @@ -68,33 +71,46 @@ export const RecordTableWithWrappers = ({

return (
<EntityDeleteContext.Provider value={deleteOneRecord}>
<ScrollWrapper contextProviderName="recordTableWithWrappers">
<RecordUpdateContext.Provider value={updateRecordMutation}>
<StyledTableWithHeader>
<StyledTableContainer>
<StyledTableInternalContainer ref={tableBodyRef}>
<RecordTable
viewBarId={viewBarId}
<RecordTableScrollContext.Provider
value={{
enableXScroll,
enableYScroll,
setEnableXScroll,
setEnableYScroll,
}}
>
<ScrollWrapper
enableXScroll={enableXScroll}
enableYScroll={enableYScroll}
contextProviderName="recordTableWithWrappers"
>
<RecordUpdateContext.Provider value={updateRecordMutation}>
<StyledTableWithHeader>
<StyledTableContainer>
<StyledTableInternalContainer ref={tableBodyRef}>
<RecordTable
viewBarId={viewBarId}
recordTableId={recordTableId}
objectNameSingular={objectNameSingular}
onColumnsChange={handleColumnsChange}
/>
<DragSelect
dragSelectable={tableBodyRef}
onDragSelectionStart={() => {
resetTableRowSelection();
}}
onDragSelectionChange={setRowSelected}
/>
</StyledTableInternalContainer>
<RecordTableInternalEffect
tableBodyRef={tableBodyRef}
recordTableId={recordTableId}
objectNameSingular={objectNameSingular}
onColumnsChange={handleColumnsChange}
/>
<DragSelect
dragSelectable={tableBodyRef}
onDragSelectionStart={() => {
resetTableRowSelection();
}}
onDragSelectionChange={setRowSelected}
/>
</StyledTableInternalContainer>
<RecordTableInternalEffect
tableBodyRef={tableBodyRef}
recordTableId={recordTableId}
/>
</StyledTableContainer>
</StyledTableWithHeader>
</RecordUpdateContext.Provider>
</ScrollWrapper>
</StyledTableContainer>
</StyledTableWithHeader>
</RecordUpdateContext.Provider>
</ScrollWrapper>
</RecordTableScrollContext.Provider>
</EntityDeleteContext.Provider>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createContext, Dispatch, SetStateAction } from 'react';

export type RecordTableScrollContextProps = {
enableXScroll: boolean;
setEnableXScroll: Dispatch<SetStateAction<boolean>>;
enableYScroll: boolean;
setEnableYScroll: Dispatch<SetStateAction<boolean>>;
};

export const RecordTableScrollContext =
createContext<RecordTableScrollContextProps>(
{} as RecordTableScrollContextProps,
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';

import { RecordTableColumnHeadDropdownMenu } from './RecordTableColumnHeadDropdownMenu';

import { RecordTableScrollContext } from '@/object-record/record-table/contexts/RecordTableScrollContext';
import { useCallback, useContext } from 'react';
import { RecordTableColumnHead } from './RecordTableColumnHead';

type RecordTableColumnHeadWithDropdownProps = {
Expand All @@ -22,8 +24,21 @@ const StyledDropdown = styled(Dropdown)`
export const RecordTableColumnHeadWithDropdown = ({
column,
}: RecordTableColumnHeadWithDropdownProps) => {
const { setEnableXScroll, setEnableYScroll } = useContext(
RecordTableScrollContext,
);
const handleDropdownOpen = useCallback(() => {
setEnableXScroll(false);
setEnableYScroll(false);
}, [setEnableXScroll, setEnableYScroll]);
const handleDropdownClose = useCallback(() => {
setEnableXScroll(true);
setEnableYScroll(true);
}, [setEnableXScroll, setEnableYScroll]);
return (
<StyledDropdown
onOpen={handleDropdownOpen}
onClose={handleDropdownClose}
dropdownId={column.fieldMetadataId + '-header'}
clickableComponent={<RecordTableColumnHead column={column} />}
dropdownComponents={<RecordTableColumnHeadDropdownMenu column={column} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const Dropdown = ({
refs: [refs.floating],
callback: () => {
onClickOutside?.();

if (isDropdownOpen) {
closeDropdown();
}
Expand All @@ -131,10 +130,12 @@ export const Dropdown = ({
useScopedHotkeys(
[Key.Escape],
() => {
closeDropdown();
if (isDropdownOpen) {
closeDropdown();
}
},
dropdownHotkeyScope.scope,
[closeDropdown],
[closeDropdown, isDropdownOpen],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ export const ScrollWrapper = ({
}, [instance, setOverlayScrollbars]);

return (
<Context.Provider value={{ ref: scrollableRef, id: contextProviderName }}>
<Context.Provider
value={{
ref: scrollableRef,
id: contextProviderName,
}}
>
<StyledScrollWrapper ref={scrollableRef} className={className}>
{children}
</StyledScrollWrapper>
Expand Down

0 comments on commit 3db6985

Please sign in to comment.