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) => () => { createAction = (linkType: string) => () => {
const { collection, onPageChange } = this.props; const { collection, onPageChange } = this.props;
if (onPageChange) { if (onPageChange) {
const link = collection._links[linkType].href; const link = collection._links[linkType];
onPageChange(link); if (link && link.href) {
onPageChange(link.href);
}
} }
}; };

View File

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

View File

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

View File

@@ -4,10 +4,14 @@ export type Link = {
name?: string name?: string
}; };
export type Links = { [string]: Link | Link[] }; type LinkValue = Link | Link[];
// TODO use LinkValue
export type Links = { [string]: any };
export type Collection = { export type Collection = {
_embedded: Object, _embedded: Object,
// $FlowFixMe
_links: Links _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); this.props.optionSelected(event.target.value);
}; };
} }

View File

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

View File

@@ -1,6 +1,6 @@
//@flow //@flow
import React from "react"; 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 classNames from "classnames";
import { translate, Interpolate } from "react-i18next"; import { translate, Interpolate } from "react-i18next";
import ChangesetAvatar from "./ChangesetAvatar"; import ChangesetAvatar from "./ChangesetAvatar";

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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