• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / ui5-webcomponents-react / 12009185407

25 Nov 2024 11:35AM CUT coverage: 87.142% (-0.02%) from 87.16%
12009185407

push

github

web-flow
fix(NavigationLayout): add root export (#6657)

2901 of 3864 branches covered (75.08%)

5056 of 5802 relevant lines covered (87.14%)

50139.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

4.0
/packages/main/src/components/AnalyticalTable/pluginHooks/useOnColumnResize.ts
1
'use client';
2

3
import { debounce } from '@ui5/webcomponents-react-base';
4
import { useEffect, useRef } from 'react';
5
import type { ReactTableHooks, TableInstance } from '../types/index.js';
6

7
interface useOnColumnResizeOptions {
8
  /**
9
   * If `liveUpdate` is `true`, the resize function will fire every time the width has changed depending on the `options.wait` delay.
10
   */
11
  liveUpdate?: boolean;
12
  /**
13
   * The number of milliseconds for which the calls are to be delayed. __Defaults to `100`__.
14
   *
15
   * __Note:__ If `liveUpdate` is `true`, this option has no effect.
16
   */
17
  wait?: number;
18
}
19

20
type useOnColumnResizeFunc = (e: { columnWidth: number; header: Record<string, any> }) => void;
21

22
/**
23
 * Plugin Hook that adds a callback which is fired on column resize.
24
 *
25
 * @param {event} callback Fired when the column is resized by dragging the "Resizer".
26
 * @param {Object=} options Additional options.
27
 * @param {number=} options.wait If `liveUpdate` is `true`, the resize function will fire every time the width has changed depending on the `options.wait` delay.
28
 * @param {boolean=} options.liveUpdate The number of milliseconds for which the calls are to be delayed. Defaults to `100`.
29
 */
30
export const useOnColumnResize = (callback: useOnColumnResizeFunc, options?: useOnColumnResizeOptions) => {
418✔
31
  const debouncedEvent = debounce(callback, options?.wait ?? 100);
×
32

33
  const useInstance = (instance: TableInstance) => {
×
34
    const { state, columns } = instance;
×
35
    const { columnResizing } = state;
×
36
    const { isResizingColumn, columnWidths } = columnResizing;
×
37
    const prevHeaderIsResizing = useRef(undefined);
×
38

39
    useEffect(() => {
×
40
      if (isResizingColumn && options?.liveUpdate) {
×
41
        const currentHeader = columns.find((item) => item.id === isResizingColumn);
×
42
        debouncedEvent({
×
43
          columnWidth: columnWidths[isResizingColumn],
44
          header: currentHeader
45
        });
46
      }
47
    }, [columnResizing, options?.liveUpdate, columns]);
48

49
    useEffect(() => {
×
50
      if (options?.liveUpdate) {
×
51
        return () => debouncedEvent.cancel();
×
52
      }
53
    }, [options?.liveUpdate]);
54

55
    useEffect(() => {
×
56
      if (!options?.liveUpdate) {
×
57
        const currentHeader = columns.find((item) => item.id === prevHeaderIsResizing.current);
×
58
        if (isResizingColumn) {
×
59
          prevHeaderIsResizing.current = isResizingColumn;
×
60
        }
61
        if (!isResizingColumn && prevHeaderIsResizing.current) {
×
62
          callback({
×
63
            columnWidth: columnWidths[prevHeaderIsResizing.current],
64
            header: currentHeader
65
          });
66
        }
67
      }
68
    }, [columnResizing, options?.liveUpdate, columns]);
69
  };
70

71
  const useOnColumnResizeHooks = (hooks: ReactTableHooks) => {
×
72
    hooks.useFinalInstance.push(useInstance);
×
73
  };
74

75
  useOnColumnResizeHooks.pluginName = 'useOnColumnResize';
×
76

77
  return useOnColumnResizeHooks;
×
78
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc