@trackunit/filters-filter-bar 2.10.6 → 2.10.7

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 CHANGED
@@ -1192,7 +1192,7 @@ const HierarchicalCheckboxFilter = ({ filterDefinition, filterBarActions, option
1192
1192
  const currentSetSearchText = isServerSearch ? customSearch.onChange : setLocalSearchText;
1193
1193
  const searchHeaderProps = {
1194
1194
  searchEnabled: true,
1195
- searchProps: { value: currentSearchText, onChange: currentSetSearchText },
1195
+ searchProps: { value: currentSearchText, onChange: currentSetSearchText, onClear: customSearch?.onClear },
1196
1196
  };
1197
1197
  const optionsMap = react.useMemo(() => {
1198
1198
  const map = new Map();
@@ -2325,6 +2325,25 @@ const useFilterBarsAsLink = (filterBarLinkConfig) => {
2325
2325
  }, [getFilterBarLink]);
2326
2326
  };
2327
2327
 
2328
+ /** How long a filter waits after the last keystroke before it searches. */
2329
+ const FILTER_SEARCH_DEBOUNCE_MS = 500;
2330
+ /**
2331
+ * Owns the search box of a filter that searches on the server or in its own data: the text as typed,
2332
+ * and the debounced copy to search with.
2333
+ *
2334
+ * @example
2335
+ * const { debouncedSearch, customSearch } = useFilterSearch();
2336
+ * const { data, loading } = useQuery(MyOptionsDocument, { variables: { search: debouncedSearch } });
2337
+ * return <DefaultCheckboxFilter {...props} customSearch={customSearch} loading={loading} options={toOptions(data)} />;
2338
+ * @returns {object} `customSearch` to hand to the filter component, and `debouncedSearch` to query or match with
2339
+ */
2340
+ const useFilterSearch = () => {
2341
+ const [searchText, setSearchText] = react.useState("");
2342
+ const debouncedSearch = reactComponents.useDebounce(searchText, { delay: FILTER_SEARCH_DEBOUNCE_MS });
2343
+ const customSearch = react.useMemo(() => ({ value: searchText, onChange: setSearchText, onClear: () => setSearchText("") }), [searchText]);
2344
+ return react.useMemo(() => ({ debouncedSearch, customSearch }), [debouncedSearch, customSearch]);
2345
+ };
2346
+
2328
2347
  /**
2329
2348
  * Handles the application of a URL search parameter as a filter in the system.
2330
2349
  * The parameter is validated using the provided Zod schema.
@@ -2407,6 +2426,7 @@ exports.DefaultDateRangeFilter = DefaultDateRangeFilter;
2407
2426
  exports.DefaultMinMaxFilter = DefaultMinMaxFilter;
2408
2427
  exports.DefaultRadioFilter = DefaultRadioFilter;
2409
2428
  exports.DynamicFilterList = DynamicFilterList;
2429
+ exports.FILTER_SEARCH_DEBOUNCE_MS = FILTER_SEARCH_DEBOUNCE_MS;
2410
2430
  exports.FilterBar = FilterBar;
2411
2431
  exports.FilterButtonTooltipLabel = FilterButtonTooltipLabel;
2412
2432
  exports.FilterComponent = FilterComponent;
@@ -2444,6 +2464,7 @@ exports.toggleFilterValue = toggleFilterValue;
2444
2464
  exports.useFilterBar = useFilterBar;
2445
2465
  exports.useFilterBarAsync = useFilterBarAsync;
2446
2466
  exports.useFilterBarsAsLink = useFilterBarsAsLink;
2467
+ exports.useFilterSearch = useFilterSearch;
2447
2468
  exports.useFiltersMenu = useFiltersMenu;
2448
2469
  exports.useSearchParamAsFilter = useSearchParamAsFilter;
2449
2470
  exports.validateFilter = validateFilter;
package/index.esm.js CHANGED
@@ -3,7 +3,7 @@ import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-l
3
3
  import { useMemo, useState, useEffect, useCallback, useId, Fragment as Fragment$1, useRef } from 'react';
4
4
  import { twMerge } from 'tailwind-merge';
5
5
  import { Filter, FilterBody, RadioFilterItem, CheckBoxFilterItem, FilterHeader as FilterHeader$1, FilterFooter } from '@trackunit/react-filter-components';
6
- import { Button, Icon, useList, List, Text, useTextSearch, useMenuSearchField, MenuDivider, MenuContent, ZStack, IconButton, Badge, useViewportBreakpoints, MenuTree, Popover, PopoverTrigger, Tooltip, PopoverContent, useCustomEncoding, useSearchParamSync, useStorageKey, useWatch } from '@trackunit/react-components';
6
+ import { Button, Icon, useList, List, Text, useTextSearch, useMenuSearchField, MenuDivider, MenuContent, ZStack, IconButton, Badge, useViewportBreakpoints, MenuTree, Popover, PopoverTrigger, Tooltip, PopoverContent, useCustomEncoding, useSearchParamSync, useStorageKey, useWatch, useDebounce } from '@trackunit/react-components';
7
7
  import { useAnalytics, useCurrentUser } from '@trackunit/react-core-hooks';
8
8
  import { capitalize } from 'string-ts';
9
9
  import { createEvent } from '@trackunit/iris-app-runtime-core-api';
@@ -1190,7 +1190,7 @@ const HierarchicalCheckboxFilter = ({ filterDefinition, filterBarActions, option
1190
1190
  const currentSetSearchText = isServerSearch ? customSearch.onChange : setLocalSearchText;
1191
1191
  const searchHeaderProps = {
1192
1192
  searchEnabled: true,
1193
- searchProps: { value: currentSearchText, onChange: currentSetSearchText },
1193
+ searchProps: { value: currentSearchText, onChange: currentSetSearchText, onClear: customSearch?.onClear },
1194
1194
  };
1195
1195
  const optionsMap = useMemo(() => {
1196
1196
  const map = new Map();
@@ -2323,6 +2323,25 @@ const useFilterBarsAsLink = (filterBarLinkConfig) => {
2323
2323
  }, [getFilterBarLink]);
2324
2324
  };
2325
2325
 
2326
+ /** How long a filter waits after the last keystroke before it searches. */
2327
+ const FILTER_SEARCH_DEBOUNCE_MS = 500;
2328
+ /**
2329
+ * Owns the search box of a filter that searches on the server or in its own data: the text as typed,
2330
+ * and the debounced copy to search with.
2331
+ *
2332
+ * @example
2333
+ * const { debouncedSearch, customSearch } = useFilterSearch();
2334
+ * const { data, loading } = useQuery(MyOptionsDocument, { variables: { search: debouncedSearch } });
2335
+ * return <DefaultCheckboxFilter {...props} customSearch={customSearch} loading={loading} options={toOptions(data)} />;
2336
+ * @returns {object} `customSearch` to hand to the filter component, and `debouncedSearch` to query or match with
2337
+ */
2338
+ const useFilterSearch = () => {
2339
+ const [searchText, setSearchText] = useState("");
2340
+ const debouncedSearch = useDebounce(searchText, { delay: FILTER_SEARCH_DEBOUNCE_MS });
2341
+ const customSearch = useMemo(() => ({ value: searchText, onChange: setSearchText, onClear: () => setSearchText("") }), [searchText]);
2342
+ return useMemo(() => ({ debouncedSearch, customSearch }), [debouncedSearch, customSearch]);
2343
+ };
2344
+
2326
2345
  /**
2327
2346
  * Handles the application of a URL search parameter as a filter in the system.
2328
2347
  * The parameter is validated using the provided Zod schema.
@@ -2399,4 +2418,4 @@ const mergeFilters = (filterBarDefinition, extraFilters) => {
2399
2418
  */
2400
2419
  setupLibraryTranslations();
2401
2420
 
2402
- export { AppliedFiltersRenderer, DefaultCheckboxFilter, DefaultDateRangeFilter, DefaultMinMaxFilter, DefaultRadioFilter, DynamicFilterList, FilterBar, FilterButtonTooltipLabel, FilterComponent, FilterEvents, FilterHeader, FilterResults, FilterTableComponent, FiltersMenu, FiltersMenuContent, FiltersRenderer, GroupedFiltersList, HierarchicalCheckboxFilter, MultipleFilterTooltipLabel, ResetFiltersButton, TooltipLabel, areaFilterGeoJsonGeometrySchema, booleanSchema, dateRangeSchema, isAreaFilterValue, isArrayFilterValue, isBooleanValue, isDateRangeValue, isMinMaxFilterValue, isStringArrayFilterValue, isValueName, isValueNameArray, mergeFilters, minMaxFilterSchema, mockFilterBar, mockFilterBarActions, numberSchema, stringArraySchema, stringSchema, toggleFilterValue, useFilterBar, useFilterBarAsync, useFilterBarsAsLink, useFiltersMenu, useSearchParamAsFilter, validateFilter, valueNameArraySchema, valueNameSchema };
2421
+ export { AppliedFiltersRenderer, DefaultCheckboxFilter, DefaultDateRangeFilter, DefaultMinMaxFilter, DefaultRadioFilter, DynamicFilterList, FILTER_SEARCH_DEBOUNCE_MS, FilterBar, FilterButtonTooltipLabel, FilterComponent, FilterEvents, FilterHeader, FilterResults, FilterTableComponent, FiltersMenu, FiltersMenuContent, FiltersRenderer, GroupedFiltersList, HierarchicalCheckboxFilter, MultipleFilterTooltipLabel, ResetFiltersButton, TooltipLabel, areaFilterGeoJsonGeometrySchema, booleanSchema, dateRangeSchema, isAreaFilterValue, isArrayFilterValue, isBooleanValue, isDateRangeValue, isMinMaxFilterValue, isStringArrayFilterValue, isValueName, isValueNameArray, mergeFilters, minMaxFilterSchema, mockFilterBar, mockFilterBarActions, numberSchema, stringArraySchema, stringSchema, toggleFilterValue, useFilterBar, useFilterBarAsync, useFilterBarsAsLink, useFilterSearch, useFiltersMenu, useSearchParamAsFilter, validateFilter, valueNameArraySchema, valueNameSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/filters-filter-bar",
3
- "version": "2.10.6",
3
+ "version": "2.10.7",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -11,17 +11,17 @@
11
11
  "tailwind-merge": "^2.0.0",
12
12
  "string-ts": "^2.0.0",
13
13
  "zod": "^3.25.76",
14
- "@trackunit/iris-app-api": "2.9.3",
15
- "@trackunit/react-core-hooks": "1.25.3",
16
- "@trackunit/react-filter-components": "2.10.6",
17
- "@trackunit/react-date-and-time-components": "2.10.6",
18
- "@trackunit/shared-utils": "1.19.3",
19
- "@trackunit/react-form-components": "2.10.6",
20
- "@trackunit/iris-app-runtime-core-api": "1.21.3",
21
- "@trackunit/geo-json-utils": "1.18.3",
22
- "@trackunit/i18n-library-translation": "2.8.3",
23
- "@trackunit/css-class-variance-utilities": "2.3.3",
24
- "@trackunit/react-components": "3.8.0"
14
+ "@trackunit/iris-app-api": "2.9.4",
15
+ "@trackunit/react-core-hooks": "1.25.4",
16
+ "@trackunit/react-filter-components": "2.10.7",
17
+ "@trackunit/react-date-and-time-components": "2.10.7",
18
+ "@trackunit/shared-utils": "1.19.4",
19
+ "@trackunit/react-form-components": "2.10.7",
20
+ "@trackunit/iris-app-runtime-core-api": "1.21.4",
21
+ "@trackunit/geo-json-utils": "1.18.4",
22
+ "@trackunit/i18n-library-translation": "2.8.4",
23
+ "@trackunit/css-class-variance-utilities": "2.3.4",
24
+ "@trackunit/react-components": "3.8.1"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@apollo/client": "^3.13.8",
package/src/index.d.ts CHANGED
@@ -24,6 +24,7 @@ export * from "./lib/hooks/types";
24
24
  export * from "./lib/hooks/useFilterBar";
25
25
  export * from "./lib/hooks/useFilterBarAsync";
26
26
  export * from "./lib/hooks/useFilterBarsAsLink";
27
+ export * from "./lib/hooks/useFilterSearch";
27
28
  export * from "./lib/hooks/useFiltersMenu";
28
29
  export * from "./lib/hooks/useSearchParamAsFilter";
29
30
  export * from "./lib/types/FilterTypes";
@@ -48,6 +48,10 @@ export interface HierarchicalFilterProps extends Omit<DefaultFilterProps<Array<V
48
48
  * @param value Updated search string
49
49
  */
50
50
  onChange: (value: string) => void;
51
+ /**
52
+ * Callback when the search is cleared. Without it the clear button leaves the search as is.
53
+ */
54
+ onClear?: () => void;
51
55
  };
52
56
  showCount?: boolean;
53
57
  }
@@ -0,0 +1,22 @@
1
+ /** How long a filter waits after the last keystroke before it searches. */
2
+ export declare const FILTER_SEARCH_DEBOUNCE_MS = 500;
3
+ /** The `customSearch` prop of `DefaultCheckboxFilter`, with the clear action always wired. */
4
+ export type FilterCustomSearch = {
5
+ value: string;
6
+ onChange: (value: string) => void;
7
+ onClear: () => void;
8
+ };
9
+ /**
10
+ * Owns the search box of a filter that searches on the server or in its own data: the text as typed,
11
+ * and the debounced copy to search with.
12
+ *
13
+ * @example
14
+ * const { debouncedSearch, customSearch } = useFilterSearch();
15
+ * const { data, loading } = useQuery(MyOptionsDocument, { variables: { search: debouncedSearch } });
16
+ * return <DefaultCheckboxFilter {...props} customSearch={customSearch} loading={loading} options={toOptions(data)} />;
17
+ * @returns {object} `customSearch` to hand to the filter component, and `debouncedSearch` to query or match with
18
+ */
19
+ export declare const useFilterSearch: () => {
20
+ debouncedSearch: string;
21
+ customSearch: FilterCustomSearch;
22
+ };
@@ -1 +0,0 @@
1
- {"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/filters/filter-bar/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}