From 1888a58cb09fdeec924008fb008322b736dc5c5b Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Wed, 17 Oct 2018 14:11:28 +0200 Subject: [PATCH] fix eslint and flow warnings --- .../packages/ui-components/src/Paginator.js | 6 ++++-- .../ui-components/src/buttons/Button.js | 5 +++-- .../ui-components/src/repositories.test.js | 2 +- scm-ui-components/packages/ui-types/src/hal.js | 6 +++++- scm-ui/src/repos/components/DropDown.js | 2 +- .../components/changesets/ChangesetAuthor.js | 6 +++++- .../components/changesets/ChangesetRow.js | 2 +- scm-ui/src/repos/containers/BranchRoot.js | 7 +------ scm-ui/src/repos/containers/BranchSelector.js | 2 +- scm-ui/src/repos/containers/Changesets.js | 12 +++++------- scm-ui/src/repos/containers/Changesets.test.js | 1 + scm-ui/src/repos/modules/branches.js | 10 +++++++--- scm-ui/src/repos/modules/branches.test.js | 1 - scm-ui/src/repos/modules/changesets.js | 18 ++++++++++-------- 14 files changed, 45 insertions(+), 35 deletions(-) diff --git a/scm-ui-components/packages/ui-components/src/Paginator.js b/scm-ui-components/packages/ui-components/src/Paginator.js index a3fa762171..f72a3512fa 100644 --- a/scm-ui-components/packages/ui-components/src/Paginator.js +++ b/scm-ui-components/packages/ui-components/src/Paginator.js @@ -18,8 +18,10 @@ class Paginator extends React.Component { 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); + } } }; diff --git a/scm-ui-components/packages/ui-components/src/buttons/Button.js b/scm-ui-components/packages/ui-components/src/buttons/Button.js index c07cb3acf3..4ad88f4eac 100644 --- a/scm-ui-components/packages/ui-components/src/buttons/Button.js +++ b/scm-ui-components/packages/ui-components/src/buttons/Button.js @@ -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 { diff --git a/scm-ui-components/packages/ui-components/src/repositories.test.js b/scm-ui-components/packages/ui-components/src/repositories.test.js index ccd972ad03..2dac5c8e54 100644 --- a/scm-ui-components/packages/ui-components/src/repositories.test.js +++ b/scm-ui-components/packages/ui-components/src/repositories.test.js @@ -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", () => { diff --git a/scm-ui-components/packages/ui-types/src/hal.js b/scm-ui-components/packages/ui-types/src/hal.js index 248c5e5453..321b32af30 100644 --- a/scm-ui-components/packages/ui-types/src/hal.js +++ b/scm-ui-components/packages/ui-types/src/hal.js @@ -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 }; diff --git a/scm-ui/src/repos/components/DropDown.js b/scm-ui/src/repos/components/DropDown.js index c118c0269c..5098a901f3 100644 --- a/scm-ui/src/repos/components/DropDown.js +++ b/scm-ui/src/repos/components/DropDown.js @@ -32,7 +32,7 @@ class DropDown extends React.Component { ); } - change = (event: Event) => { + change = (event: SyntheticInputEvent) => { this.props.optionSelected(event.target.value); }; } diff --git a/scm-ui/src/repos/components/changesets/ChangesetAuthor.js b/scm-ui/src/repos/components/changesets/ChangesetAuthor.js index 0007b24f31..778d4b5073 100644 --- a/scm-ui/src/repos/components/changesets/ChangesetAuthor.js +++ b/scm-ui/src/repos/components/changesets/ChangesetAuthor.js @@ -9,8 +9,12 @@ type Props = { export default class ChangesetAuthor extends React.Component { render() { - const { name } = this.props.changeset.author; + const { changeset } = this.props; + if (!changeset.author) { + return null; + } + const { name } = changeset.author; return ( <> {name} {this.renderMail()} diff --git a/scm-ui/src/repos/components/changesets/ChangesetRow.js b/scm-ui/src/repos/components/changesets/ChangesetRow.js index 7ffe0f25cc..09caedb433 100644 --- a/scm-ui/src/repos/components/changesets/ChangesetRow.js +++ b/scm-ui/src/repos/components/changesets/ChangesetRow.js @@ -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"; diff --git a/scm-ui/src/repos/containers/BranchRoot.js b/scm-ui/src/repos/containers/BranchRoot.js index 8d0783bb52..b20edad284 100644 --- a/scm-ui/src/repos/containers/BranchRoot.js +++ b/scm-ui/src/repos/containers/BranchRoot.js @@ -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 { - constructor(props: Props) { - super(props); - this.state = {}; - } - componentDidMount() { this.props.fetchBranches(this.props.repository); } diff --git a/scm-ui/src/repos/containers/BranchSelector.js b/scm-ui/src/repos/containers/BranchSelector.js index 25f36db723..2d8c817542 100644 --- a/scm-ui/src/repos/containers/BranchSelector.js +++ b/scm-ui/src/repos/containers/BranchSelector.js @@ -16,7 +16,7 @@ const styles = { type Props = { branches: Branch[], // TODO: Use generics? - selected?: Branch => void, + selected: (branch?: Branch) => void, // context props classes: Object, diff --git a/scm-ui/src/repos/containers/Changesets.js b/scm-ui/src/repos/containers/Changesets.js index c078e74375..75e280cb00 100644 --- a/scm-ui/src/repos/containers/Changesets.js +++ b/scm-ui/src/repos/containers/Changesets.js @@ -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 { @@ -52,7 +51,7 @@ class Changesets extends React.Component { } render() { - const { changesets, loading, error, t } = this.props; + const { changesets, loading, error } = this.props; if (error) { return ; @@ -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); diff --git a/scm-ui/src/repos/containers/Changesets.test.js b/scm-ui/src/repos/containers/Changesets.test.js index b2c8683625..deb684d31a 100644 --- a/scm-ui/src/repos/containers/Changesets.test.js +++ b/scm-ui/src/repos/containers/Changesets.test.js @@ -1,3 +1,4 @@ +// @flow import { getPageFromMatch } from "./Changesets"; describe("tests for getPageFromMatch", () => { diff --git a/scm-ui/src/repos/modules/branches.js b/scm-ui/src/repos/modules/branches.js index 3148857f51..6b19337278 100644 --- a/scm-ui/src/repos/modules/branches.js +++ b/scm-ui/src/repos/modules/branches.js @@ -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 { diff --git a/scm-ui/src/repos/modules/branches.test.js b/scm-ui/src/repos/modules/branches.test.js index 40abf951cf..4d45a24a09 100644 --- a/scm-ui/src/repos/modules/branches.test.js +++ b/scm-ui/src/repos/modules/branches.test.js @@ -9,7 +9,6 @@ import reducer, { fetchBranches, getBranch, getBranches, - getBranchNames, getFetchBranchesFailure, isFetchBranchesPending } from "./branches"; diff --git a/scm-ui/src/repos/modules/changesets.js b/scm-ui/src/repos/modules/changesets.js index 53df4a1099..067f48391c 100644 --- a/scm-ui/src/repos/modules/changesets.js +++ b/scm-ui/src/repos/modules/changesets.js @@ -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 } } }