Skip to content

Commit f207e26

Browse files
committed
AT: cleanup & fix more lint errors
1 parent 1b2723a commit f207e26

File tree

9 files changed

+54
-68
lines changed

9 files changed

+54
-68
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ export const InfiniteScrolling: Story = {
254254
const [data, setData] = useState(args.data.slice(0, 50));
255255
const [loading, setLoading] = useState(false);
256256
const offset = useRef(50);
257-
const onLoadMore = () => {
257+
const onLoadMore = (e) => {
258+
args.onLoadMore(e);
258259
setLoading(true);
259260
};
260261
useEffect(() => {

packages/main/src/components/AnalyticalTable/TableBody/VirtualTableBody.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
AnalyticalTablePropTypes,
77
ClassNames,
88
DivWithCustomScrollProp,
9-
ReactVirtualScrollToMethods,
109
TableInstance,
1110
TriggerScrollState,
1211
} from '../types/index.js';
@@ -104,6 +103,8 @@ export const VirtualTableBody = (props: VirtualTableBodyProps) => {
104103
width: `${columnVirtualizer.getTotalSize()}px`,
105104
}}
106105
>
106+
{/* Safe to update: lastNonEmptyRow ref holds non-render data only.*/}
107+
{/* eslint-disable-next-line react-hooks/refs */}
107108
{rowVirtualizer.getVirtualItems().map((virtualRow, visibleRowIndex) => {
108109
const row = rows[virtualRow.index];
109110
const rowIndexWithHeader = virtualRow.index + 1;

packages/main/src/components/AnalyticalTable/TableBody/VirtualTableBodyContainer.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ export const VirtualTableBodyContainer = (props: VirtualTableBodyContainerProps)
4848

4949
useEffect(() => {
5050
if (parentRef.current) {
51+
// Trigger one-time re-render after first render -> safe to set state here
52+
// eslint-disable-next-line react-hooks/set-state-in-effect
5153
setIsMounted(true);
5254
}
53-
}, [parentRef.current]);
55+
}, [parentRef]);
5456

5557
const dataLength = rows.length;
5658

@@ -102,16 +104,16 @@ export const VirtualTableBodyContainer = (props: VirtualTableBodyContainerProps)
102104
}
103105
},
104106
[
107+
handleExternalScroll,
105108
infiniteScroll,
106109
infiniteScrollThreshold,
107-
onLoadMore,
108-
rows,
109110
internalRowHeight,
110-
firedInfiniteLoadEvents,
111-
lastScrollTop,
112-
handleExternalScroll,
111+
isGrouped,
112+
onLoadMore,
113113
popInRowHeight,
114+
rows,
114115
tableBodyHeight,
116+
visibleRows,
115117
],
116118
);
117119

packages/main/src/components/AnalyticalTable/VerticalResizer.tsx

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface VerticalResizerProps {
99
analyticalTableRef: MutableRefObject<any>;
1010
dispatch: (e: { type: string; payload?: any }) => void;
1111
extensionsHeight: number;
12-
internalRowHeight: number;
1312
hasPopInColumns: boolean;
1413
popInRowHeight: number;
1514
rowsLength: number;
@@ -30,7 +29,6 @@ export const VerticalResizer = (props: VerticalResizerProps) => {
3029
analyticalTableRef,
3130
dispatch,
3231
extensionsHeight,
33-
internalRowHeight,
3432
hasPopInColumns,
3533
popInRowHeight,
3634
rowsLength,
@@ -47,16 +45,13 @@ export const VerticalResizer = (props: VerticalResizerProps) => {
4745

4846
const i18nBundle = useI18nBundle('@ui5/webcomponents-react');
4947

50-
const handleResizeStart = useCallback(
51-
(e) => {
52-
e.preventDefault();
53-
const touchEvent = isTouchEvent(e, 'touchstart');
54-
startY.current = touchEvent ? Math.round(e.touches[0].pageY) : e.pageY;
55-
setMountTouchEvents(touchEvent);
56-
setIsDragging(true);
57-
},
58-
[startY.current, setIsDragging],
59-
);
48+
const handleResizeStart = useCallback((e) => {
49+
e.preventDefault();
50+
const touchEvent = isTouchEvent(e, 'touchstart');
51+
startY.current = touchEvent ? Math.round(e.touches[0].pageY) : e.pageY;
52+
setMountTouchEvents(touchEvent);
53+
setIsDragging(true);
54+
}, []);
6055

6156
const handleMove = useCallback(
6257
(e) => {
@@ -67,27 +62,27 @@ export const VerticalResizer = (props: VerticalResizerProps) => {
6762
},
6863
[setResizerPosition],
6964
);
70-
const handleResizeEnd = useCallback(
71-
(e) => {
72-
setIsDragging(false);
73-
const rowCount = Math.floor(
74-
(analyticalTableRef.current.clientHeight +
75-
(isTouchEvent(e, 'touchend') ? Math.round(e.changedTouches[0].pageY) : e.pageY) -
76-
startY.current -
77-
extensionsHeight -
78-
5) /*resizer height*/ /
79-
popInRowHeight,
80-
);
81-
if (hasPopInColumns) {
82-
dispatch({ type: 'INTERACTIVE_ROWS_HAVE_POPIN', payload: true });
83-
}
84-
dispatch({
85-
type: 'VISIBLE_ROWS',
86-
payload: { visibleRows: rowCount },
87-
});
88-
},
89-
[analyticalTableRef.current?.clientHeight, startY.current, extensionsHeight, internalRowHeight, dispatch],
90-
);
65+
const handleResizeEnd = (e: TouchEvent | MouseEvent) => {
66+
setIsDragging(false);
67+
const rowCount = Math.floor(
68+
(analyticalTableRef.current.clientHeight +
69+
(isTouchEvent(e, 'touchend')
70+
? Math.round((e as TouchEvent).changedTouches[0].pageY)
71+
: (e as MouseEvent).pageY) -
72+
startY.current -
73+
extensionsHeight -
74+
5) /*resizer height*/ /
75+
popInRowHeight,
76+
);
77+
if (hasPopInColumns) {
78+
dispatch({ type: 'INTERACTIVE_ROWS_HAVE_POPIN', payload: true });
79+
}
80+
dispatch({
81+
type: 'VISIBLE_ROWS',
82+
payload: { visibleRows: rowCount },
83+
});
84+
};
85+
9186
useEffect(() => {
9287
const removeEventListeners = () => {
9388
if (mountTouchEvents) {
@@ -119,15 +114,11 @@ export const VerticalResizer = (props: VerticalResizerProps) => {
119114
const resizerPosLeft = verticalResizerRef.current?.getBoundingClientRect()?.left + window.scrollX;
120115
const resizerPosWidth = verticalResizerRef.current?.getBoundingClientRect()?.width;
121116
if (!isDragging && resizerPosTop > 0) {
122-
setResizerPosition({ left: resizerPosLeft, top: resizerPosTop, width: resizerPosWidth });
117+
requestAnimationFrame(() => {
118+
setResizerPosition({ left: resizerPosLeft, top: resizerPosTop, width: resizerPosWidth });
119+
});
123120
}
124-
}, [verticalResizerRef.current?.getBoundingClientRect()?.top, isDragging]);
125-
126-
useEffect(() => {
127-
return () => {
128-
dispatch({ type: 'WITH_POPIN', payload: false });
129-
};
130-
}, []);
121+
}, [isDragging]);
131122

132123
const isInitial = useRef(true);
133124
useEffect(() => {

packages/main/src/components/AnalyticalTable/defaults/FilterComponent/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ import { Input } from '../../../../webComponents/Input/index.js';
55
import type { FilterProps } from '../../types/index.js';
66

77
export const DefaultFilterComponent = ({ column, accessibleNameRef }: FilterProps) => {
8+
const { setFilter } = column;
89
const handleInput: InputPropTypes['onInput'] = useCallback(
910
(e) => {
1011
// Setting the filter to `undefined` removes it
11-
column.setFilter(e.target.value || undefined);
12+
setFilter(e.target.value || undefined);
1213
},
13-
[column.setFilter],
14+
[setFilter],
1415
);
1516

1617
const handleKeyDown: InputPropTypes['onKeyDown'] = (e) => {

packages/main/src/components/AnalyticalTable/hooks/useIsFirefox.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export function useIsFirefox() {
99
const [isFirefox, setIsFirefox] = useState(false);
1010

1111
useEffect(() => {
12+
// safe here because we only update state after mount for SSR hydration
13+
// eslint-disable-next-line react-hooks/set-state-in-effect
1214
setIsFirefox(isFirefoxFn());
1315
}, []);
1416

packages/main/src/components/AnalyticalTable/hooks/useKeyboardNavigation.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const useGetTableProps = (
6868
{ instance: { webComponentsReactProperties, data, columns, state } }: { instance: TableInstance },
6969
) => {
7070
const { showOverlay, tableRef } = webComponentsReactProperties;
71+
const { isRtl } = state;
7172
const currentlyFocusedCell = useRef<HTMLElement>(null);
7273
const noData = data.length === 0;
7374

@@ -153,12 +154,11 @@ const useGetTableProps = (
153154
}
154155
}
155156
},
156-
[currentlyFocusedCell.current, tableRef.current, noData],
157+
[noData, tableRef],
157158
);
158159

159160
const onKeyboardNavigation = useCallback(
160161
(e) => {
161-
const { isRtl } = state;
162162
const isActiveItemInSubComponent = Object.prototype.hasOwnProperty.call(
163163
e.target.dataset,
164164
'subcomponentActiveElement',
@@ -284,6 +284,8 @@ const useGetTableProps = (
284284
);
285285
if (hasSubcomponent && !currentlyFocusedCell.current?.dataset?.subcomponent) {
286286
currentlyFocusedCell.current.tabIndex = -1;
287+
// Happens outside of React's scope
288+
// eslint-disable-next-line react-hooks/immutability
287289
firstChildOfParent.tabIndex = 0;
288290
firstChildOfParent.dataset.rowIndexSub = `${rowIndex}`;
289291
firstChildOfParent.dataset.columnIndexSub = `${columnIndex}`;
@@ -325,7 +327,7 @@ const useGetTableProps = (
325327
}
326328
}
327329
},
328-
[currentlyFocusedCell.current, tableRef.current, state?.isRtl],
330+
[isRtl, tableRef],
329331
);
330332
if (showOverlay) {
331333
return tableProps;

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,6 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
541541
}
542542
}, [selectedRowIds]);
543543

544-
useEffect(() => {
545-
if (tableState?.interactiveRowsHavePopIn && (!tableState?.popInColumns || tableState?.popInColumns?.length === 0)) {
546-
dispatch({ type: 'WITH_POPIN', payload: false });
547-
}
548-
}, [tableState?.interactiveRowsHavePopIn, tableState?.popInColumns?.length]);
549-
550544
const tableBodyHeight = useMemo(() => {
551545
if (typeof tableState.bodyHeight === 'number') {
552546
return tableState.bodyHeight;
@@ -895,7 +889,6 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
895889
analyticalTableRef={analyticalTableRef}
896890
dispatch={dispatch}
897891
extensionsHeight={extensionsHeight}
898-
internalRowHeight={internalRowHeight}
899892
rowsLength={rows.length}
900893
visibleRows={internalVisibleRowCount}
901894
handleOnLoadMore={handleOnLoadMore}

packages/main/src/components/AnalyticalTable/types/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,6 @@ export interface TriggerScrollState {
294294
args: [number, Omit<ScrollToOptions, 'behavior'>?];
295295
}
296296

297-
export interface ReactVirtualScrollToMethods {
298-
scrollToOffset?: (offset: number, options?: ScrollToOptions) => void;
299-
scrollToIndex?: (index: number, options?: ScrollToOptions) => void;
300-
horizontalScrollToOffset?: (offset: number, options?: ScrollToOptions) => void;
301-
horizontalScrollToIndex?: (index: number, options?: ScrollToOptions) => void;
302-
}
303-
304297
interface PopInColumnsState {
305298
id: string;
306299
column: ColumnType;

0 commit comments

Comments
 (0)