@trackunit/filters-filter-bar 1.18.4 → 1.18.5

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
@@ -2516,6 +2516,41 @@ const useFilterBarAsync = ({ name, onValuesChange, filterBarDefinition, loadData
2516
2516
  }, [filterBarConfigMemoed, internalFilterBarDefinitions, dataLoaded, name, stableOnValuesChange]);
2517
2517
  };
2518
2518
 
2519
+ /**
2520
+ * Converts a filter bar configuration to a link.
2521
+ *
2522
+ * @example
2523
+ * ```ts
2524
+ * const filterBarLinkConfig: FilterBarToLinkConfig = {
2525
+ * searchPropertyName: "assetFilters",
2526
+ * filterBar: "ASSETS",
2527
+ * };
2528
+ *
2529
+ * const { getFilterBarLink } = useFilterBarsAsLink(filterBarLinkConfig);
2530
+ *
2531
+ * const link = getFilterBarLink({ ASSETS: { search: "excavator" } });
2532
+ * ```
2533
+ * @param filterBarLinkConfig - The filter bar configuration to convert to a link.
2534
+ * @returns { UseFilterBarsAsLinkResult } An object with a `getFilterBarLink` function that takes a merged filter bar definitions and returns a link.
2535
+ */
2536
+ const useFilterBarsAsLink = (filterBarLinkConfig) => {
2537
+ const filterBarLinkConfigArray = react.useMemo(() => {
2538
+ return Array.isArray(filterBarLinkConfig) ? filterBarLinkConfig : filterBarLinkConfig ? [filterBarLinkConfig] : [];
2539
+ }, [filterBarLinkConfig]);
2540
+ const { encode } = reactComponents.useCustomEncoding();
2541
+ const getFilterBarLink = react.useCallback((mergedFilterBarDefinitions) => {
2542
+ return filterBarLinkConfigArray
2543
+ .map(config => {
2544
+ const value = mergedFilterBarDefinitions[config.filterBar];
2545
+ return `${config.searchPropertyName || "filter"}=${value ? encode(value) : ""}`;
2546
+ })
2547
+ .join("&");
2548
+ }, [filterBarLinkConfigArray, encode]);
2549
+ return react.useMemo(() => {
2550
+ return { getFilterBarLink };
2551
+ }, [getFilterBarLink]);
2552
+ };
2553
+
2519
2554
  /**
2520
2555
  * Handles the application of a URL search parameter as a filter in the system.
2521
2556
  * The parameter is validated using the provided Zod schema.
@@ -2633,6 +2668,7 @@ exports.stringSchema = stringSchema;
2633
2668
  exports.toggleFilterValue = toggleFilterValue;
2634
2669
  exports.useFilterBar = useFilterBar;
2635
2670
  exports.useFilterBarAsync = useFilterBarAsync;
2671
+ exports.useFilterBarsAsLink = useFilterBarsAsLink;
2636
2672
  exports.useFiltersMenu = useFiltersMenu;
2637
2673
  exports.useSearchParamAsFilter = useSearchParamAsFilter;
2638
2674
  exports.validateFilter = validateFilter;
package/index.esm.js CHANGED
@@ -2514,6 +2514,41 @@ const useFilterBarAsync = ({ name, onValuesChange, filterBarDefinition, loadData
2514
2514
  }, [filterBarConfigMemoed, internalFilterBarDefinitions, dataLoaded, name, stableOnValuesChange]);
2515
2515
  };
2516
2516
 
2517
+ /**
2518
+ * Converts a filter bar configuration to a link.
2519
+ *
2520
+ * @example
2521
+ * ```ts
2522
+ * const filterBarLinkConfig: FilterBarToLinkConfig = {
2523
+ * searchPropertyName: "assetFilters",
2524
+ * filterBar: "ASSETS",
2525
+ * };
2526
+ *
2527
+ * const { getFilterBarLink } = useFilterBarsAsLink(filterBarLinkConfig);
2528
+ *
2529
+ * const link = getFilterBarLink({ ASSETS: { search: "excavator" } });
2530
+ * ```
2531
+ * @param filterBarLinkConfig - The filter bar configuration to convert to a link.
2532
+ * @returns { UseFilterBarsAsLinkResult } An object with a `getFilterBarLink` function that takes a merged filter bar definitions and returns a link.
2533
+ */
2534
+ const useFilterBarsAsLink = (filterBarLinkConfig) => {
2535
+ const filterBarLinkConfigArray = useMemo(() => {
2536
+ return Array.isArray(filterBarLinkConfig) ? filterBarLinkConfig : filterBarLinkConfig ? [filterBarLinkConfig] : [];
2537
+ }, [filterBarLinkConfig]);
2538
+ const { encode } = useCustomEncoding();
2539
+ const getFilterBarLink = useCallback((mergedFilterBarDefinitions) => {
2540
+ return filterBarLinkConfigArray
2541
+ .map(config => {
2542
+ const value = mergedFilterBarDefinitions[config.filterBar];
2543
+ return `${config.searchPropertyName || "filter"}=${value ? encode(value) : ""}`;
2544
+ })
2545
+ .join("&");
2546
+ }, [filterBarLinkConfigArray, encode]);
2547
+ return useMemo(() => {
2548
+ return { getFilterBarLink };
2549
+ }, [getFilterBarLink]);
2550
+ };
2551
+
2517
2552
  /**
2518
2553
  * Handles the application of a URL search parameter as a filter in the system.
2519
2554
  * The parameter is validated using the provided Zod schema.
@@ -2590,4 +2625,4 @@ const mergeFilters = (filterBarDefinition, extraFilters) => {
2590
2625
  */
2591
2626
  setupLibraryTranslations();
2592
2627
 
2593
- 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, numberSchema, stringArraySchema, stringSchema, toggleFilterValue, useFilterBar, useFilterBarAsync, useFiltersMenu, useSearchParamAsFilter, validateFilter, valueNameArraySchema, valueNameSchema };
2628
+ 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, numberSchema, stringArraySchema, stringSchema, toggleFilterValue, useFilterBar, useFilterBarAsync, useFilterBarsAsLink, useFiltersMenu, useSearchParamAsFilter, validateFilter, valueNameArraySchema, valueNameSchema };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/filters-filter-bar",
3
- "version": "1.18.4",
3
+ "version": "1.18.5",
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.23.8",
14
- "@trackunit/iris-app-api": "1.15.8",
14
+ "@trackunit/iris-app-api": "1.15.9",
15
15
  "@trackunit/react-core-hooks": "1.14.2",
16
- "@trackunit/react-filter-components": "1.17.3",
17
- "@trackunit/react-date-and-time-components": "1.20.3",
16
+ "@trackunit/react-filter-components": "1.17.4",
17
+ "@trackunit/react-date-and-time-components": "1.20.4",
18
18
  "@trackunit/shared-utils": "1.13.77",
19
- "@trackunit/react-form-components": "1.18.2",
19
+ "@trackunit/react-form-components": "1.18.3",
20
20
  "@trackunit/iris-app-runtime-core-api": "1.13.2",
21
21
  "@trackunit/geo-json-utils": "1.11.78",
22
- "@trackunit/i18n-library-translation": "1.15.2",
22
+ "@trackunit/i18n-library-translation": "1.15.3",
23
23
  "@trackunit/css-class-variance-utilities": "1.11.77",
24
- "@trackunit/react-components": "1.20.2"
24
+ "@trackunit/react-components": "1.20.3"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "react": "^19.0.0",
package/src/index.d.ts CHANGED
@@ -23,6 +23,7 @@ export * from "./lib/hooks/mockFilterBar";
23
23
  export * from "./lib/hooks/types";
24
24
  export * from "./lib/hooks/useFilterBar";
25
25
  export * from "./lib/hooks/useFilterBarAsync";
26
+ export * from "./lib/hooks/useFilterBarsAsLink";
26
27
  export * from "./lib/hooks/useFiltersMenu";
27
28
  export * from "./lib/hooks/useSearchParamAsFilter";
28
29
  export * from "./lib/types/FilterTypes";
@@ -0,0 +1,37 @@
1
+ import { AssetFilterKeysWithCustomFields, CustomerFilterKeysWithCustomFields, FilterBarToLinkConfig, SiteFilterKeysWithCustomFields } from "@trackunit/iris-app-api";
2
+ export type FiltersConfigValues = {
3
+ ASSETS?: Partial<Record<AssetFilterKeysWithCustomFields[number], unknown>>;
4
+ SITES?: Partial<Record<SiteFilterKeysWithCustomFields[number], unknown>>;
5
+ CUSTOMERS?: Partial<Record<CustomerFilterKeysWithCustomFields[number], unknown>>;
6
+ TIME_RANGE?: Record<string, unknown> | null;
7
+ };
8
+ /**
9
+ * The result of the useFilterBarsAsLink hook.
10
+ */
11
+ export interface UseFilterBarsAsLinkResult {
12
+ /**
13
+ * Gets the filter bar link.
14
+ *
15
+ * @param mergedFilterBarDefinitions - The merged filter bar definitions.
16
+ * @returns The filter bar link.
17
+ */
18
+ getFilterBarLink: (mergedFilterBarDefinitions: FiltersConfigValues) => string;
19
+ }
20
+ /**
21
+ * Converts a filter bar configuration to a link.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * const filterBarLinkConfig: FilterBarToLinkConfig = {
26
+ * searchPropertyName: "assetFilters",
27
+ * filterBar: "ASSETS",
28
+ * };
29
+ *
30
+ * const { getFilterBarLink } = useFilterBarsAsLink(filterBarLinkConfig);
31
+ *
32
+ * const link = getFilterBarLink({ ASSETS: { search: "excavator" } });
33
+ * ```
34
+ * @param filterBarLinkConfig - The filter bar configuration to convert to a link.
35
+ * @returns { UseFilterBarsAsLinkResult } An object with a `getFilterBarLink` function that takes a merged filter bar definitions and returns a link.
36
+ */
37
+ export declare const useFilterBarsAsLink: (filterBarLinkConfig: FilterBarToLinkConfig | Array<FilterBarToLinkConfig> | null) => UseFilterBarsAsLinkResult;