@snack-uikit/fields 0.35.0 → 0.35.1
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/CHANGELOG.md +11 -0
- package/dist/cjs/components/FieldSelect/hooks.d.ts +1 -1
- package/dist/cjs/components/FieldSelect/hooks.js +6 -1
- package/dist/cjs/components/FieldSelect/utils/filterItemsByFlattenIds.d.ts +2 -0
- package/dist/cjs/components/FieldSelect/utils/filterItemsByFlattenIds.js +25 -0
- package/dist/esm/components/FieldSelect/hooks.d.ts +1 -1
- package/dist/esm/components/FieldSelect/hooks.js +6 -1
- package/dist/esm/components/FieldSelect/utils/filterItemsByFlattenIds.d.ts +2 -0
- package/dist/esm/components/FieldSelect/utils/filterItemsByFlattenIds.js +17 -0
- package/package.json +2 -2
- package/src/components/FieldSelect/hooks.ts +10 -2
- package/src/components/FieldSelect/utils/filterItemsByFlattenIds.ts +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.35.1 (2024-11-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **PDS-959:** do not change item structure in search mode ([1abca3d](https://github.com/cloud-ru-tech/snack-uikit/commit/1abca3d7ca7cef91665195ee51a06cc9af14461e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 0.35.0 (2024-11-19)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -37,5 +37,5 @@ export declare function useHandleDeleteItem(setValue: Handler): (item?: ItemWith
|
|
|
37
37
|
/**
|
|
38
38
|
* Четкий и нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
39
39
|
*/
|
|
40
|
-
export declare function useSearch(items: ItemProps[], enableFuzzySearch?: boolean): (search: string) => import("@snack-uikit/list/dist/esm/components/Items").Item[]
|
|
40
|
+
export declare function useSearch(items: ItemProps[], enableFuzzySearch?: boolean): (search: string) => import("@snack-uikit/list/dist/esm/components/Items").Item[];
|
|
41
41
|
export {};
|
|
@@ -20,6 +20,7 @@ const list_1 = require("@snack-uikit/list");
|
|
|
20
20
|
const hooks_1 = require("../../hooks");
|
|
21
21
|
const legacy_1 = require("./legacy");
|
|
22
22
|
const utils_1 = require("./utils");
|
|
23
|
+
const filterItemsByFlattenIds_1 = require("./utils/filterItemsByFlattenIds");
|
|
23
24
|
function useHandleOnKeyDown(_ref) {
|
|
24
25
|
let {
|
|
25
26
|
setOpen,
|
|
@@ -158,7 +159,7 @@ function useSearch(items) {
|
|
|
158
159
|
});
|
|
159
160
|
return Object.values(flattenItems);
|
|
160
161
|
}, [items]);
|
|
161
|
-
const
|
|
162
|
+
const filterFlattenFunction = (0, react_1.useCallback)(search => {
|
|
162
163
|
if (!enableFuzzySearch) {
|
|
163
164
|
return flattenItems.filter(item => [...COMMON_FIELDS_TO_SEARCH, 'label'].some(key => {
|
|
164
165
|
const value = (0, utils_1.getValueByPath)(item, key);
|
|
@@ -168,5 +169,9 @@ function useSearch(items) {
|
|
|
168
169
|
const searcher = new fuzzy_search_1.default(flattenItems, COMMON_FIELDS_TO_SEARCH, {});
|
|
169
170
|
return searcher.search(search);
|
|
170
171
|
}, [enableFuzzySearch, flattenItems]);
|
|
172
|
+
const filterFunction = (0, react_1.useCallback)(search => {
|
|
173
|
+
const filteredIds = filterFlattenFunction(search).map(item => item.id);
|
|
174
|
+
return (0, filterItemsByFlattenIds_1.filterItemsByFlattenIds)(items, filteredIds);
|
|
175
|
+
}, [filterFlattenFunction, items]);
|
|
171
176
|
return (0, react_1.useCallback)(search => search.length >= DEFAULT_MIN_SEARCH_INPUT_LENGTH ? filterFunction(search) : items, [filterFunction, items]);
|
|
172
177
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.filterItemsByFlattenIds = filterItemsByFlattenIds;
|
|
7
|
+
const isItemWithId = item => item.id !== undefined;
|
|
8
|
+
const isGroupItem = item => item.type === 'group';
|
|
9
|
+
function filterItemsByFlattenIds(items, ids) {
|
|
10
|
+
const filteredItems = [];
|
|
11
|
+
items.forEach(item => {
|
|
12
|
+
if (isItemWithId(item) && item.id && ids.includes(item.id)) {
|
|
13
|
+
filteredItems.push(item);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (isGroupItem(item)) {
|
|
17
|
+
const filteredSubItems = filterItemsByFlattenIds(item.items, ids);
|
|
18
|
+
filteredItems.push(Object.assign(Object.assign({}, item), {
|
|
19
|
+
items: filteredSubItems
|
|
20
|
+
}));
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return filteredItems;
|
|
25
|
+
}
|
|
@@ -37,5 +37,5 @@ export declare function useHandleDeleteItem(setValue: Handler): (item?: ItemWith
|
|
|
37
37
|
/**
|
|
38
38
|
* Четкий и нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
|
|
39
39
|
*/
|
|
40
|
-
export declare function useSearch(items: ItemProps[], enableFuzzySearch?: boolean): (search: string) => import("@snack-uikit/list/dist/esm/components/Items").Item[]
|
|
40
|
+
export declare function useSearch(items: ItemProps[], enableFuzzySearch?: boolean): (search: string) => import("@snack-uikit/list/dist/esm/components/Items").Item[];
|
|
41
41
|
export {};
|
|
@@ -5,6 +5,7 @@ import { isAccordionItemProps, isNextListItemProps, kindFlattenItems, } from '@s
|
|
|
5
5
|
import { useCopyButton, useValueControl } from '../../hooks';
|
|
6
6
|
import { extractChildIds } from './legacy';
|
|
7
7
|
import { getValueByPath, isBaseOptionProps } from './utils';
|
|
8
|
+
import { filterItemsByFlattenIds } from './utils/filterItemsByFlattenIds';
|
|
8
9
|
export function useHandleOnKeyDown({ setOpen, inputKeyDownNavigationHandler, onInputKeyDownProp, }) {
|
|
9
10
|
return useCallback((onKeyDown) => (e) => {
|
|
10
11
|
if (e.code === 'Space') {
|
|
@@ -100,7 +101,7 @@ export function useSearch(items, enableFuzzySearch = true) {
|
|
|
100
101
|
const { flattenItems } = kindFlattenItems({ items });
|
|
101
102
|
return Object.values(flattenItems);
|
|
102
103
|
}, [items]);
|
|
103
|
-
const
|
|
104
|
+
const filterFlattenFunction = useCallback((search) => {
|
|
104
105
|
if (!enableFuzzySearch) {
|
|
105
106
|
return flattenItems.filter(item => [...COMMON_FIELDS_TO_SEARCH, 'label'].some(key => {
|
|
106
107
|
const value = getValueByPath(item, key);
|
|
@@ -110,5 +111,9 @@ export function useSearch(items, enableFuzzySearch = true) {
|
|
|
110
111
|
const searcher = new FuzzySearch(flattenItems, COMMON_FIELDS_TO_SEARCH, {});
|
|
111
112
|
return searcher.search(search);
|
|
112
113
|
}, [enableFuzzySearch, flattenItems]);
|
|
114
|
+
const filterFunction = useCallback((search) => {
|
|
115
|
+
const filteredIds = filterFlattenFunction(search).map(item => item.id);
|
|
116
|
+
return filterItemsByFlattenIds(items, filteredIds);
|
|
117
|
+
}, [filterFlattenFunction, items]);
|
|
113
118
|
return useCallback((search) => (search.length >= DEFAULT_MIN_SEARCH_INPUT_LENGTH ? filterFunction(search) : items), [filterFunction, items]);
|
|
114
119
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const isItemWithId = (item) => item.id !== undefined;
|
|
2
|
+
const isGroupItem = (item) => item.type === 'group';
|
|
3
|
+
export function filterItemsByFlattenIds(items, ids) {
|
|
4
|
+
const filteredItems = [];
|
|
5
|
+
items.forEach(item => {
|
|
6
|
+
if (isItemWithId(item) && item.id && ids.includes(item.id)) {
|
|
7
|
+
filteredItems.push(item);
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (isGroupItem(item)) {
|
|
11
|
+
const filteredSubItems = filterItemsByFlattenIds(item.items, ids);
|
|
12
|
+
filteredItems.push(Object.assign(Object.assign({}, item), { items: filteredSubItems }));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return filteredItems;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.35.
|
|
7
|
+
"version": "0.35.1",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@snack-uikit/locale": "*"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "8a406cbe32e37af611f8abee40c622e314a46090"
|
|
69
69
|
}
|
|
@@ -15,6 +15,7 @@ import { useCopyButton, useValueControl } from '../../hooks';
|
|
|
15
15
|
import { extractChildIds } from './legacy';
|
|
16
16
|
import { ItemWithId, SearchState, SelectedOptionFormatter } from './types';
|
|
17
17
|
import { getValueByPath, isBaseOptionProps } from './utils';
|
|
18
|
+
import { filterItemsByFlattenIds } from './utils/filterItemsByFlattenIds';
|
|
18
19
|
|
|
19
20
|
type UseHandleOnKeyDownProps = {
|
|
20
21
|
inputKeyDownNavigationHandler: KeyboardEventHandler<HTMLInputElement>;
|
|
@@ -187,13 +188,12 @@ export function useSearch(items: ItemProps[], enableFuzzySearch: boolean = true)
|
|
|
187
188
|
return Object.values(flattenItems);
|
|
188
189
|
}, [items]);
|
|
189
190
|
|
|
190
|
-
const
|
|
191
|
+
const filterFlattenFunction = useCallback(
|
|
191
192
|
(search: string) => {
|
|
192
193
|
if (!enableFuzzySearch) {
|
|
193
194
|
return flattenItems.filter(item =>
|
|
194
195
|
[...COMMON_FIELDS_TO_SEARCH, 'label'].some(key => {
|
|
195
196
|
const value = getValueByPath(item, key);
|
|
196
|
-
|
|
197
197
|
return value.toLowerCase().includes(search.toLowerCase());
|
|
198
198
|
}),
|
|
199
199
|
);
|
|
@@ -205,6 +205,14 @@ export function useSearch(items: ItemProps[], enableFuzzySearch: boolean = true)
|
|
|
205
205
|
[enableFuzzySearch, flattenItems],
|
|
206
206
|
);
|
|
207
207
|
|
|
208
|
+
const filterFunction = useCallback(
|
|
209
|
+
(search: string) => {
|
|
210
|
+
const filteredIds = filterFlattenFunction(search).map(item => item.id);
|
|
211
|
+
return filterItemsByFlattenIds(items, filteredIds);
|
|
212
|
+
},
|
|
213
|
+
[filterFlattenFunction, items],
|
|
214
|
+
);
|
|
215
|
+
|
|
208
216
|
return useCallback(
|
|
209
217
|
(search: string) => (search.length >= DEFAULT_MIN_SEARCH_INPUT_LENGTH ? filterFunction(search) : items),
|
|
210
218
|
[filterFunction, items],
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GroupItemProps, ItemId, ItemProps } from '@snack-uikit/list';
|
|
2
|
+
|
|
3
|
+
import { ItemWithId } from '../types';
|
|
4
|
+
|
|
5
|
+
const isItemWithId = (item: ItemProps): item is ItemWithId => (item as ItemWithId).id !== undefined;
|
|
6
|
+
|
|
7
|
+
const isGroupItem = (item: ItemProps): item is GroupItemProps => (item as GroupItemProps).type === 'group';
|
|
8
|
+
|
|
9
|
+
export function filterItemsByFlattenIds(items: ItemProps[], ids: ItemId[]) {
|
|
10
|
+
const filteredItems: ItemProps[] = [];
|
|
11
|
+
items.forEach(item => {
|
|
12
|
+
if (isItemWithId(item) && item.id && ids.includes(item.id)) {
|
|
13
|
+
filteredItems.push(item);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (isGroupItem(item)) {
|
|
17
|
+
const filteredSubItems = filterItemsByFlattenIds(item.items, ids);
|
|
18
|
+
filteredItems.push({ ...item, items: filteredSubItems });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return filteredItems;
|
|
23
|
+
}
|