mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
apply prettier, removed flow related config and added tsconfig
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { File } from '@scm-manager/ui-types';
|
||||
import React from "react";
|
||||
import { File } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
file: File;
|
||||
@@ -8,11 +8,11 @@ type Props = {
|
||||
class FileIcon extends React.Component<Props> {
|
||||
render() {
|
||||
const { file } = this.props;
|
||||
let icon = 'file';
|
||||
let icon = "file";
|
||||
if (file.subRepository) {
|
||||
icon = 'folder-plus';
|
||||
icon = "folder-plus";
|
||||
} else if (file.directory) {
|
||||
icon = 'folder';
|
||||
icon = "folder";
|
||||
}
|
||||
return <i className={`fa fa-${icon}`} />;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { findParent } from './FileTree';
|
||||
import { findParent } from "./FileTree";
|
||||
|
||||
describe('find parent tests', () => {
|
||||
it('should return the parent path', () => {
|
||||
expect(findParent('src/main/js/')).toBe('src/main');
|
||||
expect(findParent('src/main/js')).toBe('src/main');
|
||||
expect(findParent('src/main')).toBe('src');
|
||||
expect(findParent('src')).toBe('');
|
||||
describe("find parent tests", () => {
|
||||
it("should return the parent path", () => {
|
||||
expect(findParent("src/main/js/")).toBe("src/main");
|
||||
expect(findParent("src/main/js")).toBe("src/main");
|
||||
expect(findParent("src/main")).toBe("src");
|
||||
expect(findParent("src")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import React from 'react';
|
||||
import { compose } from 'redux';
|
||||
import { connect } from 'react-redux';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { translate } from 'react-i18next';
|
||||
import styled from 'styled-components';
|
||||
import { binder } from '@scm-manager/ui-extensions';
|
||||
import { Repository, File } from '@scm-manager/ui-types';
|
||||
import React from "react";
|
||||
import { compose } from "redux";
|
||||
import { connect } from "react-redux";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import { translate } from "react-i18next";
|
||||
import styled from "styled-components";
|
||||
import { binder } from "@scm-manager/ui-extensions";
|
||||
import { Repository, File } from "@scm-manager/ui-types";
|
||||
import {
|
||||
ErrorNotification,
|
||||
Loading,
|
||||
Notification,
|
||||
} from '@scm-manager/ui-components';
|
||||
Notification
|
||||
} from "@scm-manager/ui-components";
|
||||
import {
|
||||
getFetchSourcesFailure,
|
||||
isFetchSourcesPending,
|
||||
getSources,
|
||||
} from '../modules/sources';
|
||||
import FileTreeLeaf from './FileTreeLeaf';
|
||||
getSources
|
||||
} from "../modules/sources";
|
||||
import FileTreeLeaf from "./FileTreeLeaf";
|
||||
|
||||
type Props = {
|
||||
loading: boolean;
|
||||
@@ -37,15 +37,15 @@ const FixedWidthTh = styled.th`
|
||||
`;
|
||||
|
||||
export function findParent(path: string) {
|
||||
if (path.endsWith('/')) {
|
||||
if (path.endsWith("/")) {
|
||||
path = path.substring(0, path.length - 1);
|
||||
}
|
||||
|
||||
const index = path.lastIndexOf('/');
|
||||
const index = path.lastIndexOf("/");
|
||||
if (index > 0) {
|
||||
return path.substring(0, index);
|
||||
}
|
||||
return '';
|
||||
return "";
|
||||
}
|
||||
|
||||
class FileTree extends React.Component<Props> {
|
||||
@@ -73,9 +73,9 @@ class FileTree extends React.Component<Props> {
|
||||
|
||||
if (path) {
|
||||
files.push({
|
||||
name: '..',
|
||||
name: "..",
|
||||
path: findParent(path),
|
||||
directory: true,
|
||||
directory: true
|
||||
});
|
||||
}
|
||||
|
||||
@@ -102,9 +102,9 @@ class FileTree extends React.Component<Props> {
|
||||
if (files && files.length > 0) {
|
||||
let baseUrlWithRevision = baseUrl;
|
||||
if (revision) {
|
||||
baseUrlWithRevision += '/' + encodeURIComponent(revision);
|
||||
baseUrlWithRevision += "/" + encodeURIComponent(revision);
|
||||
} else {
|
||||
baseUrlWithRevision += '/' + encodeURIComponent(tree.revision);
|
||||
baseUrlWithRevision += "/" + encodeURIComponent(tree.revision);
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -112,17 +112,17 @@ class FileTree extends React.Component<Props> {
|
||||
<thead>
|
||||
<tr>
|
||||
<FixedWidthTh />
|
||||
<th>{t('sources.file-tree.name')}</th>
|
||||
<th>{t("sources.file-tree.name")}</th>
|
||||
<th className="is-hidden-mobile">
|
||||
{t('sources.file-tree.length')}
|
||||
{t("sources.file-tree.length")}
|
||||
</th>
|
||||
<th className="is-hidden-mobile">
|
||||
{t('sources.file-tree.lastModified')}
|
||||
{t("sources.file-tree.lastModified")}
|
||||
</th>
|
||||
<th className="is-hidden-mobile">
|
||||
{t('sources.file-tree.description')}
|
||||
{t("sources.file-tree.description")}
|
||||
</th>
|
||||
{binder.hasExtension('repos.sources.tree.row.right') && (
|
||||
{binder.hasExtension("repos.sources.tree.row.right") && (
|
||||
<th className="is-hidden-mobile" />
|
||||
)}
|
||||
</tr>
|
||||
@@ -139,7 +139,7 @@ class FileTree extends React.Component<Props> {
|
||||
</table>
|
||||
);
|
||||
}
|
||||
return <Notification type="info">{t('sources.noSources')}</Notification>;
|
||||
return <Notification type="info">{t("sources.noSources")}</Notification>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,11 +155,11 @@ const mapStateToProps = (state: any, ownProps: Props) => {
|
||||
path,
|
||||
loading,
|
||||
error,
|
||||
tree,
|
||||
tree
|
||||
};
|
||||
};
|
||||
|
||||
export default compose(
|
||||
withRouter,
|
||||
connect(mapStateToProps),
|
||||
)(translate('repos')(FileTree));
|
||||
connect(mapStateToProps)
|
||||
)(translate("repos")(FileTree));
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import { createLink } from './FileTreeLeaf';
|
||||
import { File } from '@scm-manager/ui-types';
|
||||
import { createLink } from "./FileTreeLeaf";
|
||||
import { File } from "@scm-manager/ui-types";
|
||||
|
||||
describe('create link tests', () => {
|
||||
describe("create link tests", () => {
|
||||
function dir(path: string): File {
|
||||
return {
|
||||
name: 'dir',
|
||||
name: "dir",
|
||||
path: path,
|
||||
directory: true,
|
||||
length: 1,
|
||||
revision: '1a',
|
||||
revision: "1a",
|
||||
_links: {},
|
||||
_embedded: {
|
||||
children: [],
|
||||
},
|
||||
children: []
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
it('should create link', () => {
|
||||
expect(createLink('src', dir('main'))).toBe('src/main/');
|
||||
expect(createLink('src', dir('/main'))).toBe('src/main/');
|
||||
expect(createLink('src', dir('/main/'))).toBe('src/main/');
|
||||
it("should create link", () => {
|
||||
expect(createLink("src", dir("main"))).toBe("src/main/");
|
||||
expect(createLink("src", dir("/main"))).toBe("src/main/");
|
||||
expect(createLink("src", dir("/main/"))).toBe("src/main/");
|
||||
});
|
||||
|
||||
it('should return base url if the directory path is empty', () => {
|
||||
expect(createLink('src', dir(''))).toBe('src/');
|
||||
it("should return base url if the directory path is empty", () => {
|
||||
expect(createLink("src", dir(""))).toBe("src/");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import * as React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import classNames from 'classnames';
|
||||
import styled from 'styled-components';
|
||||
import { binder, ExtensionPoint } from '@scm-manager/ui-extensions';
|
||||
import { File } from '@scm-manager/ui-types';
|
||||
import { DateFromNow, FileSize } from '@scm-manager/ui-components';
|
||||
import FileIcon from './FileIcon';
|
||||
import * as React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import classNames from "classnames";
|
||||
import styled from "styled-components";
|
||||
import { binder, ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import { File } from "@scm-manager/ui-types";
|
||||
import { DateFromNow, FileSize } from "@scm-manager/ui-components";
|
||||
import FileIcon from "./FileIcon";
|
||||
|
||||
type Props = {
|
||||
file: File;
|
||||
@@ -20,13 +20,13 @@ export function createLink(base: string, file: File) {
|
||||
let link = base;
|
||||
if (file.path) {
|
||||
let path = file.path;
|
||||
if (path.startsWith('/')) {
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
link += '/' + path;
|
||||
link += "/" + path;
|
||||
}
|
||||
if (!link.endsWith('/')) {
|
||||
link += '/';
|
||||
if (!link.endsWith("/")) {
|
||||
link += "/";
|
||||
}
|
||||
return link;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ export default class FileTreeLeaf extends React.Component<Props> {
|
||||
render() {
|
||||
const { file } = this.props;
|
||||
|
||||
const fileSize = file.directory ? '' : <FileSize bytes={file.length} />;
|
||||
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
|
||||
|
||||
return (
|
||||
<tr>
|
||||
@@ -73,16 +73,16 @@ export default class FileTreeLeaf extends React.Component<Props> {
|
||||
<td className="is-hidden-mobile">
|
||||
<DateFromNow date={file.lastModified} />
|
||||
</td>
|
||||
<MinWidthTd className={classNames('is-word-break', 'is-hidden-mobile')}>
|
||||
<MinWidthTd className={classNames("is-word-break", "is-hidden-mobile")}>
|
||||
{file.description}
|
||||
</MinWidthTd>
|
||||
{binder.hasExtension('repos.sources.tree.row.right') && (
|
||||
{binder.hasExtension("repos.sources.tree.row.right") && (
|
||||
<td className="is-hidden-mobile">
|
||||
{!file.directory && (
|
||||
<ExtensionPoint
|
||||
name="repos.sources.tree.row.right"
|
||||
props={{
|
||||
file,
|
||||
file
|
||||
}}
|
||||
renderAll={true}
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { File } from '@scm-manager/ui-types';
|
||||
import { DownloadButton } from '@scm-manager/ui-components';
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { File } from "@scm-manager/ui-types";
|
||||
import { DownloadButton } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
t: (p: string) => string;
|
||||
@@ -15,11 +15,11 @@ class DownloadViewer extends React.Component<Props> {
|
||||
<div className="has-text-centered">
|
||||
<DownloadButton
|
||||
url={file._links.self.href}
|
||||
displayName={t('sources.content.downloadButton')}
|
||||
displayName={t("sources.content.downloadButton")}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default translate('repos')(DownloadViewer);
|
||||
export default translate("repos")(DownloadViewer);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { ButtonAddons, Button } from '@scm-manager/ui-components';
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { ButtonAddons, Button } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
className?: string;
|
||||
@@ -19,7 +19,7 @@ class FileButtonAddons extends React.Component<Props> {
|
||||
};
|
||||
|
||||
color = (selected: boolean) => {
|
||||
return selected ? 'link is-selected' : null;
|
||||
return selected ? "link is-selected" : null;
|
||||
};
|
||||
|
||||
render() {
|
||||
@@ -27,7 +27,7 @@ class FileButtonAddons extends React.Component<Props> {
|
||||
|
||||
return (
|
||||
<ButtonAddons className={className}>
|
||||
<div title={t('sources.content.sourcesButton')}>
|
||||
<div title={t("sources.content.sourcesButton")}>
|
||||
<Button
|
||||
action={this.showSources}
|
||||
className="reduced"
|
||||
@@ -38,7 +38,7 @@ class FileButtonAddons extends React.Component<Props> {
|
||||
</span>
|
||||
</Button>
|
||||
</div>
|
||||
<div title={t('sources.content.historyButton')}>
|
||||
<div title={t("sources.content.historyButton")}>
|
||||
<Button
|
||||
action={this.showHistory}
|
||||
className="reduced"
|
||||
@@ -54,4 +54,4 @@ class FileButtonAddons extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate('repos')(FileButtonAddons);
|
||||
export default translate("repos")(FileButtonAddons);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { File } from '@scm-manager/ui-types';
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { File } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
t: (p: string) => string;
|
||||
@@ -20,4 +20,4 @@ class ImageViewer extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
export default translate('repos')(ImageViewer);
|
||||
export default translate("repos")(ImageViewer);
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import fetchMock from 'fetch-mock';
|
||||
import { getContent, getLanguage } from './SourcecodeViewer';
|
||||
import fetchMock from "fetch-mock";
|
||||
import { getContent, getLanguage } from "./SourcecodeViewer";
|
||||
|
||||
describe('get content', () => {
|
||||
const CONTENT_URL = '/repositories/scmadmin/TestRepo/content/testContent';
|
||||
describe("get content", () => {
|
||||
const CONTENT_URL = "/repositories/scmadmin/TestRepo/content/testContent";
|
||||
|
||||
afterEach(() => {
|
||||
fetchMock.reset();
|
||||
fetchMock.restore();
|
||||
});
|
||||
|
||||
it('should return content', done => {
|
||||
fetchMock.getOnce('/api/v2' + CONTENT_URL, 'This is a testContent');
|
||||
it("should return content", done => {
|
||||
fetchMock.getOnce("/api/v2" + CONTENT_URL, "This is a testContent");
|
||||
|
||||
getContent(CONTENT_URL).then(content => {
|
||||
expect(content).toBe('This is a testContent');
|
||||
expect(content).toBe("This is a testContent");
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('get correct language type', () => {
|
||||
it('should return javascript', () => {
|
||||
expect(getLanguage('JAVASCRIPT')).toBe('javascript');
|
||||
describe("get correct language type", () => {
|
||||
it("should return javascript", () => {
|
||||
expect(getLanguage("JAVASCRIPT")).toBe("javascript");
|
||||
});
|
||||
it('should return nothing for plain text', () => {
|
||||
expect(getLanguage('')).toBe('');
|
||||
it("should return nothing for plain text", () => {
|
||||
expect(getLanguage("")).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import React from 'react';
|
||||
import { translate } from 'react-i18next';
|
||||
import { apiClient, SyntaxHighlighter } from '@scm-manager/ui-components';
|
||||
import { File } from '@scm-manager/ui-types';
|
||||
import { ErrorNotification, Loading } from '@scm-manager/ui-components';
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { apiClient, SyntaxHighlighter } from "@scm-manager/ui-components";
|
||||
import { File } from "@scm-manager/ui-types";
|
||||
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
t: (p: string) => string;
|
||||
@@ -21,8 +21,8 @@ class SourcecodeViewer extends React.Component<Props, State> {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
content: '',
|
||||
loaded: false,
|
||||
content: "",
|
||||
loaded: false
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ class SourcecodeViewer extends React.Component<Props, State> {
|
||||
this.setState({
|
||||
...this.state,
|
||||
error: result.error,
|
||||
loaded: true,
|
||||
loaded: true
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
...this.state,
|
||||
content: result,
|
||||
loaded: true,
|
||||
loaded: true
|
||||
});
|
||||
}
|
||||
})
|
||||
@@ -82,9 +82,9 @@ export function getContent(url: string) {
|
||||
})
|
||||
.catch(err => {
|
||||
return {
|
||||
error: err,
|
||||
error: err
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default translate('repos')(SourcecodeViewer);
|
||||
export default translate("repos")(SourcecodeViewer);
|
||||
|
||||
Reference in New Issue
Block a user