use reflow to migrate from flow to typescript

This commit is contained in:
Sebastian Sdorra
2019-10-19 16:38:07 +02:00
parent f7b8050dfa
commit 6e7a08a3bb
495 changed files with 14239 additions and 13766 deletions

View File

@@ -1,26 +0,0 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import type { File } from "@scm-manager/ui-types";
import { DownloadButton } from "@scm-manager/ui-components";
type Props = {
t: string => string,
file: File
};
class DownloadViewer extends React.Component<Props> {
render() {
const { t, file } = this.props;
return (
<div className="has-text-centered">
<DownloadButton
url={file._links.self.href}
displayName={t("sources.content.downloadButton")}
/>
</div>
);
}
}
export default translate("repos")(DownloadViewer);

View File

@@ -0,0 +1,25 @@
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;
file: File;
};
class DownloadViewer extends React.Component<Props> {
render() {
const { t, file } = this.props;
return (
<div className="has-text-centered">
<DownloadButton
url={file._links.self.href}
displayName={t('sources.content.downloadButton')}
/>
</div>
);
}
}
export default translate('repos')(DownloadViewer);

View File

@@ -1,13 +1,12 @@
// @flow
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,
t: string => string,
historyIsSelected: boolean,
showHistory: boolean => void
className?: string;
t: (p: string) => string;
historyIsSelected: boolean;
showHistory: (p: boolean) => void;
};
class FileButtonAddons extends React.Component<Props> {
@@ -20,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() {
@@ -28,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"
@@ -39,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"
@@ -55,4 +54,4 @@ class FileButtonAddons extends React.Component<Props> {
}
}
export default translate("repos")(FileButtonAddons);
export default translate('repos')(FileButtonAddons);

View File

@@ -1,11 +1,10 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import type { 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: string => string,
file: File
t: (p: string) => string;
file: File;
};
class ImageViewer extends React.Component<Props> {
@@ -21,4 +20,4 @@ class ImageViewer extends React.Component<Props> {
}
}
export default translate("repos")(ImageViewer);
export default translate('repos')(ImageViewer);

View File

@@ -1,33 +0,0 @@
//@flow
import fetchMock from "fetch-mock";
import {
getContent,
getLanguage
} from "./SourcecodeViewer";
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");
getContent(CONTENT_URL).then(content => {
expect(content).toBe("This is a testContent");
done();
});
});
});
describe("get correct language type", () => {
it("should return javascript", () => {
expect(getLanguage("JAVASCRIPT")).toBe("javascript");
});
it("should return nothing for plain text", () => {
expect(getLanguage("")).toBe("");
});
});

View File

@@ -0,0 +1,29 @@
import fetchMock from 'fetch-mock';
import { getContent, getLanguage } from './SourcecodeViewer';
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');
getContent(CONTENT_URL).then(content => {
expect(content).toBe('This is a testContent');
done();
});
});
});
describe('get correct language type', () => {
it('should return javascript', () => {
expect(getLanguage('JAVASCRIPT')).toBe('javascript');
});
it('should return nothing for plain text', () => {
expect(getLanguage('')).toBe('');
});
});

View File

@@ -1,20 +1,19 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { apiClient, SyntaxHighlighter } from "@scm-manager/ui-components";
import type { 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: string => string,
file: File,
language: string
t: (p: string) => string;
file: File;
language: string;
};
type State = {
content: string,
error?: Error,
loaded: boolean
content: string;
error?: Error;
loaded: boolean;
};
class SourcecodeViewer extends React.Component<Props, State> {
@@ -22,8 +21,8 @@ class SourcecodeViewer extends React.Component<Props, State> {
super(props);
this.state = {
content: "",
loaded: false
content: '',
loaded: false,
};
}
@@ -35,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,
});
}
})
@@ -65,10 +64,7 @@ class SourcecodeViewer extends React.Component<Props, State> {
}
return (
<SyntaxHighlighter
language={getLanguage(language)}
value= {content}
/>
<SyntaxHighlighter language={getLanguage(language)} value={content} />
);
}
}
@@ -85,8 +81,10 @@ export function getContent(url: string) {
return response;
})
.catch(err => {
return { error: err };
return {
error: err,
};
});
}
export default translate("repos")(SourcecodeViewer);
export default translate('repos')(SourcecodeViewer);