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,34 +1,33 @@
//@flow
import React from "react";
import BranchView from "../components/BranchView";
import { connect } from "react-redux";
import { Redirect, Route, Switch, withRouter } from "react-router-dom";
import type { Repository, Branch } from "@scm-manager/ui-types";
import React from 'react';
import BranchView from '../components/BranchView';
import { connect } from 'react-redux';
import { Redirect, Route, Switch, withRouter } from 'react-router-dom';
import { Repository, Branch } from '@scm-manager/ui-types';
import {
fetchBranch,
getBranch,
getFetchBranchFailure,
isFetchBranchPending
} from "../modules/branches";
import { ErrorNotification, Loading } from "@scm-manager/ui-components";
import type { History } from "history";
import { NotFoundError } from "@scm-manager/ui-components";
import queryString from "query-string";
isFetchBranchPending,
} from '../modules/branches';
import { ErrorNotification, Loading } from '@scm-manager/ui-components';
import { History } from 'history';
import { NotFoundError } from '@scm-manager/ui-components';
import queryString from 'query-string';
type Props = {
repository: Repository,
branchName: string,
branch: Branch,
loading: boolean,
error?: Error,
repository: Repository;
branchName: string;
branch: Branch;
loading: boolean;
error?: Error;
// context props
history: History,
match: any,
location: any,
history: History;
match: any;
location: any;
// dispatch functions
fetchBranch: (repository: Repository, branchName: string) => void
fetchBranch: (repository: Repository, branchName: string) => void;
};
class BranchRoot extends React.Component<Props> {
@@ -39,7 +38,7 @@ class BranchRoot extends React.Component<Props> {
}
stripEndingSlash = (url: string) => {
if (url.endsWith("/")) {
if (url.endsWith('/')) {
return url.substring(0, url.length - 1);
}
return url;
@@ -57,13 +56,11 @@ class BranchRoot extends React.Component<Props> {
if (error) {
if (
error instanceof NotFoundError &&
queryString.parse(location.search).create === "true"
queryString.parse(location.search).create === 'true'
) {
return (
<Redirect
to={`/repo/${repository.namespace}/${
repository.name
}/branches/create?name=${match.params.branch}`}
to={`/repo/${repository.namespace}/${repository.name}/branches/create?name=${match.params.branch}`}
/>
);
}
@@ -100,7 +97,7 @@ const mapStateToProps = (state, ownProps) => {
branchName,
branch,
loading,
error
error,
};
};
@@ -108,13 +105,13 @@ const mapDispatchToProps = dispatch => {
return {
fetchBranch: (repository: Repository, branchName: string) => {
dispatch(fetchBranch(repository, branchName));
}
},
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(BranchRoot)
mapDispatchToProps,
)(BranchRoot),
);

View File

@@ -1,42 +1,41 @@
// @flow
import React from "react";
import React from 'react';
import {
fetchBranches,
getBranches,
getFetchBranchesFailure,
isFetchBranchesPending,
isPermittedToCreateBranches
} from "../modules/branches";
import { orderBranches } from "../util/orderBranches";
import { connect } from "react-redux";
import type { Branch, Repository } from "@scm-manager/ui-types";
import { compose } from "redux";
import { translate } from "react-i18next";
import { withRouter } from "react-router-dom";
isPermittedToCreateBranches,
} from '../modules/branches';
import { orderBranches } from '../util/orderBranches';
import { connect } from 'react-redux';
import { Branch, Repository } from '@scm-manager/ui-types';
import { compose } from 'redux';
import { translate } from 'react-i18next';
import { withRouter } from 'react-router-dom';
import {
CreateButton,
ErrorNotification,
Loading,
Notification,
Subtitle
} from "@scm-manager/ui-components";
import BranchTable from "../components/BranchTable";
Subtitle,
} from '@scm-manager/ui-components';
import BranchTable from '../components/BranchTable';
type Props = {
repository: Repository,
baseUrl: string,
loading: boolean,
error: Error,
branches: Branch[],
repository: Repository;
baseUrl: string;
loading: boolean;
error: Error;
branches: Branch[];
// dispatch props
showCreateButton: boolean,
fetchBranches: Repository => void,
showCreateButton: boolean;
fetchBranches: (p: Repository) => void;
// Context props
history: any,
match: any,
t: string => string
history: any;
match: any;
t: (p: string) => string;
};
class BranchesOverview extends React.Component<Props> {
@@ -58,7 +57,7 @@ class BranchesOverview extends React.Component<Props> {
return (
<>
<Subtitle subtitle={t("branches.overview.title")} />
<Subtitle subtitle={t('branches.overview.title')} />
{this.renderBranchesTable()}
{this.renderCreateButton()}
</>
@@ -71,7 +70,11 @@ class BranchesOverview extends React.Component<Props> {
orderBranches(branches);
return <BranchTable baseUrl={baseUrl} branches={branches} />;
}
return <Notification type="info">{t("branches.overview.noBranches")}</Notification>;
return (
<Notification type="info">
{t('branches.overview.noBranches')}
</Notification>
);
}
renderCreateButton() {
@@ -79,7 +82,7 @@ class BranchesOverview extends React.Component<Props> {
if (showCreateButton) {
return (
<CreateButton
label={t("branches.overview.createButton")}
label={t('branches.overview.createButton')}
link="./create"
/>
);
@@ -100,7 +103,7 @@ const mapStateToProps = (state, ownProps) => {
loading,
error,
branches,
showCreateButton
showCreateButton,
};
};
@@ -108,15 +111,15 @@ const mapDispatchToProps = dispatch => {
return {
fetchBranches: (repository: Repository) => {
dispatch(fetchBranches(repository));
}
},
};
};
export default compose(
translate("repos"),
translate('repos'),
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
mapDispatchToProps,
),
)(BranchesOverview);

View File

@@ -1,13 +1,12 @@
//@flow
import React from "react";
import React from 'react';
import {
ErrorNotification,
Loading,
Subtitle
} from "@scm-manager/ui-components";
import { translate } from "react-i18next";
import BranchForm from "../components/BranchForm";
import type { Repository, Branch, BranchRequest } from "@scm-manager/ui-types";
Subtitle,
} from '@scm-manager/ui-components';
import { translate } from 'react-i18next';
import BranchForm from '../components/BranchForm';
import { Repository, Branch, BranchRequest } from '@scm-manager/ui-types';
import {
fetchBranches,
getBranches,
@@ -17,35 +16,35 @@ import {
isCreateBranchPending,
getCreateBranchFailure,
isFetchBranchesPending,
getFetchBranchesFailure
} from "../modules/branches";
import type { History } from "history";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import queryString from "query-string";
getFetchBranchesFailure,
} from '../modules/branches';
import { History } from 'history';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import queryString from 'query-string';
type Props = {
loading?: boolean,
error?: Error,
repository: Repository,
branches: Branch[],
createBranchesLink: string,
isPermittedToCreateBranches: boolean,
loading?: boolean;
error?: Error;
repository: Repository;
branches: Branch[];
createBranchesLink: string;
isPermittedToCreateBranches: boolean;
// dispatcher functions
fetchBranches: Repository => void,
fetchBranches: (p: Repository) => void;
createBranch: (
createLink: string,
repository: Repository,
branch: BranchRequest,
callback?: (Branch) => void
) => void,
resetForm: Repository => void,
callback?: (p: Branch) => void,
) => void;
resetForm: (p: Repository) => void;
// context objects
t: string => string,
history: History,
location: any
t: (p: string) => string;
history: History;
location: any;
};
class CreateBranch extends React.Component<Props> {
@@ -60,7 +59,7 @@ class CreateBranch extends React.Component<Props> {
history.push(
`/repo/${repository.namespace}/${
repository.name
}/branch/${encodeURIComponent(branch.name)}/info`
}/branch/${encodeURIComponent(branch.name)}/info`,
);
};
@@ -69,7 +68,7 @@ class CreateBranch extends React.Component<Props> {
this.props.createBranchesLink,
this.props.repository,
branch,
newBranch => this.branchCreated(newBranch)
newBranch => this.branchCreated(newBranch),
);
};
@@ -79,7 +78,15 @@ class CreateBranch extends React.Component<Props> {
};
render() {
const { t, loading, error, repository, branches, createBranchesLink, location } = this.props;
const {
t,
loading,
error,
repository,
branches,
createBranchesLink,
location,
} = this.props;
if (error) {
return <ErrorNotification error={error} />;
@@ -91,7 +98,7 @@ class CreateBranch extends React.Component<Props> {
return (
<>
<Subtitle subtitle={t("branches.create.title")} />
<Subtitle subtitle={t('branches.create.title')} />
<BranchForm
submitForm={branchRequest => this.createBranch(branchRequest)}
loading={loading}
@@ -114,13 +121,13 @@ const mapDispatchToProps = dispatch => {
createLink: string,
repository: Repository,
branchRequest: BranchRequest,
callback?: (newBranch: Branch) => void
callback?: (newBranch: Branch) => void,
) => {
dispatch(createBranch(createLink, repository, branchRequest, callback));
},
resetForm: (repository: Repository) => {
dispatch(createBranchReset(repository));
}
},
};
};
@@ -138,13 +145,13 @@ const mapStateToProps = (state, ownProps) => {
loading,
error,
branches,
createBranchesLink
createBranchesLink,
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(translate("repos")(CreateBranch))
mapDispatchToProps,
)(translate('repos')(CreateBranch)),
);