fix eslint and flow warnings

This commit is contained in:
Sebastian Sdorra
2018-10-17 14:11:28 +02:00
parent 3429f17670
commit 1888a58cb0
14 changed files with 45 additions and 35 deletions

View File

@@ -18,8 +18,10 @@ class Paginator extends React.Component<Props> {
createAction = (linkType: string) => () => {
const { collection, onPageChange } = this.props;
if (onPageChange) {
const link = collection._links[linkType].href;
onPageChange(link);
const link = collection._links[linkType];
if (link && link.href) {
onPageChange(link.href);
}
}
};

View File

@@ -1,7 +1,7 @@
//@flow
import React from "react";
import classNames from "classnames";
import { Link, withRouter } from "react-router-dom";
import { withRouter } from "react-router-dom";
export type ButtonProps = {
label: string,
@@ -17,8 +17,9 @@ export type ButtonProps = {
type Props = ButtonProps & {
type: string,
color: string,
// context prop
history: History
history: any
};
class Button extends React.Component<Props> {

View File

@@ -1,7 +1,7 @@
// @flow
import type { Repository } from "@scm-manager/ui-types";
import { getProtocolLinkByType, getTypePredicate } from "./repositories";
import { getProtocolLinkByType } from "./repositories";
describe("getProtocolLinkByType tests", () => {

View File

@@ -4,10 +4,14 @@ export type Link = {
name?: string
};
export type Links = { [string]: Link | Link[] };
type LinkValue = Link | Link[];
// TODO use LinkValue
export type Links = { [string]: any };
export type Collection = {
_embedded: Object,
// $FlowFixMe
_links: Links
};

View File

@@ -32,7 +32,7 @@ class DropDown extends React.Component<Props> {
);
}
change = (event: Event) => {
change = (event: SyntheticInputEvent<HTMLSelectElement>) => {
this.props.optionSelected(event.target.value);
};
}

View File

@@ -9,8 +9,12 @@ type Props = {
export default class ChangesetAuthor extends React.Component<Props> {
render() {
const { name } = this.props.changeset.author;
const { changeset } = this.props;
if (!changeset.author) {
return null;
}
const { name } = changeset.author;
return (
<>
{name} {this.renderMail()}

View File

@@ -1,6 +1,6 @@
//@flow
import React from "react";
import type { Changeset, Repository } from "@scm-manager/ui-types";
import type { Changeset, Repository, Tag } from "@scm-manager/ui-types";
import classNames from "classnames";
import { translate, Interpolate } from "react-i18next";
import ChangesetAvatar from "./ChangesetAvatar";

View File

@@ -31,16 +31,11 @@ type Props = {
fetchBranches: Repository => void,
// Context props
history: History,
history: any, // TODO flow type
match: any
};
class BranchRoot extends React.Component<Props> {
constructor(props: Props) {
super(props);
this.state = {};
}
componentDidMount() {
this.props.fetchBranches(this.props.repository);
}

View File

@@ -16,7 +16,7 @@ const styles = {
type Props = {
branches: Branch[], // TODO: Use generics?
selected?: Branch => void,
selected: (branch?: Branch) => void,
// context props
classes: Object,

View File

@@ -23,7 +23,6 @@ import {
LinkPaginator,
Loading
} from "@scm-manager/ui-components";
import { translate } from "react-i18next";
import { compose } from "redux";
type Props = {
@@ -40,8 +39,8 @@ type Props = {
// Dispatch props
fetchChangesets: (Repository, Branch, number) => void,
// Context Props
t: string => string
// context props
match: any
};
class Changesets extends React.Component<Props> {
@@ -52,7 +51,7 @@ class Changesets extends React.Component<Props> {
}
render() {
const { changesets, loading, error, t } = this.props;
const { changesets, loading, error } = this.props;
if (error) {
return <ErrorNotification error={error} />;
@@ -96,7 +95,7 @@ const mapDispatchToProps = dispatch => {
};
export function getPageFromMatch(match: any) {
let page = parseInt(match.params.page);
let page = parseInt(match.params.page, 10);
if (isNaN(page) || !page) {
page = 1;
}
@@ -119,6 +118,5 @@ export default compose(
connect(
mapStateToProps,
mapDispatchToProps
),
translate("repos")
)
)(Changesets);

View File

@@ -1,3 +1,4 @@
// @flow
import { getPageFromMatch } from "./Changesets";
describe("tests for getPageFromMatch", () => {

View File

@@ -72,12 +72,16 @@ export default function reducer(
state: State = {},
action: Action = { type: "UNKNOWN" }
): State {
if (!action.payload) {
return state;
}
const payload = action.payload;
switch (action.type) {
case FETCH_BRANCHES_SUCCESS:
const key = createKey(action.payload.repository);
const key = createKey(payload.repository);
return {
...state,
[key]: extractBranchesFromPayload(action.payload.data)
[key]: extractBranchesFromPayload(payload.data)
};
default:
return state;
@@ -104,7 +108,7 @@ export function getBranches(state: Object, repository: Repository) {
}
export function getBranch(
state: State,
state: Object,
repository: Repository,
name: string
): ?Branch {

View File

@@ -9,7 +9,6 @@ import reducer, {
fetchBranches,
getBranch,
getBranches,
getBranchNames,
getFetchBranchesFailure,
isFetchBranchesPending
} from "./branches";

View File

@@ -8,11 +8,9 @@ import {
import { apiClient } from "@scm-manager/ui-components";
import { isPending } from "../../modules/pending";
import { getFailure } from "../../modules/failure";
import { combineReducers } from "redux";
import type {
Action,
Branch,
Changeset,
PagedCollection,
Repository
} from "@scm-manager/ui-types";
@@ -28,7 +26,7 @@ export const FETCH_CHANGESETS_FAILURE = `${FETCH_CHANGESETS}_${FAILURE_SUFFIX}`;
export function fetchChangesets(
repository: Repository,
branch?: Branch,
page: number
page?: number
) {
const link = createChangesetsLink(repository, branch, page);
@@ -49,7 +47,7 @@ export function fetchChangesets(
function createChangesetsLink(
repository: Repository,
branch?: Branch,
page: number
page?: number
) {
let link = repository._links.changesets.href;
@@ -117,9 +115,13 @@ export default function reducer(
state: any = {},
action: Action = { type: "UNKNOWN" }
): Object {
if (!action.payload) {
return state;
}
const payload = action.payload;
switch (action.type) {
case FETCH_CHANGESETS_SUCCESS:
const changesets = action.payload._embedded.changesets;
const changesets = payload._embedded.changesets;
const changesetIds = changesets.map(c => c.id);
const key = action.itemId;
@@ -139,9 +141,9 @@ export default function reducer(
list: {
entries: changesetIds,
entry: {
page: action.payload.page,
pageTotal: action.payload.pageTotal,
_links: action.payload._links
page: payload.page,
pageTotal: payload.pageTotal,
_links: payload._links
}
}
}