mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
merged
This commit is contained in:
@@ -12,9 +12,9 @@ class FileSize extends React.Component<Props> {
|
||||
}
|
||||
|
||||
const units = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1000));
|
||||
|
||||
const size = i === 0 ? bytes : (bytes / 1024 ** i).toFixed(2);
|
||||
const size = i === 0 ? bytes : (bytes / 1000 ** i).toFixed(2);
|
||||
return `${size} ${units[i]}`;
|
||||
}
|
||||
|
||||
@@ -3,17 +3,16 @@ import { contextPath } from "./urls";
|
||||
import { createBackendError, ForbiddenError, isBackendError, UnauthorizedError } from "./errors";
|
||||
import type { BackendErrorContent } from "./errors";
|
||||
|
||||
const fetchOptions: RequestOptions = {
|
||||
credentials: "same-origin",
|
||||
headers: {
|
||||
const applyFetchOptions: (RequestOptions) => RequestOptions = o => {
|
||||
o.credentials = "same-origin";
|
||||
o.headers = {
|
||||
Cache: "no-cache",
|
||||
// identify the request as ajax request
|
||||
"X-Requested-With": "XMLHttpRequest"
|
||||
}
|
||||
};
|
||||
return o;
|
||||
};
|
||||
|
||||
|
||||
|
||||
function handleFailure(response: Response) {
|
||||
if (!response.ok) {
|
||||
if (isBackendError(response)) {
|
||||
@@ -47,7 +46,7 @@ export function createUrl(url: string) {
|
||||
|
||||
class ApiClient {
|
||||
get(url: string): Promise<Response> {
|
||||
return fetch(createUrl(url), fetchOptions).then(handleFailure);
|
||||
return fetch(createUrl(url), applyFetchOptions).then(handleFailure);
|
||||
}
|
||||
|
||||
post(url: string, payload: any, contentType: string = "application/json") {
|
||||
@@ -73,7 +72,7 @@ class ApiClient {
|
||||
let options: RequestOptions = {
|
||||
method: "HEAD"
|
||||
};
|
||||
options = Object.assign(options, fetchOptions);
|
||||
options = applyFetchOptions(options);
|
||||
return fetch(createUrl(url), options).then(handleFailure);
|
||||
}
|
||||
|
||||
@@ -81,7 +80,7 @@ class ApiClient {
|
||||
let options: RequestOptions = {
|
||||
method: "DELETE"
|
||||
};
|
||||
options = Object.assign(options, fetchOptions);
|
||||
options = applyFetchOptions(options);
|
||||
return fetch(createUrl(url), options).then(handleFailure);
|
||||
}
|
||||
|
||||
@@ -99,7 +98,7 @@ class ApiClient {
|
||||
}
|
||||
|
||||
httpRequestWithBinaryBody(options: RequestOptions, url: string, contentType?: string) {
|
||||
options = Object.assign(options, fetchOptions);
|
||||
options = applyFetchOptions(options);
|
||||
if (contentType) {
|
||||
// $FlowFixMe
|
||||
options.headers["Content-Type"] = contentType;
|
||||
|
||||
@@ -19,6 +19,7 @@ export { default as Paginator } from "./Paginator.js";
|
||||
export { default as LinkPaginator } from "./LinkPaginator.js";
|
||||
export { default as StatePaginator } from "./StatePaginator.js";
|
||||
|
||||
export { default as FileSize } from "./FileSize.js";
|
||||
export { default as ProtectedRoute } from "./ProtectedRoute.js";
|
||||
export { default as Help } from "./Help";
|
||||
export { default as HelpIcon } from "./HelpIcon";
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//@flow
|
||||
import * as React from "react";
|
||||
import injectSheet from "react-jss";
|
||||
import { DateFromNow } from "@scm-manager/ui-components";
|
||||
import FileSize from "./FileSize";
|
||||
import { DateFromNow, FileSize } from "@scm-manager/ui-components";
|
||||
import FileIcon from "./FileIcon";
|
||||
import { Link } from "react-router-dom";
|
||||
import type { File } from "@scm-manager/ui-types";
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import type { File, Repository } from "@scm-manager/ui-types";
|
||||
import { DateFromNow, ButtonGroup } from "@scm-manager/ui-components";
|
||||
import FileSize from "../components/FileSize";
|
||||
import { DateFromNow, ButtonGroup, FileSize } from "@scm-manager/ui-components";
|
||||
import injectSheet from "react-jss";
|
||||
import classNames from "classnames";
|
||||
import FileButtonGroup from "../components/content/FileButtonGroup";
|
||||
|
||||
@@ -61,49 +61,42 @@ class Sources extends React.Component<Props, State> {
|
||||
repository,
|
||||
revision,
|
||||
path,
|
||||
branches,
|
||||
baseUrl,
|
||||
fetchSources
|
||||
} = this.props;
|
||||
|
||||
fetchBranches(repository);
|
||||
fetchSources(repository, revision, path);
|
||||
|
||||
if (branches) {
|
||||
const defaultBranches = branches.filter(b => b.defaultBranch);
|
||||
|
||||
if (defaultBranches.length > 0)
|
||||
this.setState({ selectedBranch: defaultBranches[0] });
|
||||
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
|
||||
}
|
||||
this.redirectToDefaultBranch();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
const {
|
||||
fetchSources,
|
||||
repository,
|
||||
revision,
|
||||
path,
|
||||
branches,
|
||||
baseUrl
|
||||
} = this.props;
|
||||
const { fetchSources, repository, revision, path } = this.props;
|
||||
if (prevProps.revision !== revision || prevProps.path !== path) {
|
||||
fetchSources(repository, revision, path);
|
||||
}
|
||||
|
||||
const currentUrl = this.props.location.pathname;
|
||||
this.redirectToDefaultBranch();
|
||||
}
|
||||
|
||||
if (
|
||||
branches &&
|
||||
(currentUrl.endsWith("sources") || currentUrl.endsWith("sources/"))
|
||||
) {
|
||||
redirectToDefaultBranch = () => {
|
||||
const { branches, baseUrl } = this.props;
|
||||
if (this.shouldRedirect()) {
|
||||
const defaultBranches = branches.filter(b => b.defaultBranch);
|
||||
|
||||
if (defaultBranches.length > 0)
|
||||
if (defaultBranches.length > 0) {
|
||||
this.setState({ selectedBranch: defaultBranches[0] });
|
||||
this.props.history.push(`${baseUrl}/${defaultBranches[0].name}/`);
|
||||
this.props.history.push(
|
||||
`${baseUrl}/${encodeURIComponent(defaultBranches[0].name)}/`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
shouldRedirect = () => {
|
||||
const { branches, revision } = this.props;
|
||||
return branches && !revision;
|
||||
};
|
||||
|
||||
branchSelected = (branch?: Branch) => {
|
||||
const { baseUrl, history, path } = this.props;
|
||||
|
||||
Reference in New Issue
Block a user