diff --git a/gradle/changelog/keep_type_on_search.yaml b/gradle/changelog/keep_type_on_search.yaml
new file mode 100644
index 0000000000..626ba4ee95
--- /dev/null
+++ b/gradle/changelog/keep_type_on_search.yaml
@@ -0,0 +1,2 @@
+- type: Changed
+ description: Keep search result type if searched from result page ([#1764](https://github.com/scm-manager/scm-manager/pull/1764))
diff --git a/scm-ui/ui-components/src/search/Hit.tsx b/scm-ui/ui-components/src/search/Hit.tsx
index d5b47653a4..a6c1694832 100644
--- a/scm-ui/ui-components/src/search/Hit.tsx
+++ b/scm-ui/ui-components/src/search/Hit.tsx
@@ -42,7 +42,7 @@ type SearchResultType = FC & {
};
const Hit: SearchResultType = ({ children }) => {
- return {children};
+ return {children};
};
Hit.Title = ({ className, children }) => (
diff --git a/scm-ui/ui-components/src/search/TextHitField.tsx b/scm-ui/ui-components/src/search/TextHitField.tsx
index 8cb07a2276..3af01a1334 100644
--- a/scm-ui/ui-components/src/search/TextHitField.tsx
+++ b/scm-ui/ui-components/src/search/TextHitField.tsx
@@ -49,15 +49,17 @@ const HighlightedTextField: FC = ({ field }) => (
>
);
-const TextHitField: FC = ({ hit, field: fieldName, truncateValueAt = 0 }) => {
+const TextHitField: FC = ({ hit, field: fieldName, children, truncateValueAt = 0 }) => {
const field = hit.fields[fieldName];
if (!field) {
- return null;
+ return <>{children}>;
} else if (isHighlightedHitField(field)) {
return ;
} else {
let value = field.value;
- if (typeof value === "string" && truncateValueAt > 0 && value.length > truncateValueAt) {
+ if (value === "") {
+ return <>{children}>;
+ } else if (typeof value === "string" && truncateValueAt > 0 && value.length > truncateValueAt) {
value = value.substring(0, truncateValueAt) + "...";
}
return <>{value}>;
diff --git a/scm-ui/ui-webapp/src/containers/OmniSearch.tsx b/scm-ui/ui-webapp/src/containers/OmniSearch.tsx
index 2bedb86949..460609daa8 100644
--- a/scm-ui/ui-webapp/src/containers/OmniSearch.tsx
+++ b/scm-ui/ui-webapp/src/containers/OmniSearch.tsx
@@ -26,7 +26,7 @@ import { Hit, Links, ValueHitField } from "@scm-manager/ui-types";
import styled from "styled-components";
import { BackendError, useSearch } from "@scm-manager/ui-api";
import classNames from "classnames";
-import { Link, useHistory } from "react-router-dom";
+import { Link, useHistory, useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
import {
Button,
@@ -322,6 +322,23 @@ const useShowResultsOnFocus = () => {
};
};
+const useSearchType = () => {
+ const location = useLocation();
+ const pathname = location.pathname;
+
+ let type = "repository";
+ if (pathname.startsWith("/search/")) {
+ const path = pathname.substring("/search/".length);
+ const index = path.indexOf("/");
+ if (index > 0) {
+ type = path.substring(0, index);
+ } else {
+ type = path;
+ }
+ }
+ return type;
+};
+
const OmniSearch: FC = () => {
const [query, setQuery] = useState("");
const debouncedQuery = useDebounce(query, 250);
@@ -329,13 +346,14 @@ const OmniSearch: FC = () => {
const { showResults, hideResults, ...handlers } = useShowResultsOnFocus();
const [showHelp, setShowHelp] = useState(false);
const history = useHistory();
+ const searchType = useSearchType();
const openHelp = () => setShowHelp(true);
const closeHelp = () => setShowHelp(false);
const clearQuery = () => setQuery("");
const gotoDetailSearch = () => {
- history.push(`/search/repository/?q=${query}`);
+ history.push(`/search/${searchType}/?q=${query}`);
hideResults();
};