Form on search page retains context

The result category will no longer be reset
to 'repository' when the search query is
refined and resubmitted.
This commit is contained in:
Florian Scholdei
2024-06-12 13:55:35 +02:00
parent 728915fe1c
commit 03e5ecbc7c
3 changed files with 8 additions and 5 deletions

View File

@@ -0,0 +1,2 @@
- type: changed
description: Search category stays the same when the search query is modified

View File

@@ -39,6 +39,7 @@ type Props = {
shouldClear: boolean;
ariaId: string;
nextFocusRef: RefObject<HTMLElement>;
selectedType?: string;
};
type GuardProps = Props & {
@@ -121,7 +122,7 @@ const useSearchParams = () => {
};
};
const OmniSearch: FC<Props> = ({ shouldClear }) => {
const OmniSearch: FC<Props> = ({ shouldClear, selectedType = "repository" }) => {
const [t] = useTranslation("commons");
const { initialQuery } = useSearchParams();
const [query, setQuery] = useState(shouldClear ? "" : initialQuery);
@@ -173,7 +174,7 @@ const OmniSearch: FC<Props> = ({ shouldClear }) => {
<HitEntry
key="search.quickSearch.searchNamespace"
label={t("search.quickSearch.searchNamespace")}
link={`/search/repository/?q=${encodeURIComponent(query)}&namespace=${context.namespace}`}
link={`/search/${selectedType}/?q=${encodeURIComponent(query)}&namespace=${context.namespace}`}
/>
);
}
@@ -181,7 +182,7 @@ const OmniSearch: FC<Props> = ({ shouldClear }) => {
<HitEntry
key="search.quickSearch.searchEverywhere"
label={t("search.quickSearch.searchEverywhere")}
link={`/search/repository/?q=${encodeURIComponent(query)}`}
link={`/search/${selectedType}/?q=${encodeURIComponent(query)}`}
/>
);
hits?.forEach((hit, idx) => {
@@ -195,7 +196,7 @@ const OmniSearch: FC<Props> = ({ shouldClear }) => {
);
});
return newEntries;
}, [context.name, context.namespace, hits, id, query, searchTypes, t]);
}, [context.name, context.namespace, hits, id, query, searchTypes, selectedType, t]);
return (
<div className={classNames("navbar-item", "field", "mb-0")}>
{showHelp ? <SyntaxModal close={closeHelp} /> : null}

View File

@@ -158,7 +158,7 @@ const SearchSubTitle: FC<Props> = ({ selectedType, queryResult, links }) => {
<br />
<Trans i18nKey="search.syntaxHelp" components={[<SyntaxHelpLink key="syntaxHelpLink" />]} />
<OmniSearchWrapper className={"mt-4 mb-2"}>
<OmniSearch links={links} shouldClear={false} ariaId={"searchPage"} />
<OmniSearch links={links} shouldClear={false} ariaId={"searchPage"} selectedType={selectedType} />
</OmniSearchWrapper>
</>
);