From 8a18a6d0a75c9d08b5ab96afe62d15024edfb5dc Mon Sep 17 00:00:00 2001 From: Laurentiu Niculae Date: Tue, 13 Feb 2024 09:19:18 +0200 Subject: [PATCH 1/2] feat(search-bar): redirect to image view on enter when search maches a repo:tag Signed-off-by: Laurentiu Niculae --- src/components/Header/SearchSuggestion.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/Header/SearchSuggestion.jsx b/src/components/Header/SearchSuggestion.jsx index 0bf2f97f..c769c2bc 100644 --- a/src/components/Header/SearchSuggestion.jsx +++ b/src/components/Header/SearchSuggestion.jsx @@ -132,8 +132,19 @@ function SearchSuggestion({ setSearchCurrentValue = () => {} }) { const handleSearch = (event) => { const { key, type } = event; + const name = event.target.value; if (key === 'Enter' || type === 'click') { - navigate({ pathname: `/explore`, search: createSearchParams({ search: inputValue || '' }).toString() }); + const splitName = name.split(':'); + let inputInSuggestions = false; + + if (splitName.length > 1) { + inputInSuggestions = suggestionData.some((sd) => sd.repoName === splitName[0] && sd.tag === splitName[1]); + } + if (inputInSuggestions) { + navigate(`/image/${encodeURIComponent(splitName[0])}/tag/${splitName[1]}`); + } else { + navigate({ pathname: `/explore`, search: createSearchParams({ search: inputValue || '' }).toString() }); + } } }; From 2316a4ca34c93a2a8b4465c61d7943d5d6e2a983 Mon Sep 17 00:00:00 2001 From: Laurentiu Niculae Date: Fri, 1 Mar 2024 11:45:57 +0200 Subject: [PATCH 2/2] feat(test): WIP Signed-off-by: Laurentiu Niculae --- src/components/Header/SearchSuggestion.jsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/components/Header/SearchSuggestion.jsx b/src/components/Header/SearchSuggestion.jsx index c769c2bc..ddb68913 100644 --- a/src/components/Header/SearchSuggestion.jsx +++ b/src/components/Header/SearchSuggestion.jsx @@ -134,13 +134,8 @@ function SearchSuggestion({ setSearchCurrentValue = () => {} }) { const { key, type } = event; const name = event.target.value; if (key === 'Enter' || type === 'click') { - const splitName = name.split(':'); - let inputInSuggestions = false; - - if (splitName.length > 1) { - inputInSuggestions = suggestionData.some((sd) => sd.repoName === splitName[0] && sd.tag === splitName[1]); - } - if (inputInSuggestions) { + if (name?.includes(':')) { + const splitName = name.split(':'); navigate(`/image/${encodeURIComponent(splitName[0])}/tag/${splitName[1]}`); } else { navigate({ pathname: `/explore`, search: createSearchParams({ search: inputValue || '' }).toString() });