mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-08 22:45:45 +01:00
Merged in feature/editor_plugin_upload (pull request #306)
Feature editor plugin upload
This commit is contained in:
@@ -1,9 +1,16 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import type { Branch } from "@scm-manager/ui-types";
|
||||
import injectSheet from "react-jss";
|
||||
import { ExtensionPoint, binder } from "@scm-manager/ui-extensions";
|
||||
import {ButtonGroup} from "./buttons";
|
||||
import classNames from "classnames";
|
||||
|
||||
type Props = {
|
||||
branch: Branch,
|
||||
defaultBranch: Branch,
|
||||
branches: Branch[],
|
||||
revision: string,
|
||||
path: string,
|
||||
baseUrl: string,
|
||||
@@ -13,6 +20,17 @@ type Props = {
|
||||
const styles = {
|
||||
noMargin: {
|
||||
margin: "0"
|
||||
},
|
||||
flexRow: {
|
||||
display: "flex",
|
||||
flexDirection: "row"
|
||||
},
|
||||
flexStart: {
|
||||
flex: "1"
|
||||
},
|
||||
buttonGroup: {
|
||||
alignSelf: "center",
|
||||
paddingRight: "1rem"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,13 +63,32 @@ class Breadcrumb extends React.Component<Props> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
const { classes, baseUrl, branch, defaultBranch, branches, revision, path } = this.props;
|
||||
|
||||
return (
|
||||
<>
|
||||
<nav className="breadcrumb sources-breadcrumb" aria-label="breadcrumbs">
|
||||
<ul>{this.renderPath()}</ul>
|
||||
</nav>
|
||||
<div className={classes.flexRow}>
|
||||
<nav className={classNames(classes.flexStart, "breadcrumb sources-breadcrumb")} aria-label="breadcrumbs">
|
||||
<ul>{this.renderPath()}</ul>
|
||||
</nav>
|
||||
{
|
||||
binder.hasExtension("repos.sources.actionbar") &&
|
||||
<div className={classes.buttonGroup}>
|
||||
<ButtonGroup>
|
||||
<ExtensionPoint
|
||||
name="repos.sources.actionbar"
|
||||
props={{
|
||||
baseUrl,
|
||||
branch: branch ? branch : defaultBranch,
|
||||
path,
|
||||
isBranchUrl: branches &&
|
||||
branches.filter(b => b.name.replace("/", "%2F") === revision).length > 0 }}
|
||||
renderAll={true}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<hr className={classes.noMargin} />
|
||||
</>
|
||||
);
|
||||
|
||||
27
scm-ui-components/packages/ui-components/src/FileSize.js
Normal file
27
scm-ui-components/packages/ui-components/src/FileSize.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
|
||||
type Props = {
|
||||
bytes: number
|
||||
};
|
||||
|
||||
class FileSize extends React.Component<Props> {
|
||||
static format(bytes: number) {
|
||||
if (!bytes) {
|
||||
return "0 B";
|
||||
}
|
||||
|
||||
const units = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1000));
|
||||
|
||||
const size = i === 0 ? bytes : (bytes / 1000 ** i).toFixed(2);
|
||||
return `${size} ${units[i]}`;
|
||||
}
|
||||
|
||||
render() {
|
||||
const formattedBytes = FileSize.format(this.props.bytes);
|
||||
return <span>{formattedBytes}</span>;
|
||||
}
|
||||
}
|
||||
|
||||
export default FileSize;
|
||||
@@ -0,0 +1,10 @@
|
||||
import FileSize from "./FileSize";
|
||||
|
||||
it("should format bytes", () => {
|
||||
expect(FileSize.format(0)).toBe("0 B");
|
||||
expect(FileSize.format(160)).toBe("160 B");
|
||||
expect(FileSize.format(6304)).toBe("6.16 K");
|
||||
expect(FileSize.format(28792588)).toBe("27.46 M");
|
||||
expect(FileSize.format(1369510189)).toBe("1.28 G");
|
||||
expect(FileSize.format(42949672960)).toBe("40.00 G");
|
||||
});
|
||||
@@ -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,13 +46,24 @@ 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") {
|
||||
return this.httpRequestWithJSONBody("POST", url, contentType, payload);
|
||||
}
|
||||
|
||||
postBinary(url: string, fileAppender: FormData => void) {
|
||||
let formData = new FormData();
|
||||
fileAppender(formData);
|
||||
|
||||
let options: RequestOptions = {
|
||||
method: "POST",
|
||||
body: formData
|
||||
};
|
||||
return this.httpRequestWithBinaryBody(options, url);
|
||||
}
|
||||
|
||||
put(url: string, payload: any, contentType: string = "application/json") {
|
||||
return this.httpRequestWithJSONBody("PUT", url, contentType, payload);
|
||||
}
|
||||
@@ -62,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);
|
||||
}
|
||||
|
||||
@@ -70,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);
|
||||
}
|
||||
|
||||
@@ -84,9 +94,15 @@ class ApiClient {
|
||||
method: method,
|
||||
body: JSON.stringify(payload)
|
||||
};
|
||||
options = Object.assign(options, fetchOptions);
|
||||
// $FlowFixMe
|
||||
options.headers["Content-Type"] = contentType;
|
||||
return this.httpRequestWithBinaryBody(options, url, contentType);
|
||||
}
|
||||
|
||||
httpRequestWithBinaryBody(options: RequestOptions, url: string, contentType?: string) {
|
||||
options = applyFetchOptions(options);
|
||||
if (contentType) {
|
||||
// $FlowFixMe
|
||||
options.headers["Content-Type"] = contentType;
|
||||
}
|
||||
|
||||
return fetch(createUrl(url), options).then(handleFailure);
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user