mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-14 17:26:22 +01:00
Add namespace selector
This commit is contained in:
@@ -22,24 +22,30 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { History } from "history";
|
|
||||||
import { withRouter, RouteComponentProps } from "react-router-dom";
|
import { withRouter, RouteComponentProps } from "react-router-dom";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { Button, urls } from "./index";
|
import { Button, DropDown, urls } from "./index";
|
||||||
import { FilterInput } from "./forms";
|
import { FilterInput } from "./forms";
|
||||||
|
import { Namespace } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
type Props = RouteComponentProps & {
|
type Props = RouteComponentProps & {
|
||||||
showCreateButton: boolean;
|
showCreateButton: boolean;
|
||||||
|
namespace: string;
|
||||||
|
namespaces: Namespace[];
|
||||||
link: string;
|
link: string;
|
||||||
|
namespaceSelected: (namespace: string) => void;
|
||||||
label?: string;
|
label?: string;
|
||||||
testId?: string;
|
testId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OverviewPageActions extends React.Component<Props> {
|
class OverviewPageActions extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { history, location, link, testId } = this.props;
|
const { history, namespace, namespaces, location, link, testId } = this.props;
|
||||||
|
const sortedNamespaces = namespaces ? namespaces.map(n => n.namespace).sort() : [];
|
||||||
|
const namespaceOptions = ["", ...sortedNamespaces];
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<DropDown options={namespaceOptions} preselectedOption={namespace} optionSelected={this.namespaceSelected} />
|
||||||
<FilterInput
|
<FilterInput
|
||||||
value={urls.getQueryStringFromLocation(location)}
|
value={urls.getQueryStringFromLocation(location)}
|
||||||
filter={filter => {
|
filter={filter => {
|
||||||
@@ -52,6 +58,10 @@ class OverviewPageActions extends React.Component<Props> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespaceSelected = (newNamespace: string) => {
|
||||||
|
this.props.namespaceSelected(newNamespace);
|
||||||
|
};
|
||||||
|
|
||||||
renderCreateButton() {
|
renderCreateButton() {
|
||||||
const { showCreateButton, link, label } = this.props;
|
const { showCreateButton, link, label } = this.props;
|
||||||
if (showCreateButton) {
|
if (showCreateButton) {
|
||||||
|
|||||||
@@ -101,8 +101,16 @@ class Overview extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespaceSelected = (newNamespace: string) => {
|
||||||
|
if (newNamespace === "") {
|
||||||
|
this.props.history.push("/repos/");
|
||||||
|
} else {
|
||||||
|
this.props.history.push(`/repos/${newNamespace}/`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { error, loading, showCreateButton, namespace, t } = this.props;
|
const { error, loading, showCreateButton, namespace, namespaces, t } = this.props;
|
||||||
|
|
||||||
const link = namespace ? `repos/${namespace}` : "repos";
|
const link = namespace ? `repos/${namespace}` : "repos";
|
||||||
|
|
||||||
@@ -112,6 +120,9 @@ class Overview extends React.Component<Props> {
|
|||||||
<PageActions>
|
<PageActions>
|
||||||
<OverviewPageActions
|
<OverviewPageActions
|
||||||
showCreateButton={showCreateButton}
|
showCreateButton={showCreateButton}
|
||||||
|
namespace={namespace}
|
||||||
|
namespaces={namespaces}
|
||||||
|
namespaceSelected={this.namespaceSelected}
|
||||||
link={link}
|
link={link}
|
||||||
label={t("overview.createButton")}
|
label={t("overview.createButton")}
|
||||||
testId="repository-overview"
|
testId="repository-overview"
|
||||||
|
|||||||
Reference in New Issue
Block a user