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