From 9ffba6e34d985d5bc39be81760118c498b7d7340 Mon Sep 17 00:00:00 2001 From: qiusen Date: Fri, 20 Oct 2023 14:50:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(select):=20#2627=20#2628=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=90=9C=E7=B4=A2=E9=98=B2=E6=8A=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hooks/use-search-mode/src/index.ts | 29 ++++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/packages/hooks/use-search-mode/src/index.ts b/packages/hooks/use-search-mode/src/index.ts index c7a53d46e..e4fdb32b8 100644 --- a/packages/hooks/use-search-mode/src/index.ts +++ b/packages/hooks/use-search-mode/src/index.ts @@ -5,6 +5,7 @@ import { invariant } from '@hi-ui/env' import { filterTree, getNodeAncestors, cloneTree } from '@hi-ui/tree-utils' import { useLatestRef } from '@hi-ui/use-latest' import { useUncontrolledState } from '@hi-ui/use-uncontrolled-state' +import { debounce } from '@hi-ui/func-utils' const initialStateInSearch = () => ({ matched: false, @@ -16,10 +17,10 @@ const initialStateInSearch = () => ({ * TODO: What is useSearchMode */ export const useSearchMode = ({ - searchable: searchableProp, - strategies, - keyword: keywordProp, -}: UseSearchModeProps) => { + searchable: searchableProp, + strategies, + keyword: keywordProp, + }: UseSearchModeProps) => { const [keyword, setKeyword] = useUncontrolledState('', keywordProp) // 搜索时的临时节点数据 @@ -58,7 +59,9 @@ export const useSearchMode = ({ }, [searchable, setKeyword, runSearch] ) - + const isAsyncMode = searchMode === 'dataSource' + // 只有异步搜索需要防抖,正常不需要 + const debounceOnSearch = isAsyncMode ? debounce(onSearch) : onSearch const keywordLatestRef = useLatestRef(keyword) // 外部数据或策略改变时,重新触发搜索 @@ -73,7 +76,7 @@ export const useSearchMode = ({ searchable, searchMode, keyword, - onSearch, + onSearch: debounceOnSearch, inSearch, isEmpty, state: stateInSearch, @@ -180,13 +183,13 @@ export const useHighlightSearch = ({ data, flattedData, searchMode }: any) => { } export const useFilterSearch = ({ - enabled, - searchMode = 'filter', - data, - flattedData, - exclude, - fieldNames, -}: any) => { + enabled, + searchMode = 'filter', + data, + flattedData, + exclude, + fieldNames, + }: any) => { const excludeLatestRef = useLatestRef(exclude) const getKeyFields = useMemo(() => genKeyFields(fieldNames), [fieldNames]) From 4f7c8c9063d9b72068a2db5fa614eed130aafd0f Mon Sep 17 00:00:00 2001 From: qiusen Date: Fri, 20 Oct 2023 14:55:48 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(select):=20#2627=20#2628=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0changeset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/light-moons-juggle.md | 5 +++++ .changeset/three-dryers-collect.md | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 .changeset/light-moons-juggle.md create mode 100644 .changeset/three-dryers-collect.md diff --git a/.changeset/light-moons-juggle.md b/.changeset/light-moons-juggle.md new file mode 100644 index 000000000..da24d05ce --- /dev/null +++ b/.changeset/light-moons-juggle.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/check-select": patch +--- + +CheckSelect dataSource 下搜索框增加防抖操作 diff --git a/.changeset/three-dryers-collect.md b/.changeset/three-dryers-collect.md new file mode 100644 index 000000000..1e236bb1d --- /dev/null +++ b/.changeset/three-dryers-collect.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/select": patch +--- + +Select dataSource 下搜索框增加防抖操作 From 3eb90ffd3e874d27c81354c085e9d410ee1e731d Mon Sep 17 00:00:00 2001 From: qiusen Date: Mon, 23 Oct 2023 19:44:48 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat(select):=20#2627=20#2628=20=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/hooks/use-search-mode/src/index.ts | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/hooks/use-search-mode/src/index.ts b/packages/hooks/use-search-mode/src/index.ts index e4fdb32b8..14009d5ed 100644 --- a/packages/hooks/use-search-mode/src/index.ts +++ b/packages/hooks/use-search-mode/src/index.ts @@ -17,10 +17,10 @@ const initialStateInSearch = () => ({ * TODO: What is useSearchMode */ export const useSearchMode = ({ - searchable: searchableProp, - strategies, - keyword: keywordProp, - }: UseSearchModeProps) => { + searchable: searchableProp, + strategies, + keyword: keywordProp, +}: UseSearchModeProps) => { const [keyword, setKeyword] = useUncontrolledState('', keywordProp) // 搜索时的临时节点数据 @@ -183,13 +183,13 @@ export const useHighlightSearch = ({ data, flattedData, searchMode }: any) => { } export const useFilterSearch = ({ - enabled, - searchMode = 'filter', - data, - flattedData, - exclude, - fieldNames, - }: any) => { + enabled, + searchMode = 'filter', + data, + flattedData, + exclude, + fieldNames, +}: any) => { const excludeLatestRef = useLatestRef(exclude) const getKeyFields = useMemo(() => genKeyFields(fieldNames), [fieldNames]) From 45cbe7bd9ddeaadfc8ff520a2448a0dade6be51c Mon Sep 17 00:00:00 2001 From: qiusen Date: Mon, 23 Oct 2023 20:27:51 +0800 Subject: [PATCH 4/4] =?UTF-8?q?feat(select):=20#2627=20#2628=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0changeset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/rude-garlics-tickle.md | 5 +++++ .changeset/unlucky-lizards-sleep.md | 5 +++++ packages/hooks/use-search-mode/package.json | 1 + 3 files changed, 11 insertions(+) create mode 100644 .changeset/rude-garlics-tickle.md create mode 100644 .changeset/unlucky-lizards-sleep.md diff --git a/.changeset/rude-garlics-tickle.md b/.changeset/rude-garlics-tickle.md new file mode 100644 index 000000000..ff52a4916 --- /dev/null +++ b/.changeset/rude-garlics-tickle.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/hiui": patch +--- + +CheckSelect Select dataSource 下搜索框增加防抖操作 diff --git a/.changeset/unlucky-lizards-sleep.md b/.changeset/unlucky-lizards-sleep.md new file mode 100644 index 000000000..64bf5447b --- /dev/null +++ b/.changeset/unlucky-lizards-sleep.md @@ -0,0 +1,5 @@ +--- +"@hi-ui/use-search-mode": patch +--- + +异步 search 增加防抖功能 diff --git a/packages/hooks/use-search-mode/package.json b/packages/hooks/use-search-mode/package.json index 4adcde8d1..f988eb037 100644 --- a/packages/hooks/use-search-mode/package.json +++ b/packages/hooks/use-search-mode/package.json @@ -51,6 +51,7 @@ "dependencies": { "@hi-ui/dom-utils": "^4.0.4", "@hi-ui/env": "^4.0.1", + "@hi-ui/func-utils": "^4.0.1", "@hi-ui/loading": "^4.0.4", "@hi-ui/tree-utils": "^4.0.2", "@hi-ui/type-assertion": "^4.0.1",