Fixes table header (#1087)
* Wrap up Front chat * Wrap up Front chat * Disable entity selectionwhen starting from menu
This commit is contained in:
@ -3,9 +3,9 @@ import styled from '@emotion/styled';
|
|||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { SelectedSortType, SortType } from '@/ui/filter-n-sort/types/interface';
|
import { SelectedSortType, SortType } from '@/ui/filter-n-sort/types/interface';
|
||||||
|
import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';
|
||||||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';
|
||||||
|
|
||||||
import { DragSelect } from '../../../../utils/DragSelect';
|
|
||||||
import { useLeaveTableFocus } from '../hooks/useLeaveTableFocus';
|
import { useLeaveTableFocus } from '../hooks/useLeaveTableFocus';
|
||||||
import { useMapKeyboardToSoftFocus } from '../hooks/useMapKeyboardToSoftFocus';
|
import { useMapKeyboardToSoftFocus } from '../hooks/useMapKeyboardToSoftFocus';
|
||||||
import { useSetRowSelectedState } from '../hooks/useSetRowSelectedState';
|
import { useSetRowSelectedState } from '../hooks/useSetRowSelectedState';
|
||||||
@ -103,7 +103,6 @@ export function EntityTable<SortField>({
|
|||||||
useUpdateEntityMutation,
|
useUpdateEntityMutation,
|
||||||
}: OwnProps<SortField>) {
|
}: OwnProps<SortField>) {
|
||||||
const tableBodyRef = useRef<HTMLDivElement>(null);
|
const tableBodyRef = useRef<HTMLDivElement>(null);
|
||||||
const entityTableBodyRef = useRef<HTMLTableSectionElement>(null);
|
|
||||||
|
|
||||||
const rowIds = useRecoilValue(tableRowIdsState);
|
const rowIds = useRecoilValue(tableRowIdsState);
|
||||||
const setRowSelectedState = useSetRowSelectedState();
|
const setRowSelectedState = useSetRowSelectedState();
|
||||||
@ -138,11 +137,11 @@ export function EntityTable<SortField>({
|
|||||||
<StyledTableWrapper>
|
<StyledTableWrapper>
|
||||||
<StyledTable>
|
<StyledTable>
|
||||||
<EntityTableHeader />
|
<EntityTableHeader />
|
||||||
<EntityTableBody tbodyRef={entityTableBodyRef} />
|
<EntityTableBody />
|
||||||
</StyledTable>
|
</StyledTable>
|
||||||
</StyledTableWrapper>
|
</StyledTableWrapper>
|
||||||
<DragSelect
|
<DragSelect
|
||||||
dragSelectable={entityTableBodyRef}
|
dragSelectable={tableBodyRef}
|
||||||
onDragSelectionStart={resetSelections}
|
onDragSelectionStart={resetSelections}
|
||||||
onDragSelectionChange={setRowSelectedState}
|
onDragSelectionChange={setRowSelectedState}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { Ref } from 'react';
|
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
|
|
||||||
import { isNavbarSwitchingSizeState } from '@/ui/layout/states/isNavbarSwitchingSizeState';
|
import { isNavbarSwitchingSizeState } from '@/ui/layout/states/isNavbarSwitchingSizeState';
|
||||||
@ -10,11 +9,7 @@ import { tableRowIdsState } from '../states/tableRowIdsState';
|
|||||||
|
|
||||||
import { EntityTableRow } from './EntityTableRow';
|
import { EntityTableRow } from './EntityTableRow';
|
||||||
|
|
||||||
type OwnProps = {
|
export function EntityTableBody() {
|
||||||
tbodyRef: Ref<HTMLTableSectionElement>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function EntityTableBody({ tbodyRef }: OwnProps) {
|
|
||||||
const rowIds = useRecoilValue(tableRowIdsState);
|
const rowIds = useRecoilValue(tableRowIdsState);
|
||||||
|
|
||||||
const isNavbarSwitchingSize = useRecoilValue(isNavbarSwitchingSizeState);
|
const isNavbarSwitchingSize = useRecoilValue(isNavbarSwitchingSizeState);
|
||||||
@ -28,7 +23,7 @@ export function EntityTableBody({ tbodyRef }: OwnProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tbody ref={tbodyRef}>
|
<tbody>
|
||||||
{rowIds.map((rowId, index) => (
|
{rowIds.map((rowId, index) => (
|
||||||
<RowIdContext.Provider value={rowId} key={rowId}>
|
<RowIdContext.Provider value={rowId} key={rowId}>
|
||||||
<RowIndexContext.Provider value={index}>
|
<RowIndexContext.Provider value={index}>
|
||||||
|
|||||||
@ -188,7 +188,7 @@ export function EntityTableHeader() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<thead>
|
<thead data-select-disable>
|
||||||
<tr>
|
<tr>
|
||||||
<th
|
<th
|
||||||
style={{
|
style={{
|
||||||
|
|||||||
@ -16,6 +16,17 @@ export function DragSelect({
|
|||||||
onDragSelectionStart,
|
onDragSelectionStart,
|
||||||
}: OwnProps) {
|
}: OwnProps) {
|
||||||
const { DragSelection } = useSelectionContainer({
|
const { DragSelection } = useSelectionContainer({
|
||||||
|
shouldStartSelecting: (target) => {
|
||||||
|
if (target instanceof HTMLElement) {
|
||||||
|
let el = target;
|
||||||
|
while (el.parentElement && !el.dataset.selectDisable) {
|
||||||
|
el = el.parentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
return el.dataset.selectDisable !== 'true';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
onSelectionStart: onDragSelectionStart,
|
onSelectionStart: onDragSelectionStart,
|
||||||
onSelectionChange: (box) => {
|
onSelectionChange: (box) => {
|
||||||
const scrollAwareBox = {
|
const scrollAwareBox = {
|
||||||
Reference in New Issue
Block a user