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,19 +1,18 @@
// @flow
import React from "react";
import type { File } from "@scm-manager/ui-types";
import React from 'react';
import { File } from '@scm-manager/ui-types';
type Props = {
file: File
file: File;
};
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}`} />;
}

View File

@@ -1,12 +0,0 @@
// @flow
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("");
});
});

View File

@@ -0,0 +1,10 @@
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('');
});
});

View File

@@ -1,36 +1,35 @@
//@flow
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 type { 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,
error: Error,
tree: File,
repository: Repository,
revision: string,
path: string,
baseUrl: string,
loading: boolean;
error: Error;
tree: File;
repository: Repository;
revision: string;
path: string;
baseUrl: string;
// context props
t: string => string,
match: any
t: (p: string) => string;
match: any;
};
const FixedWidthTh = styled.th`
@@ -38,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> {
@@ -74,9 +73,9 @@ class FileTree extends React.Component<Props> {
if (path) {
files.push({
name: "..",
name: '..',
path: findParent(path),
directory: true
directory: true,
});
}
@@ -103,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 (
@@ -113,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>
@@ -140,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>;
}
}
@@ -156,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));

View File

@@ -1,30 +0,0 @@
// @flow
import { createLink } from "./FileTreeLeaf";
import type { File } from "@scm-manager/ui-types";
describe("create link tests", () => {
function dir(path: string): File {
return {
name: "dir",
path: path,
directory: true,
length: 1,
revision: "1a",
_links: {},
_embedded: {
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 return base url if the directory path is empty", () => {
expect(createLink("src", dir(""))).toBe("src/");
});
});

View File

@@ -0,0 +1,28 @@
import { createLink } from './FileTreeLeaf';
import { File } from '@scm-manager/ui-types';
describe('create link tests', () => {
function dir(path: string): File {
return {
name: 'dir',
path: path,
directory: true,
length: 1,
revision: '1a',
_links: {},
_embedded: {
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 return base url if the directory path is empty', () => {
expect(createLink('src', dir(''))).toBe('src/');
});
});

View File

@@ -1,16 +1,15 @@
//@flow
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 type { 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,
baseUrl: string
file: File;
baseUrl: string;
};
const MinWidthTd = styled.td`
@@ -21,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;
}
@@ -62,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>
@@ -74,15 +73,17 @@ 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 }}
props={{
file,
}}
renderAll={true}
/>
)}

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);

View File

@@ -1,32 +1,36 @@
// @flow
import React from "react";
import {connect} from "react-redux";
import {translate} from "react-i18next";
import classNames from "classnames";
import styled from "styled-components";
import {ExtensionPoint} from "@scm-manager/ui-extensions";
import type {File, Repository} from "@scm-manager/ui-types";
import {DateFromNow, ErrorNotification, FileSize, Icon} from "@scm-manager/ui-components";
import {getSources} from "../modules/sources";
import FileButtonAddons from "../components/content/FileButtonAddons";
import SourcesView from "./SourcesView";
import HistoryView from "./HistoryView";
import React from 'react';
import { connect } from 'react-redux';
import { translate } from 'react-i18next';
import classNames from 'classnames';
import styled from 'styled-components';
import { ExtensionPoint } from '@scm-manager/ui-extensions';
import { File, Repository } from '@scm-manager/ui-types';
import {
DateFromNow,
ErrorNotification,
FileSize,
Icon,
} from '@scm-manager/ui-components';
import { getSources } from '../modules/sources';
import FileButtonAddons from '../components/content/FileButtonAddons';
import SourcesView from './SourcesView';
import HistoryView from './HistoryView';
type Props = {
loading: boolean,
file: File,
repository: Repository,
revision: string,
path: string,
loading: boolean;
file: File;
repository: Repository;
revision: string;
path: string;
// context props
t: string => string
t: (p: string) => string;
};
type State = {
collapsed: boolean,
showHistory: boolean,
errorFromExtension?: Error
collapsed: boolean;
showHistory: boolean;
errorFromExtension?: Error;
};
const VCenteredChild = styled.div`
@@ -55,31 +59,33 @@ class Content extends React.Component<Props, State> {
this.state = {
collapsed: true,
showHistory: false
showHistory: false,
};
}
toggleCollapse = () => {
this.setState(prevState => ({
collapsed: !prevState.collapsed
collapsed: !prevState.collapsed,
}));
};
setShowHistoryState(showHistory: boolean) {
this.setState({
...this.state,
showHistory
showHistory,
});
}
handleExtensionError = (error: Error) => {
this.setState({ errorFromExtension: error });
this.setState({
errorFromExtension: error,
});
};
showHeader() {
const { file, revision } = this.props;
const { showHistory, collapsed } = this.state;
const icon = collapsed ? "angle-right" : "angle-down";
const icon = collapsed ? 'angle-right' : 'angle-down';
const selector = file._links.history ? (
<RightMarginFileButtonAddons
@@ -93,7 +99,7 @@ class Content extends React.Component<Props, State> {
return (
<span className="has-cursor-pointer">
<VCenteredChild className={classNames("media", "is-flex")}>
<VCenteredChild className={classNames('media', 'is-flex')}>
<div className="media-content" onClick={this.toggleCollapse}>
<RightMarginIcon name={icon} color="inherit" />
<span className="is-word-break">{file.name}</span>
@@ -105,7 +111,7 @@ class Content extends React.Component<Props, State> {
props={{
file,
revision,
handleExtensionError: this.handleExtensionError
handleExtensionError: this.handleExtensionError,
}}
renderAll={true}
/>
@@ -121,7 +127,7 @@ class Content extends React.Component<Props, State> {
const date = <DateFromNow date={file.lastModified} />;
const description = file.description ? (
<p>
{file.description.split("\n").map((item, key) => {
{file.description.split('\n').map((item, key) => {
return (
<span key={key}>
{item}
@@ -131,36 +137,40 @@ class Content extends React.Component<Props, State> {
})}
</p>
) : null;
const fileSize = file.directory ? "" : <FileSize bytes={file.length} />;
const fileSize = file.directory ? '' : <FileSize bytes={file.length} />;
if (!collapsed) {
return (
<LighterGreyBackgroundPanelBlock className="panel-block">
<LighterGreyBackgroundTable className="table">
<tbody>
<tr>
<td>{t("sources.content.path")}</td>
<td>{t('sources.content.path')}</td>
<td className="is-word-break">{file.path}</td>
</tr>
<tr>
<td>{t("sources.content.branch")}</td>
<td>{t('sources.content.branch')}</td>
<td className="is-word-break">{revision}</td>
</tr>
<tr>
<td>{t("sources.content.size")}</td>
<td>{t('sources.content.size')}</td>
<td>{fileSize}</td>
</tr>
<tr>
<td>{t("sources.content.lastModified")}</td>
<td>{t('sources.content.lastModified')}</td>
<td>{date}</td>
</tr>
<tr>
<td>{t("sources.content.description")}</td>
<td>{t('sources.content.description')}</td>
<td className="is-word-break">{description}</td>
</tr>
<ExtensionPoint
name="repos.content.metadata"
renderAll={true}
props={{ file, repository, revision }}
props={{
file,
repository,
revision,
}}
/>
</tbody>
</LighterGreyBackgroundTable>
@@ -207,8 +217,8 @@ const mapStateToProps = (state: any, ownProps: Props) => {
const file = getSources(state, repository, revision, path);
return {
file
file,
};
};
export default connect(mapStateToProps)(translate("repos")(Content));
export default connect(mapStateToProps)(translate('repos')(Content));

View File

@@ -1,30 +1,29 @@
// @flow
import React from "react";
import type {
import React from 'react';
import {
File,
Changeset,
Repository,
PagedCollection
} from "@scm-manager/ui-types";
PagedCollection,
} from '@scm-manager/ui-types';
import {
ErrorNotification,
Loading,
StatePaginator,
ChangesetList
} from "@scm-manager/ui-components";
import { getHistory } from "./history";
ChangesetList,
} from '@scm-manager/ui-components';
import { getHistory } from './history';
type Props = {
file: File,
repository: Repository
file: File;
repository: Repository;
};
type State = {
loaded: boolean,
changesets: Changeset[],
page: number,
pageCollection?: PagedCollection,
error?: Error
loaded: boolean;
changesets: Changeset[];
page: number;
pageCollection?: PagedCollection;
error?: Error;
};
class HistoryView extends React.Component<Props, State> {
@@ -34,7 +33,7 @@ class HistoryView extends React.Component<Props, State> {
this.state = {
loaded: false,
page: 1,
changesets: []
changesets: [],
};
}
@@ -50,7 +49,7 @@ class HistoryView extends React.Component<Props, State> {
this.setState({
...this.state,
error: result.error,
loaded: true
loaded: true,
});
} else {
this.setState({
@@ -58,7 +57,7 @@ class HistoryView extends React.Component<Props, State> {
loaded: true,
changesets: result.changesets,
pageCollection: result.pageCollection,
page: result.pageCollection.page
page: result.pageCollection.page,
});
}
})
@@ -69,7 +68,7 @@ class HistoryView extends React.Component<Props, State> {
const { file } = this.props;
const internalPage = page - 1;
this.updateHistory(
file._links.history.href + "?page=" + internalPage.toString()
file._links.history.href + '?page=' + internalPage.toString(),
);
}

View File

@@ -1,49 +1,48 @@
// @flow
import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import type { Branch, Repository } from "@scm-manager/ui-types";
import FileTree from "../components/FileTree";
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { Branch, Repository } from '@scm-manager/ui-types';
import FileTree from '../components/FileTree';
import {
BranchSelector,
Breadcrumb,
ErrorNotification,
Loading
} from "@scm-manager/ui-components";
import { translate } from "react-i18next";
Loading,
} from '@scm-manager/ui-components';
import { translate } from 'react-i18next';
import {
fetchBranches,
getBranches,
getFetchBranchesFailure,
isFetchBranchesPending
} from "../../branches/modules/branches";
import { compose } from "redux";
import Content from "./Content";
import { fetchSources, isDirectory } from "../modules/sources";
isFetchBranchesPending,
} from '../../branches/modules/branches';
import { compose } from 'redux';
import Content from './Content';
import { fetchSources, isDirectory } from '../modules/sources';
type Props = {
repository: Repository,
loading: boolean,
error: Error,
baseUrl: string,
branches: Branch[],
revision: string,
path: string,
currentFileIsDirectory: boolean,
repository: Repository;
loading: boolean;
error: Error;
baseUrl: string;
branches: Branch[];
revision: string;
path: string;
currentFileIsDirectory: boolean;
// dispatch props
fetchBranches: Repository => void,
fetchSources: (Repository, string, string) => void,
fetchBranches: (p: Repository) => void;
fetchSources: (p1: Repository, p2: string, p3: string) => void;
// Context props
history: any,
match: any,
location: any,
t: string => string
history: any;
match: any;
location: any;
t: (p: string) => string;
};
type State = {
selectedBranch: any
selectedBranch: any;
};
class Sources extends React.Component<Props, State> {
@@ -51,7 +50,7 @@ class Sources extends React.Component<Props, State> {
super(props);
this.state = {
selectedBranch: null
selectedBranch: null,
};
}
@@ -61,7 +60,7 @@ class Sources extends React.Component<Props, State> {
repository,
revision,
path,
fetchSources
fetchSources,
} = this.props;
fetchBranches(repository);
@@ -99,14 +98,18 @@ class Sources extends React.Component<Props, State> {
const { baseUrl, history, path } = this.props;
let url;
if (branch) {
this.setState({ selectedBranch: branch });
this.setState({
selectedBranch: branch,
});
if (path) {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/${path}`;
} else {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/`;
}
} else {
this.setState({ selectedBranch: null });
this.setState({
selectedBranch: null,
});
url = `${baseUrl}/`;
}
history.push(url);
@@ -120,7 +123,7 @@ class Sources extends React.Component<Props, State> {
error,
revision,
path,
currentFileIsDirectory
currentFileIsDirectory,
} = this.props;
if (error) {
@@ -160,7 +163,7 @@ class Sources extends React.Component<Props, State> {
<BranchSelector
branches={branches}
selectedBranch={revision}
label={t("changesets.branchSelectorLabel")}
label={t('changesets.branchSelectorLabel')}
selected={(b: Branch) => {
this.branchSelected(b);
}}
@@ -212,7 +215,7 @@ const mapStateToProps = (state, ownProps) => {
loading,
error,
branches,
currentFileIsDirectory
currentFileIsDirectory,
};
};
@@ -223,15 +226,15 @@ const mapDispatchToProps = dispatch => {
},
fetchSources: (repository: Repository, revision: string, path: string) => {
dispatch(fetchSources(repository, revision, path));
}
},
};
};
export default compose(
translate("repos"),
translate('repos'),
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
mapDispatchToProps,
),
)(Sources);

View File

@@ -1,26 +1,25 @@
// @flow
import React from "react";
import React from 'react';
import SourcecodeViewer from "../components/content/SourcecodeViewer";
import ImageViewer from "../components/content/ImageViewer";
import DownloadViewer from "../components/content/DownloadViewer";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import { getContentType } from "./contentType";
import type { File, Repository } from "@scm-manager/ui-types";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
import SourcecodeViewer from '../components/content/SourcecodeViewer';
import ImageViewer from '../components/content/ImageViewer';
import DownloadViewer from '../components/content/DownloadViewer';
import { ExtensionPoint } from '@scm-manager/ui-extensions';
import { getContentType } from './contentType';
import { File, Repository } from '@scm-manager/ui-types';
import { ErrorNotification, Loading } from '@scm-manager/ui-components';
type Props = {
repository: Repository,
file: File,
revision: string,
path: string
repository: Repository;
file: File;
revision: string;
path: string;
};
type State = {
contentType: string,
language: string,
loaded: boolean,
error?: Error
contentType: string;
language: string;
loaded: boolean;
error?: Error;
};
class SourcesView extends React.Component<Props, State> {
@@ -28,9 +27,9 @@ class SourcesView extends React.Component<Props, State> {
super(props);
this.state = {
contentType: "",
language: "",
loaded: false
contentType: '',
language: '',
loaded: false,
};
}
@@ -42,14 +41,14 @@ class SourcesView extends React.Component<Props, State> {
this.setState({
...this.state,
error: result.error,
loaded: true
loaded: true,
});
} else {
this.setState({
...this.state,
contentType: result.type,
language: result.language,
loaded: true
loaded: true,
});
}
})
@@ -59,17 +58,21 @@ class SourcesView extends React.Component<Props, State> {
showSources() {
const { file, revision } = this.props;
const { contentType, language } = this.state;
if (contentType.startsWith("image/")) {
if (contentType.startsWith('image/')) {
return <ImageViewer file={file} />;
} else if (language) {
return <SourcecodeViewer file={file} language={language} />;
} else if (contentType.startsWith("text/")) {
} else if (contentType.startsWith('text/')) {
return <SourcecodeViewer file={file} language="none" />;
} else {
return (
<ExtensionPoint
name="repos.sources.view"
props={{ file, contentType, revision }}
props={{
file,
contentType,
revision,
}}
>
<DownloadViewer file={file} />
</ExtensionPoint>

View File

@@ -1,16 +0,0 @@
//@flow
import { apiClient } from "@scm-manager/ui-components";
export function getContentType(url: string) {
return apiClient
.head(url)
.then(response => {
return {
type: response.headers.get("Content-Type"),
language: response.headers.get("X-Programming-Language")
};
})
.catch(err => {
return { error: err };
});
}

View File

@@ -1,29 +0,0 @@
//@flow
import fetchMock from "fetch-mock";
import { getContentType } from "./contentType";
describe("get content type", () => {
const CONTENT_URL = "/repositories/scmadmin/TestRepo/content/testContent";
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it("should return content", done => {
let headers = {
"Content-Type": "application/text",
"X-Programming-Language": "JAVA"
};
fetchMock.head("/api/v2" + CONTENT_URL, {
headers
});
getContentType(CONTENT_URL).then(content => {
expect(content.type).toBe("application/text");
expect(content.language).toBe("JAVA");
done();
});
});
});

View File

@@ -0,0 +1,28 @@
import fetchMock from 'fetch-mock';
import { getContentType } from './contentType';
describe('get content type', () => {
const CONTENT_URL = '/repositories/scmadmin/TestRepo/content/testContent';
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it('should return content', done => {
let headers = {
'Content-Type': 'application/text',
'X-Programming-Language': 'JAVA',
};
fetchMock.head('/api/v2' + CONTENT_URL, {
headers,
});
getContentType(CONTENT_URL).then(content => {
expect(content.type).toBe('application/text');
expect(content.language).toBe('JAVA');
done();
});
});
});

View File

@@ -0,0 +1,17 @@
import { apiClient } from '@scm-manager/ui-components';
export function getContentType(url: string) {
return apiClient
.head(url)
.then(response => {
return {
type: response.headers.get('Content-Type'),
language: response.headers.get('X-Programming-Language'),
};
})
.catch(err => {
return {
error: err,
};
});
}

View File

@@ -1,53 +0,0 @@
//@flow
import fetchMock from "fetch-mock";
import { getHistory } from "./history";
describe("get content type", () => {
const FILE_URL = "/repositories/scmadmin/TestRepo/history/file";
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
const history = {
page: 0,
pageTotal: 10,
_links: {
self: {
href: "/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10"
},
first: {
href: "/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10"
},
next: {
href: "/repositories/scmadmin/TestRepo/history/file?page=1&pageSize=10"
},
last: {
href: "/repositories/scmadmin/TestRepo/history/file?page=9&pageSize=10"
}
},
_embedded: {
changesets: [
{
id: "1234"
},
{
id: "2345"
}
]
}
};
it("should return history", done => {
fetchMock.get("/api/v2" + FILE_URL, history);
getHistory(FILE_URL).then(content => {
expect(content.changesets).toEqual(history._embedded.changesets);
expect(content.pageCollection.page).toEqual(history.page);
expect(content.pageCollection.pageTotal).toEqual(history.pageTotal);
expect(content.pageCollection._links).toEqual(history._links);
done();
});
});
});

View File

@@ -0,0 +1,52 @@
import fetchMock from 'fetch-mock';
import { getHistory } from './history';
describe('get content type', () => {
const FILE_URL = '/repositories/scmadmin/TestRepo/history/file';
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
const history = {
page: 0,
pageTotal: 10,
_links: {
self: {
href: '/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10',
},
first: {
href: '/repositories/scmadmin/TestRepo/history/file?page=0&pageSize=10',
},
next: {
href: '/repositories/scmadmin/TestRepo/history/file?page=1&pageSize=10',
},
last: {
href: '/repositories/scmadmin/TestRepo/history/file?page=9&pageSize=10',
},
},
_embedded: {
changesets: [
{
id: '1234',
},
{
id: '2345',
},
],
},
};
it('should return history', done => {
fetchMock.get('/api/v2' + FILE_URL, history);
getHistory(FILE_URL).then(content => {
expect(content.changesets).toEqual(history._embedded.changesets);
expect(content.pageCollection.page).toEqual(history.page);
expect(content.pageCollection.pageTotal).toEqual(history.pageTotal);
expect(content.pageCollection._links).toEqual(history._links);
done();
});
});
});

View File

@@ -1,5 +1,4 @@
//@flow
import { apiClient } from "@scm-manager/ui-components";
import { apiClient } from '@scm-manager/ui-components';
export function getHistory(url: string) {
return apiClient
@@ -12,11 +11,13 @@ export function getHistory(url: string) {
_embedded: result._embedded,
_links: result._links,
page: result.page,
pageTotal: result.pageTotal
}
pageTotal: result.pageTotal,
},
};
})
.catch(err => {
return { error: err };
return {
error: err,
};
});
}

View File

@@ -1,274 +0,0 @@
// @flow
import type { Repository, File } from "@scm-manager/ui-types";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import fetchMock from "fetch-mock";
import {
FETCH_SOURCES,
FETCH_SOURCES_FAILURE,
FETCH_SOURCES_PENDING,
FETCH_SOURCES_SUCCESS,
fetchSources,
getFetchSourcesFailure,
isFetchSourcesPending,
default as reducer,
getSources,
fetchSourcesSuccess,
isDirectory
} from "./sources";
const sourcesUrl =
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/";
const repository: Repository = {
name: "core",
namespace: "scm",
type: "git",
_links: {
sources: {
href: sourcesUrl
}
}
};
const collection = {
name: "src",
path: "src",
directory: true,
description: "foo",
length: 176,
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
subRepository: undefined,
_links: {
self: {
href:
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/"
}
},
_embedded: {
children: [
{
name: "src",
path: "src",
directory: true,
description: "",
length: 176,
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
lastModified: "",
subRepository: undefined,
_links: {
self: {
href:
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src"
}
},
_embedded: {
children: []
}
},
{
name: "package.json",
path: "package.json",
directory: false,
description: "bump version",
length: 780,
revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4",
lastModified: "2017-07-31T11:17:19Z",
subRepository: undefined,
_links: {
self: {
href:
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/content/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json"
},
history: {
href:
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/history/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json"
}
},
_embedded: {
children: []
}
}
]
}
};
const noDirectory: File = {
name: "src",
path: "src",
directory: true,
length: 176,
revision: "abc",
_links: {
self: {
href:
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src"
}
},
_embedded: {
children: []
}
};
describe("sources fetch", () => {
const mockStore = configureMockStore([thunk]);
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it("should fetch the sources of the repository", () => {
fetchMock.getOnce(sourcesUrl, collection);
const expectedActions = [
{ type: FETCH_SOURCES_PENDING, itemId: "scm/core/_/" },
{
type: FETCH_SOURCES_SUCCESS,
itemId: "scm/core/_/",
payload: collection
}
];
const store = mockStore({});
return store.dispatch(fetchSources(repository, "", "")).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it("should fetch the sources of the repository with the given revision and path", () => {
fetchMock.getOnce(sourcesUrl + "abc/src", collection);
const expectedActions = [
{ type: FETCH_SOURCES_PENDING, itemId: "scm/core/abc/src" },
{
type: FETCH_SOURCES_SUCCESS,
itemId: "scm/core/abc/src",
payload: collection
}
];
const store = mockStore({});
return store.dispatch(fetchSources(repository, "abc", "src")).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it("should dispatch FETCH_SOURCES_FAILURE on server error", () => {
fetchMock.getOnce(sourcesUrl, {
status: 500
});
const store = mockStore({});
return store.dispatch(fetchSources(repository, "", "")).then(() => {
const actions = store.getActions();
expect(actions[0].type).toBe(FETCH_SOURCES_PENDING);
expect(actions[1].type).toBe(FETCH_SOURCES_FAILURE);
expect(actions[1].itemId).toBe("scm/core/_/");
expect(actions[1].payload).toBeDefined();
});
});
});
describe("reducer tests", () => {
it("should return unmodified state on unknown action", () => {
const state = {};
expect(reducer(state)).toBe(state);
});
it("should store the collection, without revision and path", () => {
const expectedState = {
"scm/core/_/": collection
};
expect(
reducer({}, fetchSourcesSuccess(repository, "", "", collection))
).toEqual(expectedState);
});
it("should store the collection, with revision and path", () => {
const expectedState = {
"scm/core/abc/src/main": collection
};
expect(
reducer(
{},
fetchSourcesSuccess(repository, "abc", "src/main", collection)
)
).toEqual(expectedState);
});
});
describe("selector tests", () => {
it("should return false if it is no directory", () => {
const state = {
sources: {
"scm/core/abc/src/main/package.json": {
noDirectory
}
}
};
expect(
isDirectory(state, repository, "abc", "src/main/package.json")
).toBeFalsy();
});
it("should return true if it is directory", () => {
const state = {
sources: {
"scm/core/abc/src": noDirectory
}
};
expect(isDirectory(state, repository, "abc", "src")).toBe(true);
});
it("should return null", () => {
expect(getSources({}, repository, "", "")).toBeFalsy();
});
it("should return the source collection without revision and path", () => {
const state = {
sources: {
"scm/core/_/": collection
}
};
expect(getSources(state, repository, "", "")).toBe(collection);
});
it("should return the source collection with revision and path", () => {
const state = {
sources: {
"scm/core/abc/src/main": collection
}
};
expect(getSources(state, repository, "abc", "src/main")).toBe(collection);
});
it("should return true, when fetch sources is pending", () => {
const state = {
pending: {
[FETCH_SOURCES + "/scm/core/_/"]: true
}
};
expect(isFetchSourcesPending(state, repository, "", "")).toEqual(true);
});
it("should return false, when fetch sources is not pending", () => {
expect(isFetchSourcesPending({}, repository, "", "")).toEqual(false);
});
const error = new Error("incredible error from hell");
it("should return error when fetch sources did fail", () => {
const state = {
failure: {
[FETCH_SOURCES + "/scm/core/_/"]: error
}
};
expect(getFetchSourcesFailure(state, repository, "", "")).toEqual(error);
});
it("should return undefined when fetch sources did not fail", () => {
expect(getFetchSourcesFailure({}, repository, "", "")).toBe(undefined);
});
});

View File

@@ -0,0 +1,278 @@
import { Repository, File } from '@scm-manager/ui-types';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import fetchMock from 'fetch-mock';
import {
FETCH_SOURCES,
FETCH_SOURCES_FAILURE,
FETCH_SOURCES_PENDING,
FETCH_SOURCES_SUCCESS,
fetchSources,
getFetchSourcesFailure,
isFetchSourcesPending,
default as reducer,
getSources,
fetchSourcesSuccess,
isDirectory,
} from './sources';
const sourcesUrl =
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/';
const repository: Repository = {
name: 'core',
namespace: 'scm',
type: 'git',
_links: {
sources: {
href: sourcesUrl,
},
},
};
const collection = {
name: 'src',
path: 'src',
directory: true,
description: 'foo',
length: 176,
revision: '76aae4bb4ceacf0e88938eb5b6832738b7d537b4',
subRepository: undefined,
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/',
},
},
_embedded: {
children: [
{
name: 'src',
path: 'src',
directory: true,
description: '',
length: 176,
revision: '76aae4bb4ceacf0e88938eb5b6832738b7d537b4',
lastModified: '',
subRepository: undefined,
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src',
},
},
_embedded: {
children: [],
},
},
{
name: 'package.json',
path: 'package.json',
directory: false,
description: 'bump version',
length: 780,
revision: '76aae4bb4ceacf0e88938eb5b6832738b7d537b4',
lastModified: '2017-07-31T11:17:19Z',
subRepository: undefined,
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/content/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json',
},
history: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/history/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json',
},
},
_embedded: {
children: [],
},
},
],
},
};
const noDirectory: File = {
name: 'src',
path: 'src',
directory: true,
length: 176,
revision: 'abc',
_links: {
self: {
href:
'http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src',
},
},
_embedded: {
children: [],
},
};
describe('sources fetch', () => {
const mockStore = configureMockStore([thunk]);
afterEach(() => {
fetchMock.reset();
fetchMock.restore();
});
it('should fetch the sources of the repository', () => {
fetchMock.getOnce(sourcesUrl, collection);
const expectedActions = [
{
type: FETCH_SOURCES_PENDING,
itemId: 'scm/core/_/',
},
{
type: FETCH_SOURCES_SUCCESS,
itemId: 'scm/core/_/',
payload: collection,
},
];
const store = mockStore({});
return store.dispatch(fetchSources(repository, '', '')).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it('should fetch the sources of the repository with the given revision and path', () => {
fetchMock.getOnce(sourcesUrl + 'abc/src', collection);
const expectedActions = [
{
type: FETCH_SOURCES_PENDING,
itemId: 'scm/core/abc/src',
},
{
type: FETCH_SOURCES_SUCCESS,
itemId: 'scm/core/abc/src',
payload: collection,
},
];
const store = mockStore({});
return store.dispatch(fetchSources(repository, 'abc', 'src')).then(() => {
expect(store.getActions()).toEqual(expectedActions);
});
});
it('should dispatch FETCH_SOURCES_FAILURE on server error', () => {
fetchMock.getOnce(sourcesUrl, {
status: 500,
});
const store = mockStore({});
return store.dispatch(fetchSources(repository, '', '')).then(() => {
const actions = store.getActions();
expect(actions[0].type).toBe(FETCH_SOURCES_PENDING);
expect(actions[1].type).toBe(FETCH_SOURCES_FAILURE);
expect(actions[1].itemId).toBe('scm/core/_/');
expect(actions[1].payload).toBeDefined();
});
});
});
describe('reducer tests', () => {
it('should return unmodified state on unknown action', () => {
const state = {};
expect(reducer(state)).toBe(state);
});
it('should store the collection, without revision and path', () => {
const expectedState = {
'scm/core/_/': collection,
};
expect(
reducer({}, fetchSourcesSuccess(repository, '', '', collection)),
).toEqual(expectedState);
});
it('should store the collection, with revision and path', () => {
const expectedState = {
'scm/core/abc/src/main': collection,
};
expect(
reducer(
{},
fetchSourcesSuccess(repository, 'abc', 'src/main', collection),
),
).toEqual(expectedState);
});
});
describe('selector tests', () => {
it('should return false if it is no directory', () => {
const state = {
sources: {
'scm/core/abc/src/main/package.json': {
noDirectory,
},
},
};
expect(
isDirectory(state, repository, 'abc', 'src/main/package.json'),
).toBeFalsy();
});
it('should return true if it is directory', () => {
const state = {
sources: {
'scm/core/abc/src': noDirectory,
},
};
expect(isDirectory(state, repository, 'abc', 'src')).toBe(true);
});
it('should return null', () => {
expect(getSources({}, repository, '', '')).toBeFalsy();
});
it('should return the source collection without revision and path', () => {
const state = {
sources: {
'scm/core/_/': collection,
},
};
expect(getSources(state, repository, '', '')).toBe(collection);
});
it('should return the source collection with revision and path', () => {
const state = {
sources: {
'scm/core/abc/src/main': collection,
},
};
expect(getSources(state, repository, 'abc', 'src/main')).toBe(collection);
});
it('should return true, when fetch sources is pending', () => {
const state = {
pending: {
[FETCH_SOURCES + '/scm/core/_/']: true,
},
};
expect(isFetchSourcesPending(state, repository, '', '')).toEqual(true);
});
it('should return false, when fetch sources is not pending', () => {
expect(isFetchSourcesPending({}, repository, '', '')).toEqual(false);
});
const error = new Error('incredible error from hell');
it('should return error when fetch sources did fail', () => {
const state = {
failure: {
[FETCH_SOURCES + '/scm/core/_/']: error,
},
};
expect(getFetchSourcesFailure(state, repository, '', '')).toEqual(error);
});
it('should return undefined when fetch sources did not fail', () => {
expect(getFetchSourcesFailure({}, repository, '', '')).toBe(undefined);
});
});

View File

@@ -1,12 +1,10 @@
// @flow
import * as types from '../../../modules/types';
import { Repository, File, Action } from '@scm-manager/ui-types';
import { apiClient } from '@scm-manager/ui-components';
import { isPending } from '../../../modules/pending';
import { getFailure } from '../../../modules/failure';
import * as types from "../../../modules/types";
import type { Repository, File, Action } from "@scm-manager/ui-types";
import { apiClient } from "@scm-manager/ui-components";
import { isPending } from "../../../modules/pending";
import { getFailure } from "../../../modules/failure";
export const FETCH_SOURCES = "scm/repos/FETCH_SOURCES";
export const FETCH_SOURCES = 'scm/repos/FETCH_SOURCES';
export const FETCH_SOURCES_PENDING = `${FETCH_SOURCES}_${types.PENDING_SUFFIX}`;
export const FETCH_SOURCES_SUCCESS = `${FETCH_SOURCES}_${types.SUCCESS_SUFFIX}`;
export const FETCH_SOURCES_FAILURE = `${FETCH_SOURCES}_${types.FAILURE_SUFFIX}`;
@@ -14,7 +12,7 @@ export const FETCH_SOURCES_FAILURE = `${FETCH_SOURCES}_${types.FAILURE_SUFFIX}`;
export function fetchSources(
repository: Repository,
revision: string,
path: string
path: string,
) {
return function(dispatch: any) {
dispatch(fetchSourcesPending(repository, revision, path));
@@ -37,18 +35,18 @@ function createUrl(repository: Repository, revision: string, path: string) {
}
// TODO handle trailing slash
const pathDefined = path ? path : "";
const pathDefined = path ? path : '';
return `${base}${encodeURIComponent(revision)}/${pathDefined}`;
}
export function fetchSourcesPending(
repository: Repository,
revision: string,
path: string
path: string,
): Action {
return {
type: FETCH_SOURCES_PENDING,
itemId: createItemId(repository, revision, path)
itemId: createItemId(repository, revision, path),
};
}
@@ -56,12 +54,12 @@ export function fetchSourcesSuccess(
repository: Repository,
revision: string,
path: string,
sources: File
sources: File,
) {
return {
type: FETCH_SOURCES_SUCCESS,
payload: sources,
itemId: createItemId(repository, revision, path)
itemId: createItemId(repository, revision, path),
};
}
@@ -69,18 +67,18 @@ export function fetchSourcesFailure(
repository: Repository,
revision: string,
path: string,
error: Error
error: Error,
): Action {
return {
type: FETCH_SOURCES_FAILURE,
payload: error,
itemId: createItemId(repository, revision, path)
itemId: createItemId(repository, revision, path),
};
}
function createItemId(repository: Repository, revision: string, path: string) {
const revPart = revision ? revision : "_";
const pathPart = path ? path : "";
const revPart = revision ? revision : '_';
const pathPart = path ? path : '';
return `${repository.namespace}/${repository.name}/${revPart}/${pathPart}`;
}
@@ -88,12 +86,14 @@ function createItemId(repository: Repository, revision: string, path: string) {
export default function reducer(
state: any = {},
action: Action = { type: "UNKNOWN" }
action: Action = {
type: 'UNKNOWN',
},
): any {
if (action.itemId && action.type === FETCH_SOURCES_SUCCESS) {
return {
...state,
[action.itemId]: action.payload
[action.itemId]: action.payload,
};
}
return state;
@@ -105,7 +105,7 @@ export function isDirectory(
state: any,
repository: Repository,
revision: string,
path: string
path: string,
): boolean {
const currentFile = getSources(state, repository, revision, path);
if (currentFile && !currentFile.directory) {
@@ -119,8 +119,8 @@ export function getSources(
state: any,
repository: Repository,
revision: string,
path: string
): ?File {
path: string,
): File | null | undefined {
if (state.sources) {
return state.sources[createItemId(repository, revision, path)];
}
@@ -131,12 +131,12 @@ export function isFetchSourcesPending(
state: any,
repository: Repository,
revision: string,
path: string
path: string,
): boolean {
return isPending(
state,
FETCH_SOURCES,
createItemId(repository, revision, path)
createItemId(repository, revision, path),
);
}
@@ -144,11 +144,11 @@ export function getFetchSourcesFailure(
state: any,
repository: Repository,
revision: string,
path: string
): ?Error {
path: string,
): Error | null | undefined {
return getFailure(
state,
FETCH_SOURCES,
createItemId(repository, revision, path)
createItemId(repository, revision, path),
);
}