diff --git a/gradle/changelog/navigate_after_search.yaml b/gradle/changelog/navigate_after_search.yaml new file mode 100644 index 0000000000..91bd0cb265 --- /dev/null +++ b/gradle/changelog/navigate_after_search.yaml @@ -0,0 +1,2 @@ +- type: fixed + description: Navigate after search ([#1589](https://github.com/scm-manager/scm-manager/pull/1589)) diff --git a/scm-ui/ui-api/src/urls.ts b/scm-ui/ui-api/src/urls.ts index 50e564d848..b413302678 100644 --- a/scm-ui/ui-api/src/urls.ts +++ b/scm-ui/ui-api/src/urls.ts @@ -38,6 +38,13 @@ export function withEndingSlash(url: string) { return url + "/"; } +export function withStartingSlash(url: string) { + if (url.startsWith("/")) { + return url; + } + return "/" + url; +} + export function concat(base: string, ...parts: string[]) { let url = base; for (const p of parts) { diff --git a/scm-ui/ui-components/src/OverviewPageActions.tsx b/scm-ui/ui-components/src/OverviewPageActions.tsx index abfc12c890..d5d9ee99d9 100644 --- a/scm-ui/ui-components/src/OverviewPageActions.tsx +++ b/scm-ui/ui-components/src/OverviewPageActions.tsx @@ -38,11 +38,15 @@ type Props = { searchPlaceholder?: string; }; +const createAbsoluteLink = (url: string) => { + return urls.withStartingSlash(urls.withEndingSlash(url)); +}; + const OverviewPageActions: FC = ({ groups, currentGroup, showCreateButton, - link, + link: inputLink, groupSelected, label, testId, @@ -50,8 +54,9 @@ const OverviewPageActions: FC = ({ }) => { const history = useHistory(); const location = useLocation(); - const [filterValue, setFilterValue] = useState(urls.getQueryStringFromLocation(location)); - + const [filterValue, setFilterValue] = useState(urls.getQueryStringFromLocation(location) || ""); + const link = createAbsoluteLink(inputLink); + const groupSelector = groups && (
= ({ if (showCreateButton) { return (
-
); } return null; }; - const filter = (filter: string) => { - if ((filter && filter !== filterValue) || (!filter && filterValue)) { - history.push(`/${link}/?q=${filter}`); - } else { - history.push(`${location.pathname}?q=${filter}`); + const filter = (q: string) => { + if (q !== filterValue) { + setFilterValue(q); + history.push(`${link}?q=${q}`); } - setFilterValue(filter); }; return (