@trackunit/filters-filter-bar 0.0.129 → 0.0.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +15 -8
- package/index.esm.js +16 -9
- package/package.json +3 -3
- package/src/lib/components/VirtualizedList.d.ts +3 -2
package/index.cjs.js
CHANGED
|
@@ -11,7 +11,7 @@ var reactComponents = require('@trackunit/react-components');
|
|
|
11
11
|
var reactRouterDom = require('react-router-dom');
|
|
12
12
|
var reactCoreHooks = require('@trackunit/react-core-hooks');
|
|
13
13
|
var reactCoreContextsApi = require('@trackunit/react-core-contexts-api');
|
|
14
|
-
var reactVirtual = require('react-virtual');
|
|
14
|
+
var reactVirtual = require('@tanstack/react-virtual');
|
|
15
15
|
var reactFormComponents = require('@trackunit/react-form-components');
|
|
16
16
|
var dequal = require('dequal');
|
|
17
17
|
var lodash = require('lodash');
|
|
@@ -543,19 +543,26 @@ const toggleFilterValue = (value) => {
|
|
|
543
543
|
* @template T - The type of data items in the list.
|
|
544
544
|
* @returns {JSX.Element} - Returns the virtualized list component.
|
|
545
545
|
*/
|
|
546
|
-
const VirtualizedList = ({ parentRef, count, children }) => {
|
|
547
|
-
const rowVirtualizer = reactVirtual.
|
|
548
|
-
|
|
546
|
+
const VirtualizedList = ({ parentRef, count, rowHeight = 40, children, }) => {
|
|
547
|
+
const rowVirtualizer = reactVirtual.useVirtualizer({
|
|
548
|
+
count,
|
|
549
|
+
getScrollElement: () => parentRef.current,
|
|
550
|
+
estimateSize: react.useCallback((i) => rowHeight, [rowHeight]),
|
|
549
551
|
overscan: 10,
|
|
550
|
-
parentRef,
|
|
551
552
|
});
|
|
552
|
-
|
|
553
|
+
react.useEffect(() => {
|
|
554
|
+
// this ensures the cache is cleared if the rowHeight changes
|
|
555
|
+
if (rowHeight) {
|
|
556
|
+
rowVirtualizer.measure();
|
|
557
|
+
}
|
|
558
|
+
}, [rowHeight, rowVirtualizer]);
|
|
559
|
+
return (jsxRuntime.jsx("div", { className: "relative", style: { height: rowVirtualizer.getTotalSize() }, children: rowVirtualizer.getVirtualItems().map((virtualRow, index) => (jsxRuntime.jsx("div", { style: {
|
|
553
560
|
position: "absolute",
|
|
554
561
|
top: 0,
|
|
555
562
|
left: 0,
|
|
556
563
|
width: "100%",
|
|
557
564
|
transform: `translateY(${virtualRow.start}px)`,
|
|
558
|
-
}, children: children(
|
|
565
|
+
}, children: children(index) }, index))) }));
|
|
559
566
|
};
|
|
560
567
|
|
|
561
568
|
/**
|
|
@@ -567,7 +574,7 @@ const DynamicFilterList = ({ rowCount, keyMapper, labelMapper, prefixMapper, onC
|
|
|
567
574
|
const [t] = useTranslation();
|
|
568
575
|
const parentRef = react.useRef(null);
|
|
569
576
|
const updatedRowCount = react.useMemo(() => (showRequestMoreUseSearch ? rowCount + 1 : rowCount), [rowCount, showRequestMoreUseSearch]);
|
|
570
|
-
return (jsxRuntime.jsx(reactFilterComponents.FilterBody, { limitSize: true, ref: parentRef, children: jsxRuntime.jsx(VirtualizedList, { parentRef: parentRef, count: updatedRowCount, children: index => {
|
|
577
|
+
return (jsxRuntime.jsx(reactFilterComponents.FilterBody, { limitSize: true, ref: parentRef, children: jsxRuntime.jsx(VirtualizedList, { rowHeight: 40, parentRef: parentRef, count: updatedRowCount, children: index => {
|
|
571
578
|
return (jsxRuntime.jsx("div", { children: showRequestMoreUseSearch && index === rowCount ? (jsxRuntime.jsxs("div", { className: "p-3 pt-2", children: [jsxRuntime.jsx("span", { className: "text-sm text-gray-600", children: t("filter.more.options.if.you.search.title", { count: rowCount }) }), jsxRuntime.jsx("br", {}), jsxRuntime.jsx("span", { className: "text-sm italic text-gray-400", children: t("filter.more.options.if.you.search.description") })] })) : type === "Radio" ? (jsxRuntime.jsx(reactFilterComponents.RadioFilterItem, { dataTestId: "dynamic-filter-radio-" + keyMapper(index), label: labelMapper(index), value: keyMapper(index), selected: checked(index), prefix: prefixMapper === null || prefixMapper === void 0 ? void 0 : prefixMapper(index), itemCount: count(index) }, keyMapper(index))) : (jsxRuntime.jsx(reactFilterComponents.CheckBoxFilterItem, { dataTestId: "dynamic-filter-check-box-" + keyMapper(index), name: keyMapper(index), label: labelMapper(index), checked: checked(index), showTooltip: showTooltip, onChange: () => onChange === null || onChange === void 0 ? void 0 : onChange(index), prefix: prefixMapper === null || prefixMapper === void 0 ? void 0 : prefixMapper(index), itemCount: count(index) }, keyMapper(index))) }));
|
|
572
579
|
} }) }));
|
|
573
580
|
};
|
package/index.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
3
|
import { truthy, capitalize as capitalize$1, nonNullable } from '@trackunit/shared-utils';
|
|
4
|
-
import { useMemo, Fragment as Fragment$1,
|
|
4
|
+
import { useMemo, Fragment as Fragment$1, useCallback, useEffect, useRef, useState } from 'react';
|
|
5
5
|
import { Filter as Filter$1, FilterBody, RadioFilterItem, CheckBoxFilterItem, FilterHeader as FilterHeader$1, FilterFooter } from '@trackunit/react-filter-components';
|
|
6
6
|
import { Button, Popover, PopoverTrigger, IconButton, Icon, PopoverContent, MenuList, Text, StarButton, DayRangePicker } from '@trackunit/react-components';
|
|
7
7
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
8
8
|
import { useAnalytics, useTextSearch } from '@trackunit/react-core-hooks';
|
|
9
9
|
import { createEvent } from '@trackunit/react-core-contexts-api';
|
|
10
|
-
import {
|
|
10
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
11
11
|
import { Search, NumberField, RadioGroup } from '@trackunit/react-form-components';
|
|
12
12
|
import { dequal } from 'dequal';
|
|
13
13
|
import { isEqual } from 'lodash';
|
|
@@ -539,19 +539,26 @@ const toggleFilterValue = (value) => {
|
|
|
539
539
|
* @template T - The type of data items in the list.
|
|
540
540
|
* @returns {JSX.Element} - Returns the virtualized list component.
|
|
541
541
|
*/
|
|
542
|
-
const VirtualizedList = ({ parentRef, count, children }) => {
|
|
543
|
-
const rowVirtualizer =
|
|
544
|
-
|
|
542
|
+
const VirtualizedList = ({ parentRef, count, rowHeight = 40, children, }) => {
|
|
543
|
+
const rowVirtualizer = useVirtualizer({
|
|
544
|
+
count,
|
|
545
|
+
getScrollElement: () => parentRef.current,
|
|
546
|
+
estimateSize: useCallback((i) => rowHeight, [rowHeight]),
|
|
545
547
|
overscan: 10,
|
|
546
|
-
parentRef,
|
|
547
548
|
});
|
|
548
|
-
|
|
549
|
+
useEffect(() => {
|
|
550
|
+
// this ensures the cache is cleared if the rowHeight changes
|
|
551
|
+
if (rowHeight) {
|
|
552
|
+
rowVirtualizer.measure();
|
|
553
|
+
}
|
|
554
|
+
}, [rowHeight, rowVirtualizer]);
|
|
555
|
+
return (jsx("div", { className: "relative", style: { height: rowVirtualizer.getTotalSize() }, children: rowVirtualizer.getVirtualItems().map((virtualRow, index) => (jsx("div", { style: {
|
|
549
556
|
position: "absolute",
|
|
550
557
|
top: 0,
|
|
551
558
|
left: 0,
|
|
552
559
|
width: "100%",
|
|
553
560
|
transform: `translateY(${virtualRow.start}px)`,
|
|
554
|
-
}, children: children(
|
|
561
|
+
}, children: children(index) }, index))) }));
|
|
555
562
|
};
|
|
556
563
|
|
|
557
564
|
/**
|
|
@@ -563,7 +570,7 @@ const DynamicFilterList = ({ rowCount, keyMapper, labelMapper, prefixMapper, onC
|
|
|
563
570
|
const [t] = useTranslation();
|
|
564
571
|
const parentRef = useRef(null);
|
|
565
572
|
const updatedRowCount = useMemo(() => (showRequestMoreUseSearch ? rowCount + 1 : rowCount), [rowCount, showRequestMoreUseSearch]);
|
|
566
|
-
return (jsx(FilterBody, { limitSize: true, ref: parentRef, children: jsx(VirtualizedList, { parentRef: parentRef, count: updatedRowCount, children: index => {
|
|
573
|
+
return (jsx(FilterBody, { limitSize: true, ref: parentRef, children: jsx(VirtualizedList, { rowHeight: 40, parentRef: parentRef, count: updatedRowCount, children: index => {
|
|
567
574
|
return (jsx("div", { children: showRequestMoreUseSearch && index === rowCount ? (jsxs("div", { className: "p-3 pt-2", children: [jsx("span", { className: "text-sm text-gray-600", children: t("filter.more.options.if.you.search.title", { count: rowCount }) }), jsx("br", {}), jsx("span", { className: "text-sm italic text-gray-400", children: t("filter.more.options.if.you.search.description") })] })) : type === "Radio" ? (jsx(RadioFilterItem, { dataTestId: "dynamic-filter-radio-" + keyMapper(index), label: labelMapper(index), value: keyMapper(index), selected: checked(index), prefix: prefixMapper === null || prefixMapper === void 0 ? void 0 : prefixMapper(index), itemCount: count(index) }, keyMapper(index))) : (jsx(CheckBoxFilterItem, { dataTestId: "dynamic-filter-check-box-" + keyMapper(index), name: keyMapper(index), label: labelMapper(index), checked: checked(index), showTooltip: showTooltip, onChange: () => onChange === null || onChange === void 0 ? void 0 : onChange(index), prefix: prefixMapper === null || prefixMapper === void 0 ? void 0 : prefixMapper(index), itemCount: count(index) }, keyMapper(index))) }));
|
|
568
575
|
} }) }));
|
|
569
576
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/filters-filter-bar",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.130",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -14,12 +14,12 @@
|
|
|
14
14
|
"react": "^18.2.0",
|
|
15
15
|
"@trackunit/react-form-components": "*",
|
|
16
16
|
"react-router-dom": "6.18.0",
|
|
17
|
-
"react-virtual": "^2.10.4",
|
|
18
17
|
"dequal": "^2.0.3",
|
|
19
18
|
"lodash": "4.17.21",
|
|
20
19
|
"jest-fetch-mock": "^3.0.3",
|
|
21
20
|
"@trackunit/react-core-contexts-api": "*",
|
|
22
|
-
"@trackunit/i18n-library-translation": "*"
|
|
21
|
+
"@trackunit/i18n-library-translation": "*",
|
|
22
|
+
"@tanstack/react-virtual": "3.0.0-beta.68"
|
|
23
23
|
},
|
|
24
24
|
"module": "./index.esm.js",
|
|
25
25
|
"main": "./index.cjs.js"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RefObject } from "react";
|
|
2
|
-
interface VirtualizedListProps<T> {
|
|
2
|
+
interface VirtualizedListProps<T extends HTMLElement> {
|
|
3
3
|
/**
|
|
4
4
|
* A reference to the parent container element that holds the virtualized list.
|
|
5
5
|
*/
|
|
@@ -8,6 +8,7 @@ interface VirtualizedListProps<T> {
|
|
|
8
8
|
* The total number of items in the virtualized list.
|
|
9
9
|
*/
|
|
10
10
|
count: number;
|
|
11
|
+
rowHeight?: number;
|
|
11
12
|
/**
|
|
12
13
|
* A function that takes an index and returns the JSX element to be rendered for that index.
|
|
13
14
|
*
|
|
@@ -22,5 +23,5 @@ interface VirtualizedListProps<T> {
|
|
|
22
23
|
* @template T - The type of data items in the list.
|
|
23
24
|
* @returns {JSX.Element} - Returns the virtualized list component.
|
|
24
25
|
*/
|
|
25
|
-
export declare const VirtualizedList: <T>({ parentRef, count, children }: VirtualizedListProps<T>) => JSX.Element;
|
|
26
|
+
export declare const VirtualizedList: <T extends HTMLElement>({ parentRef, count, rowHeight, children, }: VirtualizedListProps<T>) => JSX.Element;
|
|
26
27
|
export {};
|