Namespace filter leads to empty page (#1476)

* Namespace filter leads to empty page

Fix bug where an empty page was shown if the repository namespace filtered overview page was called directly. Also now the namespace filter and the search action can be used together.

Co-authored-by: Florian Scholdei <florian.scholdei@cloudogu.com>
This commit is contained in:
Eduard Heimbuch
2020-12-16 09:46:53 +01:00
committed by GitHub
parent 88b93dc8b8
commit b167d90fea
3 changed files with 11 additions and 10 deletions

View File

@@ -25,7 +25,7 @@ import React from "react";
import { connect } from "react-redux";
import { RouteComponentProps, withRouter } from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next";
import { NamespaceCollection, RepositoryCollection, Link } from "@scm-manager/ui-types";
import { Link, NamespaceCollection, RepositoryCollection } from "@scm-manager/ui-types";
import {
CreateButton,
LinkPaginator,
@@ -61,15 +61,14 @@ type Props = WithTranslation &
namespacesLink: string;
// dispatched functions
fetchReposByPage: (link: string, page: number, namespace?: string, filter?: string) => void;
fetchNamespaces: (link: string) => void;
fetchReposByPage: (link: string, page: number, filter?: string) => void;
fetchNamespaces: (link: string, callback?: () => void) => void;
};
class Overview extends React.Component<Props> {
componentDidMount() {
const { fetchNamespaces, namespacesLink } = this.props;
fetchNamespaces(namespacesLink);
this.fetchRepos();
fetchNamespaces(namespacesLink, () => this.fetchRepos());
}
componentDidUpdate = (prevProps: Props) => {
@@ -130,7 +129,7 @@ class Overview extends React.Component<Props> {
currentGroup={namespace}
groups={namespacesToRender}
groupSelected={this.namespaceSelected}
link="repos"
link={namespace ? `repos/${namespace}` : "repos"}
label={t("overview.createButton")}
testId="repository-overview"
searchPlaceholder={t("overview.searchRepository")}
@@ -204,8 +203,8 @@ const mapDispatchToProps = (dispatch: any) => {
fetchReposByPage: (link: string, page: number, filter?: string) => {
dispatch(fetchReposByPage(link, page, filter));
},
fetchNamespaces: (link: string) => {
dispatch(fetchNamespaces(link));
fetchNamespaces: (link: string, callback?: () => void) => {
dispatch(fetchNamespaces(link, callback));
}
};
};

View File

@@ -143,7 +143,7 @@ export function fetchReposFailure(err: Error): Action {
}
// fetch namespaces
export function fetchNamespaces(link: string) {
export function fetchNamespaces(link: string, callback?: () => void) {
return function(dispatch: any) {
dispatch(fetchNamespacesPending());
return apiClient
@@ -152,6 +152,7 @@ export function fetchNamespaces(link: string) {
.then(namespaces => {
dispatch(fetchNamespacesSuccess(namespaces));
})
.then(callback)
.catch(err => {
dispatch(fetchNamespacesFailure(err));
});