From 3b76772f81a14843d486450be66d765a564d475d Mon Sep 17 00:00:00 2001 From: Florian Hye <31217036+Flo2410@users.noreply.github.com> Date: Fri, 9 Feb 2024 16:49:25 +0100 Subject: [PATCH 1/3] Fix: search opens when losing focus, prevent unnecessary search API calls (#2867) Co-Authored-By: shamoon <4887959+shamoon@users.noreply.github.com> --- src/components/quicklaunch.jsx | 2 +- src/components/widgets/search/search.jsx | 81 +++++++++++++++--------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/components/quicklaunch.jsx b/src/components/quicklaunch.jsx index 23f7cef9..aaa40493 100644 --- a/src/components/quicklaunch.jsx +++ b/src/components/quicklaunch.jsx @@ -120,7 +120,7 @@ export default function QuickLaunch({ }); if (showSearchSuggestions && searchProvider.suggestionUrl) { - if (searchString.trim() !== searchSuggestions[0]) { + if (searchString.trim() !== searchSuggestions[0]?.trim()) { fetch( `/api/search/searchSuggestion?query=${encodeURIComponent(searchString)}&providerName=${ searchProvider.name ?? "Custom" diff --git a/src/components/widgets/search/search.jsx b/src/components/widgets/search/search.jsx index 6a634308..c9391d35 100644 --- a/src/components/widgets/search/search.jsx +++ b/src/components/widgets/search/search.jsx @@ -1,4 +1,4 @@ -import { useState, useEffect, useCallback, Fragment } from "react"; +import { useState, useEffect, Fragment } from "react"; import { useTranslation } from "next-i18next"; import { FiSearch } from "react-icons/fi"; import { SiDuckduckgo, SiMicrosoftbing, SiGoogle, SiBaidu, SiBrave } from "react-icons/si"; @@ -119,20 +119,27 @@ export default function Search({ options }) { }; }, [selectedProvider, options, query, searchSuggestions]); - const submitCallback = useCallback( - (value) => { - const q = encodeURIComponent(value); - const { url } = selectedProvider; - if (url) { - window.open(`${url}${q}`, options.target || "_blank"); - } else { - window.open(`${options.url}${q}`, options.target || "_blank"); - } + let currentSuggestion; - setQuery(""); - }, - [selectedProvider, options.url, options.target], - ); + function doSearch(value) { + const q = encodeURIComponent(value); + const { url } = selectedProvider; + if (url) { + window.open(`${url}${q}`, options.target || "_blank"); + } else { + window.open(`${options.url}${q}`, options.target || "_blank"); + } + + setQuery(""); + currentSuggestion = null; + } + + const handleSearchKeyDown = (event) => { + const useSuggestion = searchSuggestions.length && currentSuggestion; + if (event.key === "Enter") { + doSearch(useSuggestion ? currentSuggestion : event.target.value); + } + }; if (!availableProviderIds) { return null; @@ -148,7 +155,7 @@ export default function Search({ options }) {
- + setQuery(event.target.value)} + onChange={(event) => { + setQuery(event.target.value); + }} required autoCapitalize="off" autoCorrect="off" autoComplete="off" // eslint-disable-next-line jsx-a11y/no-autofocus autoFocus={options.focus} + onBlur={(e) => e.preventDefault()} + onKeyDown={handleSearchKeyDown} /> {searchSuggestions[1].map((suggestion) => ( - - {({ active }) => ( -
- {suggestion.indexOf(query) === 0 ? query : ""} - - {suggestion.indexOf(query) === 0 ? suggestion.substring(query.length) : suggestion} - -
- )} + { + doSearch(suggestion); + }} + className="flex w-full" + > + {({ active }) => { + if (active) currentSuggestion = suggestion; + return ( +
+ {suggestion.indexOf(query) === 0 ? query : ""} + + {suggestion.indexOf(query) === 0 ? suggestion.substring(query.length) : suggestion} + +
+ ); + }}
))}
From eda5b0f0cf0fa0d8deb041e09781cbff977f4710 Mon Sep 17 00:00:00 2001 From: Lawton Manning Date: Fri, 9 Feb 2024 14:00:08 -0500 Subject: [PATCH 2/3] Fix: healthchecks widget does not respect fields parameter (#2875) --- src/widgets/healthchecks/component.jsx | 28 +++++++++++--------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/widgets/healthchecks/component.jsx b/src/widgets/healthchecks/component.jsx index bcb8d740..21fb7cb6 100644 --- a/src/widgets/healthchecks/component.jsx +++ b/src/widgets/healthchecks/component.jsx @@ -63,26 +63,22 @@ export default function Component({ service }) { ); } - const hasUuid = widget?.uuid; + const hasUuid = !!widget?.uuid; const { upCount, downCount } = countStatus(data); - return ( + return hasUuid ? ( - {hasUuid ? ( - <> - - - - ) : ( - <> - - - - )} + + + + ) : ( + + + ); } From 187291eecad34896f2c059807933df8e6bfa770a Mon Sep 17 00:00:00 2001 From: Florian Hye <31217036+Flo2410@users.noreply.github.com> Date: Fri, 9 Feb 2024 20:46:56 +0100 Subject: [PATCH 3/3] Chore: add Python requirements and prettier to devcontaier (#2878) --- .devcontainer/Dockerfile | 6 ++++ .devcontainer/devcontainer.json | 49 ++++++++++++++++----------------- .devcontainer/setup.sh | 2 ++ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 9f20426f..44bc1759 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -3,4 +3,10 @@ FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:${VARIANT} RUN npm install -g pnpm +RUN apt-get update \ + && apt-get -y install --no-install-recommends \ + python3-pip \ + && apt-get clean -y \ + && rm -rf /var/lib/apt/lists/* + ENV PATH="${PATH}:./node_modules/.bin" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 15d1b9f3..06e7f6ee 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,27 +1,26 @@ { - "name": "homepage", - "build": { - "dockerfile": "Dockerfile", - "args": { - "VARIANT": "18-bullseye" - } - }, - "customizations": { - "vscode": { - "extensions": [ - "dbaeumer.vscode-eslint", - "mhutchie.git-graph", - "streetsidesoftware.code-spell-checker", - ], - "settings": { - "eslint.format.enable": true, - "eslint.lintTask.enable": true, - "eslint.packageManager": "pnpm" - } - } - }, - "postCreateCommand": ".devcontainer/setup.sh", - "forwardPorts": [ - 3000 - ] + "name": "homepage", + "build": { + "dockerfile": "Dockerfile", + "args": { + "VARIANT": "18-bullseye", + }, + }, + "customizations": { + "vscode": { + "extensions": [ + "dbaeumer.vscode-eslint", + "mhutchie.git-graph", + "streetsidesoftware.code-spell-checker", + "esbenp.prettier-vscode", + ], + "settings": { + "eslint.format.enable": true, + "eslint.lintTask.enable": true, + "eslint.packageManager": "pnpm", + }, + }, + }, + "postCreateCommand": ".devcontainer/setup.sh", + "forwardPorts": [3000], } diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 70bf96cf..ea5d2fe9 100755 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -3,6 +3,8 @@ # Install Node packages pnpm install +python3 -m pip install -r requirements.txt + # Copy in skeleton configuration if there is no existing configuration if [ ! -d "config/" ]; then echo "Adding skeleton config"