@trackunit/react-core-hooks 0.2.80 → 0.2.83-alpha-bfdefa6ec9.0
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 +22 -0
- package/index.esm.js +23 -2
- package/package.json +5 -4
- package/src/index.d.ts +1 -0
- package/src/useTextSearch.d.ts +12 -0
package/index.cjs.js
CHANGED
|
@@ -6,6 +6,7 @@ var React = require('react');
|
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
|
|
8
8
|
var reactRouterDom = require('react-router-dom');
|
|
9
|
+
var sharedUtils = require('@trackunit/shared-utils');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
12
|
|
|
@@ -434,6 +435,26 @@ const TokenProvider = (props) => {
|
|
|
434
435
|
return jsxRuntime.jsx(TokenContext.Provider, Object.assign({}, props));
|
|
435
436
|
};
|
|
436
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Hook for filtering a list of items by text search, client side search in a list.
|
|
440
|
+
*
|
|
441
|
+
* @param items The list of items to filter.
|
|
442
|
+
* @param props The properties to search in each item.
|
|
443
|
+
* @returns A tuple with the filtered items, the search text and a setter for the search text.
|
|
444
|
+
* @example
|
|
445
|
+
* const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
|
|
446
|
+
*/
|
|
447
|
+
function useTextSearch(items, props) {
|
|
448
|
+
const [searchText, setSearchText] = React.useState("");
|
|
449
|
+
const result = React.useMemo(() => {
|
|
450
|
+
if (!searchText) {
|
|
451
|
+
return items;
|
|
452
|
+
}
|
|
453
|
+
return sharedUtils.filterByMultiple(items, props, searchText);
|
|
454
|
+
}, [items, props, searchText]);
|
|
455
|
+
return [result, searchText, setSearchText];
|
|
456
|
+
}
|
|
457
|
+
|
|
437
458
|
const CurrentUserContext = React__namespace.createContext(null);
|
|
438
459
|
/**
|
|
439
460
|
* This is a provider for the CurrentUserContext.
|
|
@@ -485,6 +506,7 @@ exports.useNavigationRuntime = useNavigationRuntime;
|
|
|
485
506
|
exports.useOemBrandingContext = useOemBrandingContext;
|
|
486
507
|
exports.useRestRuntime = useRestRuntime;
|
|
487
508
|
exports.useSiteRuntime = useSiteRuntime;
|
|
509
|
+
exports.useTextSearch = useTextSearch;
|
|
488
510
|
exports.useToast = useToast;
|
|
489
511
|
exports.useToken = useToken;
|
|
490
512
|
exports.useURLSynchronization = useURLSynchronization;
|
package/index.esm.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { createContext, useContext, useState, useEffect } from 'react';
|
|
2
|
+
import React__default, { createContext, useContext, useState, useEffect, useMemo } from 'react';
|
|
3
3
|
import { jsx } from 'react/jsx-runtime';
|
|
4
4
|
import { NavigationRuntime, AssetRuntime, CustomFieldRuntime, RestRuntime, SiteRuntime } from '@trackunit/iris-app-runtime-core';
|
|
5
5
|
import { useLocation } from 'react-router-dom';
|
|
6
|
+
import { filterByMultiple } from '@trackunit/shared-utils';
|
|
6
7
|
|
|
7
8
|
const AnalyticsContext = createContext(null);
|
|
8
9
|
const AnalyticsContextProvider = AnalyticsContext.Provider; // easy import
|
|
@@ -408,6 +409,26 @@ const TokenProvider = (props) => {
|
|
|
408
409
|
return jsx(TokenContext.Provider, Object.assign({}, props));
|
|
409
410
|
};
|
|
410
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Hook for filtering a list of items by text search, client side search in a list.
|
|
414
|
+
*
|
|
415
|
+
* @param items The list of items to filter.
|
|
416
|
+
* @param props The properties to search in each item.
|
|
417
|
+
* @returns A tuple with the filtered items, the search text and a setter for the search text.
|
|
418
|
+
* @example
|
|
419
|
+
* const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
|
|
420
|
+
*/
|
|
421
|
+
function useTextSearch(items, props) {
|
|
422
|
+
const [searchText, setSearchText] = useState("");
|
|
423
|
+
const result = useMemo(() => {
|
|
424
|
+
if (!searchText) {
|
|
425
|
+
return items;
|
|
426
|
+
}
|
|
427
|
+
return filterByMultiple(items, props, searchText);
|
|
428
|
+
}, [items, props, searchText]);
|
|
429
|
+
return [result, searchText, setSearchText];
|
|
430
|
+
}
|
|
431
|
+
|
|
411
432
|
const CurrentUserContext = React.createContext(null);
|
|
412
433
|
/**
|
|
413
434
|
* This is a provider for the CurrentUserContext.
|
|
@@ -437,4 +458,4 @@ const useCurrentUser = () => {
|
|
|
437
458
|
return context;
|
|
438
459
|
};
|
|
439
460
|
|
|
440
|
-
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, CurrentUserProvider, EnvironmentContextProvider, GlobalSelectionProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useCurrentUser, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useGlobalSelection, useNavigationRuntime, useOemBrandingContext, useRestRuntime, useSiteRuntime, useToast, useToken, useURLSynchronization, useUserSubscription };
|
|
461
|
+
export { AnalyticsContext, AnalyticsContextProvider, AssetSortingProvider, CurrentUserProvider, EnvironmentContextProvider, GlobalSelectionProvider, OemBrandingContextProvider, ToastProvider, TokenProvider, UserSubscriptionProvider, useAnalytics, useAssetRuntime, useAssetSorting, useCurrentUser, useCustomFieldRuntime, useCustomFieldRuntimeForEntity, useEnvironment, useGlobalSelection, useNavigationRuntime, useOemBrandingContext, useRestRuntime, useSiteRuntime, useTextSearch, useToast, useToken, useURLSynchronization, useUserSubscription };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-core-hooks",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.83-alpha-bfdefa6ec9.0",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -9,9 +9,10 @@
|
|
|
9
9
|
"module": "./index.esm.js",
|
|
10
10
|
"main": "./index.cjs.js",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@trackunit/iris-app-runtime-core": "0.3.
|
|
13
|
-
"@trackunit/iris-app-runtime-core-api": "0.3.
|
|
14
|
-
"@trackunit/react-core-contexts-api": "0.2.
|
|
12
|
+
"@trackunit/iris-app-runtime-core": "0.3.67-alpha-bfdefa6ec9.0",
|
|
13
|
+
"@trackunit/iris-app-runtime-core-api": "0.3.60-alpha-bfdefa6ec9.0",
|
|
14
|
+
"@trackunit/react-core-contexts-api": "0.2.53-alpha-bfdefa6ec9.0",
|
|
15
|
+
"@trackunit/shared-utils": "0.0.3-alpha-bfdefa6ec9.0",
|
|
15
16
|
"react": "18.2.0",
|
|
16
17
|
"react-router-dom": "6.11.2"
|
|
17
18
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -13,4 +13,5 @@ export * from "./runtimes/useSiteRuntime";
|
|
|
13
13
|
export * from "./subscription/UserSubscriptionProvider";
|
|
14
14
|
export * from "./toast/ToastProvider";
|
|
15
15
|
export * from "./token/TokenProvider";
|
|
16
|
+
export * from "./useTextSearch";
|
|
16
17
|
export * from "./user/CurrentUserProvider";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Maybe } from "@trackunit/shared-utils";
|
|
2
|
+
import { Dispatch } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Hook for filtering a list of items by text search, client side search in a list.
|
|
5
|
+
*
|
|
6
|
+
* @param items The list of items to filter.
|
|
7
|
+
* @param props The properties to search in each item.
|
|
8
|
+
* @returns A tuple with the filtered items, the search text and a setter for the search text.
|
|
9
|
+
* @example
|
|
10
|
+
* const [result, searchText, setSearchText] = useTextSearch(items, item => [item.name, item.description]);
|
|
11
|
+
*/
|
|
12
|
+
export declare function useTextSearch<T>(items: T[], props: (item: T) => Maybe<string>[]): [T[], string, Dispatch<string>];
|