merge 2.0.0-m3

This commit is contained in:
Eduard Heimbuch
2019-10-25 12:33:16 +02:00
603 changed files with 8015 additions and 151780 deletions

View File

@@ -1,9 +1,8 @@
// @flow
import React from "react";
import type { File } from "@scm-manager/ui-types";
import { File } from "@scm-manager/ui-types";
type Props = {
file: File
file: File;
};
class FileIcon extends React.Component<Props> {

View File

@@ -1,5 +1,3 @@
// @flow
import { findParent } from "./FileTree";
describe("find parent tests", () => {

View File

@@ -1,36 +1,26 @@
//@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 { WithTranslation, withTranslation } 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 {
ErrorNotification,
Loading,
Notification
} from "@scm-manager/ui-components";
import {
getFetchSourcesFailure,
isFetchSourcesPending,
getSources
} from "../modules/sources";
import { Repository, File } from "@scm-manager/ui-types";
import { ErrorNotification, Loading, Notification } from "@scm-manager/ui-components";
import { getFetchSourcesFailure, isFetchSourcesPending, getSources } from "../modules/sources";
import FileTreeLeaf from "./FileTreeLeaf";
type Props = {
loading: boolean,
error: Error,
tree: File,
repository: Repository,
revision: string,
path: string,
baseUrl: string,
type Props = WithTranslation & {
loading: boolean;
error: Error;
tree: File;
repository: Repository;
revision: string;
path: string;
baseUrl: string;
// context props
t: string => string,
match: any
match: any;
};
const FixedWidthTh = styled.th`
@@ -114,27 +104,15 @@ class FileTree extends React.Component<Props> {
<tr>
<FixedWidthTh />
<th>{t("sources.file-tree.name")}</th>
<th className="is-hidden-mobile">
{t("sources.file-tree.length")}
</th>
<th className="is-hidden-mobile">
{t("sources.file-tree.lastModified")}
</th>
<th className="is-hidden-mobile">
{t("sources.file-tree.description")}
</th>
{binder.hasExtension("repos.sources.tree.row.right") && (
<th className="is-hidden-mobile" />
)}
<th className="is-hidden-mobile">{t("sources.file-tree.length")}</th>
<th className="is-hidden-mobile">{t("sources.file-tree.lastModified")}</th>
<th className="is-hidden-mobile">{t("sources.file-tree.description")}</th>
{binder.hasExtension("repos.sources.tree.row.right") && <th className="is-hidden-mobile" />}
</tr>
</thead>
<tbody>
{files.map(file => (
<FileTreeLeaf
key={file.name}
file={file}
baseUrl={baseUrlWithRevision}
/>
<FileTreeLeaf key={file.name} file={file} baseUrl={baseUrlWithRevision} />
))}
</tbody>
</table>
@@ -163,4 +141,4 @@ const mapStateToProps = (state: any, ownProps: Props) => {
export default compose(
withRouter,
connect(mapStateToProps)
)(translate("repos")(FileTree));
)(withTranslation("repos")(FileTree));

View File

@@ -1,7 +1,5 @@
// @flow
import { createLink } from "./FileTreeLeaf";
import type { File } from "@scm-manager/ui-types";
import { File } from "@scm-manager/ui-types";
describe("create link tests", () => {
function dir(path: string): File {

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 { 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`
@@ -67,22 +66,20 @@ export default class FileTreeLeaf extends React.Component<Props> {
return (
<tr>
<td>{this.createFileIcon(file)}</td>
<MinWidthTd className="is-word-break">
{this.createFileName(file)}
</MinWidthTd>
<MinWidthTd className="is-word-break">{this.createFileName(file)}</MinWidthTd>
<td className="is-hidden-mobile">{fileSize}</td>
<td className="is-hidden-mobile">
<DateFromNow date={file.lastModified} />
</td>
<MinWidthTd className={classNames("is-word-break", "is-hidden-mobile")}>
{file.description}
</MinWidthTd>
<MinWidthTd className={classNames("is-word-break", "is-hidden-mobile")}>{file.description}</MinWidthTd>
{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,21 @@
import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import { File } from "@scm-manager/ui-types";
import { DownloadButton } from "@scm-manager/ui-components";
type Props = WithTranslation & {
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 withTranslation("repos")(DownloadViewer);

View File

@@ -1,13 +1,11 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
import { ButtonAddons, Button } from "@scm-manager/ui-components";
type Props = {
className?: string,
t: string => string,
historyIsSelected: boolean,
showHistory: boolean => void
type Props = WithTranslation & {
className?: string;
historyIsSelected: boolean;
showHistory: (p: boolean) => void;
};
class FileButtonAddons extends React.Component<Props> {
@@ -29,22 +27,14 @@ class FileButtonAddons extends React.Component<Props> {
return (
<ButtonAddons className={className}>
<div title={t("sources.content.sourcesButton")}>
<Button
action={this.showSources}
className="reduced"
color={this.color(!historyIsSelected)}
>
<Button action={this.showSources} className="reduced" color={this.color(!historyIsSelected)}>
<span className="icon">
<i className="fas fa-code" />
</span>
</Button>
</div>
<div title={t("sources.content.historyButton")}>
<Button
action={this.showHistory}
className="reduced"
color={this.color(historyIsSelected)}
>
<Button action={this.showHistory} className="reduced" color={this.color(historyIsSelected)}>
<span className="icon">
<i className="fas fa-history" />
</span>
@@ -55,4 +45,4 @@ class FileButtonAddons extends React.Component<Props> {
}
}
export default translate("repos")(FileButtonAddons);
export default withTranslation("repos")(FileButtonAddons);

View File

@@ -1,11 +1,9 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import type { File } from "@scm-manager/ui-types";
import { WithTranslation, withTranslation } from "react-i18next";
import { File } from "@scm-manager/ui-types";
type Props = {
t: string => string,
file: File
type Props = WithTranslation & {
file: File;
};
class ImageViewer extends React.Component<Props> {
@@ -21,4 +19,4 @@ class ImageViewer extends React.Component<Props> {
}
}
export default translate("repos")(ImageViewer);
export default withTranslation("repos")(ImageViewer);

View File

@@ -1,9 +1,5 @@
//@flow
import fetchMock from "fetch-mock";
import {
getContent,
getLanguage
} from "./SourcecodeViewer";
import { getContent, getLanguage } from "./SourcecodeViewer";
describe("get content", () => {
const CONTENT_URL = "/repositories/scmadmin/TestRepo/content/testContent";

View File

@@ -1,20 +1,18 @@
// @flow
import React from "react";
import { translate } from "react-i18next";
import { WithTranslation, withTranslation } from "react-i18next";
import { apiClient, SyntaxHighlighter } from "@scm-manager/ui-components";
import type { File } from "@scm-manager/ui-types";
import { File } from "@scm-manager/ui-types";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
type Props = {
t: string => string,
file: File,
language: string
type Props = WithTranslation & {
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> {
@@ -64,12 +62,7 @@ class SourcecodeViewer extends React.Component<Props, State> {
return null;
}
return (
<SyntaxHighlighter
language={getLanguage(language)}
value= {content}
/>
);
return <SyntaxHighlighter language={getLanguage(language)} value={content} />;
}
}
@@ -85,8 +78,10 @@ export function getContent(url: string) {
return response;
})
.catch(err => {
return { error: err };
return {
error: err
};
});
}
export default translate("repos")(SourcecodeViewer);
export default withTranslation("repos")(SourcecodeViewer);

View File

@@ -1,32 +1,28 @@
// @flow
import React from "react";
import {connect} from "react-redux";
import {translate} from "react-i18next";
import { connect } from "react-redux";
import { WithTranslation, withTranslation } 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 { 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,
// context props
t: string => string
type Props = WithTranslation & {
loading: boolean;
file: File;
repository: Repository;
revision: string;
path: string;
};
type State = {
collapsed: boolean,
showHistory: boolean,
errorFromExtension?: Error
collapsed: boolean;
showHistory: boolean;
errorFromExtension?: Error;
};
const VCenteredChild = styled.div`
@@ -73,7 +69,9 @@ class Content extends React.Component<Props, State> {
}
handleExtensionError = (error: Error) => {
this.setState({ errorFromExtension: error });
this.setState({
errorFromExtension: error
});
};
showHeader() {
@@ -85,9 +83,7 @@ class Content extends React.Component<Props, State> {
<RightMarginFileButtonAddons
file={file}
historyIsSelected={showHistory}
showHistory={(changeShowHistory: boolean) =>
this.setShowHistoryState(changeShowHistory)
}
showHistory={(changeShowHistory: boolean) => this.setShowHistoryState(changeShowHistory)}
/>
) : null;
@@ -160,7 +156,11 @@ class Content extends React.Component<Props, State> {
<ExtensionPoint
name="repos.content.metadata"
renderAll={true}
props={{ file, repository, revision }}
props={{
file,
repository,
revision
}}
/>
</tbody>
</LighterGreyBackgroundTable>
@@ -179,12 +179,7 @@ class Content extends React.Component<Props, State> {
showHistory && file._links.history ? (
<HistoryView file={file} repository={repository} />
) : (
<SourcesView
revision={revision}
file={file}
repository={repository}
path={path}
/>
<SourcesView revision={revision} file={file} repository={repository} path={path} />
);
const moreInformation = this.showMoreInformation();
@@ -211,4 +206,4 @@ const mapStateToProps = (state: any, ownProps: Props) => {
};
};
export default connect(mapStateToProps)(translate("repos")(Content));
export default connect(mapStateToProps)(withTranslation("repos")(Content));

View File

@@ -1,30 +1,19 @@
// @flow
import React from "react";
import type {
File,
Changeset,
Repository,
PagedCollection
} from "@scm-manager/ui-types";
import {
ErrorNotification,
Loading,
StatePaginator,
ChangesetList
} from "@scm-manager/ui-components";
import { File, Changeset, Repository, PagedCollection } from "@scm-manager/ui-types";
import { ErrorNotification, Loading, StatePaginator, 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> {
@@ -68,9 +57,7 @@ class HistoryView extends React.Component<Props, State> {
updatePage(page: number) {
const { file } = this.props;
const internalPage = page - 1;
this.updateHistory(
file._links.history.href + "?page=" + internalPage.toString()
);
this.updateHistory(file._links.history.href + "?page=" + internalPage.toString());
}
showHistory() {

View File

@@ -0,0 +1,211 @@
import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next";
import { Branch, Repository } from "@scm-manager/ui-types";
import { BranchSelector, Breadcrumb, ErrorNotification, Loading } from "@scm-manager/ui-components";
import FileTree from "../components/FileTree";
import {
fetchBranches,
getBranches,
getFetchBranchesFailure,
isFetchBranchesPending
} from "../../branches/modules/branches";
import { compose } from "redux";
import Content from "./Content";
import { fetchSources, isDirectory } from "../modules/sources";
type Props = WithTranslation & {
repository: Repository;
loading: boolean;
error: Error;
baseUrl: string;
branches: Branch[];
revision: string;
path: string;
currentFileIsDirectory: boolean;
// dispatch props
fetchBranches: (p: Repository) => void;
fetchSources: (p1: Repository, p2: string, p3: string) => void;
// Context props
history: any;
match: any;
location: any;
};
type State = {
selectedBranch: any;
};
class Sources extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
selectedBranch: null
};
}
componentDidMount() {
const { fetchBranches, repository, revision, path, fetchSources } = this.props;
fetchBranches(repository);
fetchSources(repository, revision, path);
this.redirectToDefaultBranch();
}
componentDidUpdate(prevProps) {
const { fetchSources, repository, revision, path } = this.props;
if (prevProps.revision !== revision || prevProps.path !== path) {
fetchSources(repository, revision, path);
}
this.redirectToDefaultBranch();
}
redirectToDefaultBranch = () => {
const { branches } = this.props;
if (this.shouldRedirectToDefaultBranch()) {
const defaultBranches = branches.filter(b => b.defaultBranch);
if (defaultBranches.length > 0) {
this.branchSelected(defaultBranches[0]);
}
}
};
shouldRedirectToDefaultBranch = () => {
const { branches, revision } = this.props;
return branches && !revision;
};
branchSelected = (branch?: Branch) => {
const { baseUrl, history, path } = this.props;
let url;
if (branch) {
this.setState({
selectedBranch: branch
});
if (path) {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/${path}`;
} else {
url = `${baseUrl}/${encodeURIComponent(branch.name)}/`;
}
} else {
this.setState({
selectedBranch: null
});
url = `${baseUrl}/`;
}
history.push(url);
};
render() {
const { repository, baseUrl, loading, error, revision, path, currentFileIsDirectory } = this.props;
if (error) {
return <ErrorNotification error={error} />;
}
if (loading) {
return <Loading />;
}
if (currentFileIsDirectory) {
return (
<div className="panel">
{this.renderBranchSelector()}
{this.renderBreadcrumb()}
<FileTree repository={repository} revision={revision} path={path} baseUrl={baseUrl} />
</div>
);
} else {
return <Content repository={repository} revision={revision} path={path} />;
}
}
renderBranchSelector = () => {
const { branches, revision, t } = this.props;
if (branches) {
return (
<div className="panel-heading">
<BranchSelector
branches={branches}
selectedBranch={revision}
label={t("changesets.branchSelectorLabel")}
selected={(b: Branch) => {
this.branchSelected(b);
}}
/>
</div>
);
}
return null;
};
renderBreadcrumb = () => {
const { revision, path, baseUrl, branches, repository } = this.props;
const { selectedBranch } = this.state;
if (revision) {
return (
<Breadcrumb
revision={encodeURIComponent(revision)}
path={path}
baseUrl={baseUrl}
branch={selectedBranch}
defaultBranch={branches && branches.filter(b => b.defaultBranch === true)[0]}
branches={branches}
repository={repository}
/>
);
}
return null;
};
}
const mapStateToProps = (state, ownProps) => {
const { repository, match } = ownProps;
const { revision, path } = match.params;
const decodedRevision = revision ? decodeURIComponent(revision) : undefined;
const loading = isFetchBranchesPending(state, repository);
const error = getFetchBranchesFailure(state, repository);
const branches = getBranches(state, repository);
const currentFileIsDirectory = decodedRevision
? isDirectory(state, repository, decodedRevision, path)
: isDirectory(state, repository, revision, path);
return {
repository,
revision: decodedRevision,
path,
loading,
error,
branches,
currentFileIsDirectory
};
};
const mapDispatchToProps = dispatch => {
return {
fetchBranches: (repository: Repository) => {
dispatch(fetchBranches(repository));
},
fetchSources: (repository: Repository, revision: string, path: string) => {
dispatch(fetchSources(repository, revision, path));
}
};
};
export default compose(
withTranslation("repos"),
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
)(Sources);

View File

@@ -1,4 +1,3 @@
// @flow
import React from "react";
import SourcecodeViewer from "../components/content/SourcecodeViewer";
@@ -6,21 +5,21 @@ 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 { 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> {
@@ -69,7 +68,11 @@ class SourcesView extends React.Component<Props, State> {
return (
<ExtensionPoint
name="repos.sources.view"
props={{ file, contentType, revision }}
props={{
file,
contentType,
revision
}}
>
<DownloadViewer file={file} />
</ExtensionPoint>

View File

@@ -1,4 +1,3 @@
//@flow
import fetchMock from "fetch-mock";
import { getContentType } from "./contentType";
@@ -11,7 +10,7 @@ describe("get content type", () => {
});
it("should return content", done => {
let headers = {
const headers = {
"Content-Type": "application/text",
"X-Programming-Language": "JAVA"
};

View File

@@ -1,4 +1,3 @@
//@flow
import { apiClient } from "@scm-manager/ui-components";
export function getContentType(url: string) {
@@ -11,6 +10,8 @@ export function getContentType(url: string) {
};
})
.catch(err => {
return { error: err };
return {
error: err
};
});
}

View File

@@ -1,4 +1,3 @@
//@flow
import fetchMock from "fetch-mock";
import { getHistory } from "./history";

View File

@@ -1,4 +1,3 @@
//@flow
import { apiClient } from "@scm-manager/ui-components";
export function getHistory(url: string) {
@@ -17,6 +16,8 @@ export function getHistory(url: string) {
};
})
.catch(err => {
return { error: err };
return {
error: err
};
});
}

View File

@@ -1,6 +1,4 @@
// @flow
import type { Repository, File } from "@scm-manager/ui-types";
import { Repository, File } from "@scm-manager/ui-types";
import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import fetchMock from "fetch-mock";
@@ -18,8 +16,7 @@ import {
isDirectory
} from "./sources";
const sourcesUrl =
"http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/";
const sourcesUrl = "http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/";
const repository: Repository = {
name: "core",
@@ -123,7 +120,10 @@ describe("sources fetch", () => {
fetchMock.getOnce(sourcesUrl, collection);
const expectedActions = [
{ type: FETCH_SOURCES_PENDING, itemId: "scm/core/_/" },
{
type: FETCH_SOURCES_PENDING,
itemId: "scm/core/_/"
},
{
type: FETCH_SOURCES_SUCCESS,
itemId: "scm/core/_/",
@@ -141,7 +141,10 @@ describe("sources fetch", () => {
fetchMock.getOnce(sourcesUrl + "abc/src", collection);
const expectedActions = [
{ type: FETCH_SOURCES_PENDING, itemId: "scm/core/abc/src" },
{
type: FETCH_SOURCES_PENDING,
itemId: "scm/core/abc/src"
},
{
type: FETCH_SOURCES_SUCCESS,
itemId: "scm/core/abc/src",
@@ -181,21 +184,14 @@ describe("reducer tests", () => {
const expectedState = {
"scm/core/_/": collection
};
expect(
reducer({}, fetchSourcesSuccess(repository, "", "", collection))
).toEqual(expectedState);
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);
expect(reducer({}, fetchSourcesSuccess(repository, "abc", "src/main", collection))).toEqual(expectedState);
});
});
@@ -208,9 +204,7 @@ describe("selector tests", () => {
}
}
};
expect(
isDirectory(state, repository, "abc", "src/main/package.json")
).toBeFalsy();
expect(isDirectory(state, repository, "abc", "src/main/package.json")).toBeFalsy();
});
it("should return true if it is directory", () => {

View File

@@ -1,7 +1,5 @@
// @flow
import * as types from "../../../modules/types";
import type { Repository, File, Action } from "@scm-manager/ui-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";
@@ -11,11 +9,7 @@ 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}`;
export function fetchSources(
repository: Repository,
revision: string,
path: string
) {
export function fetchSources(repository: Repository, revision: string, path: string) {
return function(dispatch: any) {
dispatch(fetchSourcesPending(repository, revision, path));
return apiClient
@@ -41,23 +35,14 @@ function createUrl(repository: Repository, revision: string, path: string) {
return `${base}${encodeURIComponent(revision)}/${pathDefined}`;
}
export function fetchSourcesPending(
repository: Repository,
revision: string,
path: string
): Action {
export function fetchSourcesPending(repository: Repository, revision: string, path: string): Action {
return {
type: FETCH_SOURCES_PENDING,
itemId: createItemId(repository, revision, path)
};
}
export function fetchSourcesSuccess(
repository: Repository,
revision: string,
path: string,
sources: File
) {
export function fetchSourcesSuccess(repository: Repository, revision: string, path: string, sources: File) {
return {
type: FETCH_SOURCES_SUCCESS,
payload: sources,
@@ -65,12 +50,7 @@ export function fetchSourcesSuccess(
};
}
export function fetchSourcesFailure(
repository: Repository,
revision: string,
path: string,
error: Error
): Action {
export function fetchSourcesFailure(repository: Repository, revision: string, path: string, error: Error): Action {
return {
type: FETCH_SOURCES_FAILURE,
payload: error,
@@ -88,7 +68,9 @@ 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 {
@@ -101,12 +83,7 @@ export default function reducer(
// selectors
export function isDirectory(
state: any,
repository: Repository,
revision: string,
path: string
): boolean {
export function isDirectory(state: any, repository: Repository, revision: string, path: string): boolean {
const currentFile = getSources(state, repository, revision, path);
if (currentFile && !currentFile.directory) {
return false;
@@ -120,24 +97,15 @@ export function getSources(
repository: Repository,
revision: string,
path: string
): ?File {
): File | null | undefined {
if (state.sources) {
return state.sources[createItemId(repository, revision, path)];
}
return null;
}
export function isFetchSourcesPending(
state: any,
repository: Repository,
revision: string,
path: string
): boolean {
return isPending(
state,
FETCH_SOURCES,
createItemId(repository, revision, path)
);
export function isFetchSourcesPending(state: any, repository: Repository, revision: string, path: string): boolean {
return isPending(state, FETCH_SOURCES, createItemId(repository, revision, path));
}
export function getFetchSourcesFailure(
@@ -145,10 +113,6 @@ export function getFetchSourcesFailure(
repository: Repository,
revision: string,
path: string
): ?Error {
return getFailure(
state,
FETCH_SOURCES,
createItemId(repository, revision, path)
);
): Error | null | undefined {
return getFailure(state, FETCH_SOURCES, createItemId(repository, revision, path));
}