Skip to content

Commit 280ab3f

Browse files
committed
fix lint errors
1 parent fbdaed7 commit 280ab3f

File tree

13 files changed

+78
-56
lines changed

13 files changed

+78
-56
lines changed

packages/base/src/internal/hooks/useSyncRef.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ export function useSyncRef<RefType = never>(
3535
ref(node);
3636
}
3737
if ({}.hasOwnProperty.call(ref, 'current')) {
38+
// React Refs are mutable
39+
// eslint-disable-next-line react-hooks/immutability
3840
(ref as MutableRefObject<RefType>).current = node;
3941
}
4042
}

packages/base/src/internal/wrapper/withWebComponent.cy.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ describe('withWebComponent', () => {
202202
</Button>
203203
<Popover
204204
open={open}
205+
// eslint-disable-next-line react-hooks/refs
205206
opener={btnRef.current}
206207
onClose={() => {
207208
setOpen(false);

packages/charts/src/components/LineChart/index.tsx

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { enrichEventWithDetails, ThemingParameters, useIsRTL, useSyncRef } from '@ui5/webcomponents-react-base';
4-
import { forwardRef, useCallback, useRef } from 'react';
4+
import { forwardRef, useRef } from 'react';
55
import type { LineProps, YAxisProps } from 'recharts';
66
import {
77
Brush,
@@ -182,32 +182,29 @@ const LineChart = forwardRef<HTMLDivElement, LineChartProps>((props, ref) => {
182182

183183
const onItemLegendClick = useLegendItemClick(onLegendClick);
184184
const preventOnClickCall = useRef(0);
185-
const onDataPointClickInternal = useCallback(
186-
(payload, eventOrIndex) => {
187-
if (eventOrIndex.dataKey && typeof onDataPointClick === 'function') {
188-
preventOnClickCall.current = 2;
189-
onDataPointClick(
190-
enrichEventWithDetails({} as any, {
191-
value: eventOrIndex.value,
192-
dataKey: eventOrIndex.dataKey,
193-
dataIndex: eventOrIndex.index,
194-
payload: eventOrIndex.payload,
195-
}),
196-
);
197-
} else if (typeof onClick === 'function' && preventOnClickCall.current === 0) {
198-
onClick(
199-
enrichEventWithDetails(eventOrIndex, {
200-
payload: payload?.activePayload?.[0]?.payload,
201-
activePayloads: payload?.activePayload,
202-
}),
203-
);
204-
}
205-
if (preventOnClickCall.current > 0) {
206-
preventOnClickCall.current -= 1;
207-
}
208-
},
209-
[onDataPointClick, preventOnClickCall.current],
210-
);
185+
const onDataPointClickInternal = (payload, eventOrIndex) => {
186+
if (eventOrIndex.dataKey && typeof onDataPointClick === 'function') {
187+
preventOnClickCall.current = 2;
188+
onDataPointClick(
189+
enrichEventWithDetails({} as any, {
190+
value: eventOrIndex.value,
191+
dataKey: eventOrIndex.dataKey,
192+
dataIndex: eventOrIndex.index,
193+
payload: eventOrIndex.payload,
194+
}),
195+
);
196+
} else if (typeof onClick === 'function' && preventOnClickCall.current === 0) {
197+
onClick(
198+
enrichEventWithDetails(eventOrIndex, {
199+
payload: payload?.activePayload?.[0]?.payload,
200+
activePayloads: payload?.activePayload,
201+
}),
202+
);
203+
}
204+
if (preventOnClickCall.current > 0) {
205+
preventOnClickCall.current -= 1;
206+
}
207+
};
211208

212209
const isBigDataSet = dataset?.length > 30;
213210
const primaryDimensionAccessor = primaryDimension?.accessor;

packages/charts/src/components/PieChart/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,9 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
159159
);
160160
};
161161

162-
const tooltipValueFormatter = useCallback(
163-
(value, name) => [measure.formatter(value), dimension.formatter(name)],
164-
[measure.formatter, dimension.formatter],
165-
);
162+
const tooltipValueFormatter = (value, name) => {
163+
return [measure.formatter(value), dimension.formatter(name)];
164+
};
166165

167166
const onItemLegendClick = useLegendItemClick(onLegendClick, () => measure.accessor);
168167
const onClickInternal = useOnClickInternal(onClick);
@@ -248,7 +247,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
248247
</g>
249248
);
250249
},
251-
[showActiveSegmentDataLabel, chartConfig.activeSegment, isDonutChart],
250+
[showActiveSegmentDataLabel, chartConfig.activeSegment, isDonutChart, chartRef, measure],
252251
);
253252

254253
const renderLabelLine = useCallback(
@@ -258,7 +257,7 @@ const PieChart = forwardRef<HTMLDivElement, PieChartProps>((props, ref) => {
258257
if (hideDataLabel || chartConfig.activeSegment === props.index) return null;
259258
return Pie.renderLabelLineItem({}, props, undefined);
260259
},
261-
[chartConfig.activeSegment, measure.hideDataLabel],
260+
[chartConfig.activeSegment, measure],
262261
);
263262

264263
const legendWrapperStyle = useMemo(() => {

packages/charts/src/components/TimelineChart/TimelineChartHeaders.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const TimelineChartColumnLabel = ({
7575
const newLabelArray = columnLabels
7676
? columnLabels
7777
: Array.from(Array(totalDuration).keys()).map((num) => `${num + start}`);
78+
// eslint-disable-next-line react-hooks/set-state-in-effect
7879
setLabelArray(newLabelArray);
7980
}
8081
}, [isDiscrete, columnLabels, start, totalDuration]);
@@ -95,7 +96,7 @@ const TimelineChartColumnLabel = ({
9596
height: `${halfHeaderHeight}px`,
9697
lineHeight: `${halfHeaderHeight}px`,
9798
}}
98-
></div>
99+
/>
99100
{isDiscrete ? (
100101
<div
101102
className={classNames.columnLabelItems}

packages/charts/src/components/TimelineChart/chartbody/TimelineChartBody.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,25 @@ const TimelineChartBody = ({
5555
const scaleExpRef = useRef(0);
5656
const [displayArrows, setDisplayArrows] = useState(false);
5757

58+
const onMouseWheelEvent = (evt: WheelEvent) => {
59+
evt.preventDefault();
60+
if (evt.deltaY < 0) {
61+
// Only scale up if scaled width will not exceed MAX_BODY_WIDTH
62+
const msrWidth = bodyRef.current.getBoundingClientRect().width;
63+
if (msrWidth * SCALE_FACTOR < MAX_BODY_WIDTH) {
64+
scaleExpRef.current++;
65+
}
66+
} else {
67+
// Only scale down if scaled width will not be less than original
68+
// width
69+
if (scaleExpRef.current > 0) {
70+
resetScroll();
71+
scaleExpRef.current--;
72+
}
73+
}
74+
onScale(Math.pow(SCALE_FACTOR, scaleExpRef.current));
75+
};
76+
5877
useEffect(() => {
5978
const bodyElement = bodyRef.current;
6079
bodyElement?.addEventListener('wheel', onMouseWheelEvent);
@@ -81,25 +100,6 @@ const TimelineChartBody = ({
81100
};
82101
const hideTooltip = () => tooltipRef.current?.onLeaveItem();
83102

84-
const onMouseWheelEvent = (evt: WheelEvent) => {
85-
evt.preventDefault();
86-
if (evt.deltaY < 0) {
87-
// Only scale up if scaled width will not exceed MAX_BODY_WIDTH
88-
const msrWidth = bodyRef.current.getBoundingClientRect().width;
89-
if (msrWidth * SCALE_FACTOR < MAX_BODY_WIDTH) {
90-
scaleExpRef.current++;
91-
}
92-
} else {
93-
// Only scale down if scaled width will not be less than original
94-
// width
95-
if (scaleExpRef.current > 0) {
96-
resetScroll();
97-
scaleExpRef.current--;
98-
}
99-
}
100-
onScale(Math.pow(SCALE_FACTOR, scaleExpRef.current));
101-
};
102-
103103
const showArrows = () => setDisplayArrows(true);
104104

105105
return (
@@ -121,6 +121,8 @@ const TimelineChartBody = ({
121121
dataSet={dataset}
122122
width={width}
123123
rowHeight={rowHeight}
124+
// todo: check side-effect
125+
// eslint-disable-next-line react-hooks/refs
124126
bodyRect={bodyRef.current?.getBoundingClientRect()}
125127
/>
126128
</TimelineChartLayer>

packages/charts/src/components/TimelineChart/chartbody/TimelineChartRow.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ const TimelineChartRow = ({
2727
showTooltip,
2828
hideTooltip,
2929
}: TimelineChartRowProps) => {
30+
// todo: fix mutation
31+
// eslint-disable-next-line react-hooks/immutability
3032
rowData.color = rowData.color ?? `var(--sapChart_OrderedColor_${(rowIndex % 12) + 1})`;
3133

3234
return (

packages/compat/src/components/Toolbar/OverflowPopover.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ export const OverflowPopover: FC<OverflowPopoverProps> = (props: OverflowPopover
164164
return (
165165
<OverflowPopoverContextProvider value={{ inPopover: true }}>
166166
{overflowButton ? (
167+
// eslint-disable-next-line react-hooks/refs
167168
cloneElement(overflowButton, { onClick: clonedOverflowButtonClick })
168169
) : (
169170
<ToggleButton

packages/compat/src/components/Toolbar/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,11 @@ const Toolbar = forwardRef<HTMLDivElement, ToolbarPropTypes>((props, ref) => {
190190
}, [children]);
191191

192192
const childrenWithRef = useMemo(() => {
193+
// eslint-disable-next-line react-hooks/refs
193194
controlMetaData.current = [];
194195

195196
let hasOnlySpacersOrSeparators = true;
197+
// eslint-disable-next-line react-hooks/refs
196198
const enrichedChildren = flatChildren.map((item, index) => {
197199
const itemRef: RefObject<HTMLDivElement> = createRef();
198200
// @ts-expect-error: if type is not defined, it's not a spacer

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,7 @@ describe('AnalyticalTable', () => {
37243724
// transform data to the pattern which is accepted by the tree table
37253725
// NOTES: this algorithm is less likely related to the bug, because in our reality project there is a different algorithm to generate the tree table and the bug still occurs.
37263726
const data = useMemo(() => {
3727+
// eslint-disable-next-line react-hooks/refs
37273728
raw.forEach((item) => {
37283729
const newItem = { ...item };
37293730
rowById.current[newItem.nodeId] = {
@@ -3747,7 +3748,7 @@ describe('AnalyticalTable', () => {
37473748
rowById.current[newItem.parentId].subRows.push(rowById.current[newItem.nodeId]);
37483749
}
37493750
});
3750-
3751+
// eslint-disable-next-line react-hooks/refs
37513752
return Object.values(rowById.current).filter((row) => !row.parentId);
37523753
}, [raw]);
37533754

0 commit comments

Comments
 (0)