Merged in feature/modify_for_svn (pull request #342)

Feature/modify for svn
This commit is contained in:
Sebastian Sdorra
2019-11-05 13:30:25 +00:00
51 changed files with 843 additions and 228 deletions

View File

@@ -20,6 +20,7 @@ import PermissionsNavLink from "../components/PermissionsNavLink";
import Sources from "../sources/containers/Sources";
import RepositoryNavLink from "../components/RepositoryNavLink";
import { getLinks, getRepositoriesLink } from "../../modules/indexResource";
import SourceExtensions from "../sources/containers/SourceExtensions";
type Props = WithTranslation & {
namespace: string;
@@ -67,6 +68,12 @@ class RepositoryRoot extends React.Component<Props> {
return route.location.pathname.match(regex);
};
matchesSources = (route: any) => {
const url = this.matchedUrl();
const regex = new RegExp(`${url}(/sources|/sourceext)/.*`);
return route.location.pathname.match(regex);
};
render() {
const { loading, error, indexLinks, repository, t } = this.props;
@@ -120,6 +127,15 @@ class RepositoryRoot extends React.Component<Props> {
path={`${url}/sources/:revision/:path*`}
render={() => <Sources repository={repository} baseUrl={`${url}/sources`} />}
/>
<Route
path={`${url}/sourceext/:extension`}
exact={true}
render={() => <SourceExtensions repository={repository} />}
/>
<Route
path={`${url}/sourceext/:extension/:revision/:path*`}
render={() => <SourceExtensions repository={repository} />}
/>
<Route
path={`${url}/changesets`}
render={() => (
@@ -186,6 +202,7 @@ class RepositoryRoot extends React.Component<Props> {
to={`${url}/sources`}
icon="fas fa-code"
label={t("repositoryRoot.menu.sourcesNavLink")}
activeWhenMatch={this.matchesSources}
activeOnlyWhenExact={false}
/>
<ExtensionPoint name="repository.navigation" props={extensionProps} renderAll={true} />

View File

@@ -75,7 +75,7 @@ class Content extends React.Component<Props, State> {
};
showHeader() {
const { file, revision } = this.props;
const { repository, file, revision } = this.props;
const { showHistory, collapsed } = this.state;
const icon = collapsed ? "angle-right" : "angle-down";
@@ -99,6 +99,7 @@ class Content extends React.Component<Props, State> {
<ExtensionPoint
name="repos.sources.content.actionbar"
props={{
repository,
file,
revision,
handleExtensionError: this.handleExtensionError

View File

@@ -0,0 +1,92 @@
import React from "react";
import { Repository, File } from "@scm-manager/ui-types";
import { withRouter, RouteComponentProps } from "react-router-dom";
import { ExtensionPoint, binder } from "@scm-manager/ui-extensions";
import { fetchSources, getFetchSourcesFailure, getSources, isFetchSourcesPending } from "../modules/sources";
import { connect } from "react-redux";
import { Loading, ErrorNotification } from "@scm-manager/ui-components";
import Notification from "@scm-manager/ui-components/src/Notification";
import {WithTranslation, withTranslation} from "react-i18next";
type Props = WithTranslation & RouteComponentProps & {
repository: Repository;
// url params
extension: string;
revision?: string;
path?: string;
// redux state
loading: boolean;
error?: Error | null;
sources?: File | null;
// dispatch props
fetchSources: (repository: Repository, revision: string, path: string) => void;
};
const extensionPointName = "repos.sources.extensions";
class SourceExtensions extends React.Component<Props> {
componentDidMount() {
const { fetchSources, repository, revision, path } = this.props;
// TODO get typing right
fetchSources(repository,revision || "", path || "");
}
render() {
const { loading, error, repository, extension, revision, path, sources, t } = this.props;
if (error) {
return <ErrorNotification error={error} />;
}
if (loading) {
return <Loading />;
}
const extprops = { extension, repository, revision, path, sources };
if (!binder.hasExtension(extensionPointName, extprops)) {
return <Notification type="warning">{t("sources.extension.notBound")}</Notification>;
}
return <ExtensionPoint name={extensionPointName} props={extprops} />;
}
}
const mapStateToProps = (state: any, ownProps: Props): Partial<Props> => {
const { repository, match } = ownProps;
// @ts-ignore
const revision: string = match.params.revision;
// @ts-ignore
const path: string = match.params.path;
// @ts-ignore
const extension: string = match.params.extension;
const loading = isFetchSourcesPending(state, repository, revision, path);
const error = getFetchSourcesFailure(state, repository, revision, path);
const sources = getSources(state, repository, revision, path);
return {
repository,
extension,
revision,
path,
loading,
error,
sources
};
};
const mapDispatchToProps = (dispatch: any) => {
return {
fetchSources: (repository: Repository, revision: string, path: string) => {
dispatch(fetchSources(repository, decodeURIComponent(revision), path));
}
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(SourceExtensions))
);

View File

@@ -13,7 +13,7 @@ import {
} from "../../branches/modules/branches";
import { compose } from "redux";
import Content from "./Content";
import { fetchSources, isDirectory } from "../modules/sources";
import {fetchSources, getSources, isDirectory} from "../modules/sources";
type Props = WithTranslation & {
repository: Repository;
@@ -24,6 +24,7 @@ type Props = WithTranslation & {
revision: string;
path: string;
currentFileIsDirectory: boolean;
sources: File;
// dispatch props
fetchBranches: (p: Repository) => void;
@@ -52,7 +53,7 @@ class Sources extends React.Component<Props, State> {
const { fetchBranches, repository, revision, path, fetchSources } = this.props;
fetchBranches(repository);
fetchSources(repository, revision, path);
fetchSources(repository, this.decodeRevision(revision), path);
this.redirectToDefaultBranch();
}
@@ -60,12 +61,16 @@ class Sources extends React.Component<Props, State> {
componentDidUpdate(prevProps) {
const { fetchSources, repository, revision, path } = this.props;
if (prevProps.revision !== revision || prevProps.path !== path) {
fetchSources(repository, revision, path);
fetchSources(repository, this.decodeRevision(revision), path);
}
this.redirectToDefaultBranch();
}
decodeRevision = (revision: string) => {
return revision ? decodeURIComponent(revision) : revision;
};
redirectToDefaultBranch = () => {
const { branches } = this.props;
if (this.shouldRedirectToDefaultBranch()) {
@@ -148,23 +153,22 @@ class Sources extends React.Component<Props, State> {
};
renderBreadcrumb = () => {
const { revision, path, baseUrl, branches, repository } = this.props;
const { revision, path, baseUrl, branches, sources, repository } = this.props;
const { selectedBranch } = this.state;
if (revision) {
return (
<Breadcrumb
revision={encodeURIComponent(revision)}
path={path}
baseUrl={baseUrl}
branch={selectedBranch}
defaultBranch={branches && branches.filter(b => b.defaultBranch === true)[0]}
branches={branches}
repository={repository}
/>
);
}
return null;
return (
<Breadcrumb
repository={repository}
revision={revision}
path={path}
baseUrl={baseUrl}
branch={selectedBranch}
defaultBranch={
branches && branches.filter(b => b.defaultBranch === true)[0]
}
sources={sources}
/>
);
};
}
@@ -178,15 +182,17 @@ const mapStateToProps = (state, ownProps) => {
const currentFileIsDirectory = decodedRevision
? isDirectory(state, repository, decodedRevision, path)
: isDirectory(state, repository, revision, path);
const sources = getSources(state, repository, decodedRevision, path);
return {
repository,
revision: decodedRevision,
revision,
path,
loading,
error,
branches,
currentFileIsDirectory
currentFileIsDirectory,
sources
};
};

View File

@@ -1,5 +1,5 @@
import * as types from "../../../modules/types";
import { Repository, File, Action } from "@scm-manager/ui-types";
import { Repository, File, Action, Link } from "@scm-manager/ui-types";
import { apiClient } from "@scm-manager/ui-components";
import { isPending } from "../../../modules/pending";
import { getFailure } from "../../../modules/failure";
@@ -25,7 +25,7 @@ export function fetchSources(repository: Repository, revision: string, path: str
}
function createUrl(repository: Repository, revision: string, path: string) {
const base = repository._links.sources.href;
const base = (repository._links.sources as Link).href;
if (!revision && !path) {
return base;
}
@@ -61,7 +61,7 @@ export function fetchSourcesFailure(repository: Repository, revision: string, pa
function createItemId(repository: Repository, revision: string, path: string) {
const revPart = revision ? revision : "_";
const pathPart = path ? path : "";
return `${repository.namespace}/${repository.name}/${revPart}/${pathPart}`;
return `${repository.namespace}/${repository.name}/${decodeURIComponent(revPart)}/${pathPart}`;
}
// reducer