mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 14:05:44 +01:00
Add branch selector to sources
This commit is contained in:
@@ -60,6 +60,8 @@ class BranchSelector extends React.Component<Props, State> {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import type { Repository, File } from "@scm-manager/ui-types";
|
import type { Repository, Branch, File } from "@scm-manager/ui-types";
|
||||||
import FileTree from "../components/FileTree";
|
import FileTree from "../components/FileTree";
|
||||||
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
|
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
|
||||||
import {
|
import {
|
||||||
@@ -10,6 +10,8 @@ import {
|
|||||||
getSources,
|
getSources,
|
||||||
isFetchSourcesPending
|
isFetchSourcesPending
|
||||||
} from "../modules/sources";
|
} from "../modules/sources";
|
||||||
|
import BranchSelector from "../../containers/BranchSelector";
|
||||||
|
import { getBranches } from "../../modules/branches";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
@@ -19,6 +21,8 @@ type Props = {
|
|||||||
revision: string,
|
revision: string,
|
||||||
path: string,
|
path: string,
|
||||||
baseUrl: string,
|
baseUrl: string,
|
||||||
|
branches: Branch[],
|
||||||
|
selectedBranch: string,
|
||||||
|
|
||||||
// dispatch props
|
// dispatch props
|
||||||
fetchSources: (
|
fetchSources: (
|
||||||
@@ -26,6 +30,9 @@ type Props = {
|
|||||||
revision: string,
|
revision: string,
|
||||||
path: string
|
path: string
|
||||||
) => void,
|
) => void,
|
||||||
|
|
||||||
|
// Context props
|
||||||
|
history: any,
|
||||||
match: any
|
match: any
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -36,6 +43,16 @@ class Sources extends React.Component<Props> {
|
|||||||
fetchSources(repository, revision, path);
|
fetchSources(repository, revision, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
branchSelected = (branch?: Branch) => {
|
||||||
|
let url;
|
||||||
|
if (branch) {
|
||||||
|
url = `${this.props.baseUrl}/${branch.revision}`;
|
||||||
|
} else {
|
||||||
|
url = `${this.props.baseUrl}/`;
|
||||||
|
}
|
||||||
|
this.props.history.push(url);
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { sources, revision, path, baseUrl, loading, error } = this.props;
|
const { sources, revision, path, baseUrl, loading, error } = this.props;
|
||||||
|
|
||||||
@@ -48,14 +65,32 @@ class Sources extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FileTree
|
<>
|
||||||
tree={sources}
|
{this.renderBranchSelector()}
|
||||||
revision={revision}
|
<FileTree
|
||||||
path={path}
|
tree={sources}
|
||||||
baseUrl={baseUrl}
|
revision={revision}
|
||||||
/>
|
path={path}
|
||||||
|
baseUrl={baseUrl}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderBranchSelector = () => {
|
||||||
|
const { repository, branches } = this.props;
|
||||||
|
if (repository._links.branches) {
|
||||||
|
return (
|
||||||
|
<BranchSelector
|
||||||
|
branches={branches}
|
||||||
|
selected={(b: Branch) => {
|
||||||
|
this.branchSelected(b);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => {
|
const mapStateToProps = (state, ownProps) => {
|
||||||
@@ -64,6 +99,7 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
|
|
||||||
const loading = isFetchSourcesPending(state, repository, revision, path);
|
const loading = isFetchSourcesPending(state, repository, revision, path);
|
||||||
const error = getFetchSourcesFailure(state, repository, revision, path);
|
const error = getFetchSourcesFailure(state, repository, revision, path);
|
||||||
|
const branches = getBranches(state, repository);
|
||||||
const sources = getSources(state, repository, revision, path);
|
const sources = getSources(state, repository, revision, path);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -71,7 +107,8 @@ const mapStateToProps = (state, ownProps) => {
|
|||||||
error,
|
error,
|
||||||
sources,
|
sources,
|
||||||
revision,
|
revision,
|
||||||
path
|
path,
|
||||||
|
branches
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user