Show warning for search requests without valid search context (#2114)

This commit is contained in:
Eduard Heimbuch
2022-09-06 18:24:34 +02:00
committed by GitHub
parent 6f2be13197
commit 9ea76073b2
5 changed files with 16 additions and 5 deletions

View File

@@ -0,0 +1,2 @@
- type: fixed
description: Show warning message for invalid search requests ([#2114](https://github.com/scm-manager/scm-manager/pull/2114))

View File

@@ -93,7 +93,6 @@ const findLink = (links: Link[], name: string) => {
return l.href;
}
}
throw new Error(`could not find search link for ${name}`);
};
const useSearchLinks = (options?: SearchOptions): SearchLinks => {
@@ -105,11 +104,11 @@ const useSearchLinks = (options?: SearchOptions): SearchLinks => {
);
if (options?.repositoryNameContext) {
return { links: repo?._links["search"] as Link[], isLoading: repoLoading };
return { links: (repo?._links["search"] as Link[]) || [], isLoading: repoLoading };
}
if (options?.namespaceContext) {
return { links: namespace?._links["search"] as Link[], isLoading: namespaceLoading };
return { links: (namespace?._links["search"] as Link[]) || [], isLoading: namespaceLoading };
}
const searchLinks = links["search"];

View File

@@ -205,6 +205,7 @@
"types": "Ergebnisse",
"noHits": "Keine Ergebnisse gefunden. Auf der rechten Seite finden Sie weitere Kategorien, in denen Ergebnisse vorhanden sein könnten",
"syntaxHelp": "Finden Sie bessere Ergebnisse durch die Nutzung der vollen <0>Such-Syntax</0>",
"invalid": "Ihre Suchanfrage ist ungültig. Bitte verwenden Sie einen gültigen Suchkontext.",
"quickSearch": {
"resultHeading": "Hilfe beim Suchen?",
"parseError": "Der Suchstring is ungültig.",

View File

@@ -206,6 +206,7 @@
"types": "Results",
"noHits": "No results found. On the right side you will find other categories where results might be available",
"syntaxHelp": "Find better results by using the full <0>search syntax</0>",
"invalid": "Your search request is invalid. Please be sure to use a valid search context.",
"quickSearch": {
"resultHeading": "Need help?",
"parseError": "Failed to parse query.",

View File

@@ -27,6 +27,7 @@ import {
CustomQueryFlexWrappedColumns,
Level,
NavLink,
Notification,
Page,
PrimaryContentColumn,
SecondaryNavigation,
@@ -75,7 +76,7 @@ const usePageParams = () => {
const location = useLocation();
const { type: selectedType, ...params } = useParams<PathParams>();
const page = urls.getPageFromMatch({ params });
const query = urls.getQueryStringFromLocation(location);
const query = urls.getQueryStringFromLocation(location) || "";
const namespace = urls.getValueStringFromLocationByKey(location, "namespace");
const name = urls.getValueStringFromLocationByKey(location, "name");
return {
@@ -127,6 +128,11 @@ const SearchSubTitle: FC<Props> = ({ selectedType, query }) => {
);
};
const InvalidSearch: FC = () => {
const [t] = useTranslation("commons");
return <Notification type="warning">{t("search.invalid")}</Notification>;
};
const Search: FC = () => {
const [t] = useTranslation(["commons", "plugins"]);
const [showHelp, setShowHelp] = useState(false);
@@ -220,7 +226,9 @@ const Search: FC = () => {
)}
</SecondaryNavigation>
</CustomQueryFlexWrappedColumns>
) : null}
) : (
<InvalidSearch />
)}
</Page>
);
};