fix a ton of typescript errors

This commit is contained in:
Eduard Heimbuch
2020-01-08 13:40:07 +01:00
parent 15a9a5b09b
commit a43ffacf03
41 changed files with 229 additions and 311 deletions

View File

@@ -1,6 +1,7 @@
import React from "react";
import BranchView from "../components/BranchView";
import { connect } from "react-redux";
import { compose } from "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";
@@ -28,7 +29,6 @@ type Props = {
class BranchRoot extends React.Component<Props> {
componentDidMount() {
const { fetchBranch, repository, branchName } = this.props;
fetchBranch(repository, branchName);
}
@@ -96,9 +96,4 @@ const mapDispatchToProps = (dispatch: any) => {
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(BranchRoot)
);
export default compose(withRouter, connect(mapStateToProps, mapDispatchToProps))(BranchRoot);

View File

@@ -75,7 +75,7 @@ class BranchesOverview extends React.Component<Props> {
}
}
const mapStateToProps = (state, ownProps) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const { repository } = ownProps;
const loading = isFetchBranchesPending(state, repository);
const error = getFetchBranchesFailure(state, repository);
@@ -91,7 +91,7 @@ const mapStateToProps = (state, ownProps) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
fetchBranches: (repository: Repository) => {
dispatch(fetchBranches(repository));
@@ -102,8 +102,5 @@ const mapDispatchToProps = dispatch => {
export default compose(
withTranslation("repos"),
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
connect(mapStateToProps, mapDispatchToProps)
)(BranchesOverview);

View File

@@ -20,7 +20,7 @@ const CodeViewSwitcher: FC<Props> = ({ url }) => {
const createDestinationUrl = (destination: string) => {
let splittedUrl = url.split("/");
splittedUrl[5] = destination;
return splittedUrl.join("/")
return splittedUrl.join("/");
};
return (

View File

@@ -8,8 +8,8 @@ import * as validator from "./repositoryValidation";
type Props = WithTranslation & {
submitForm: (p: Repository) => void;
repository?: Repository;
repositoryTypes: RepositoryType[];
namespaceStrategy: string;
repositoryTypes?: RepositoryType[];
namespaceStrategy?: string;
loading?: boolean;
};
@@ -127,13 +127,16 @@ class RepositoryForm extends React.Component<Props, State> {
);
}
createSelectOptions(repositoryTypes: RepositoryType[]) {
return repositoryTypes.map(repositoryType => {
return {
label: repositoryType.displayName,
value: repositoryType.name
};
});
createSelectOptions(repositoryTypes?: RepositoryType[]) {
if (repositoryTypes) {
return repositoryTypes.map(repositoryType => {
return {
label: repositoryType.displayName,
value: repositoryType.name
};
});
}
return [];
}
renderNamespaceField = () => {

View File

@@ -1,5 +1,6 @@
import React from "react";
import { connect } from "react-redux";
import { compose } from "redux";
import { withRouter } from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next";
import { Changeset, Repository } from "@scm-manager/ui-types";
@@ -42,7 +43,7 @@ class ChangesetView extends React.Component<Props> {
}
}
const mapStateToProps = (state, ownProps: Props) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const repository = ownProps.repository;
const id = ownProps.match.params.id;
const changeset = getChangeset(state, repository, id);
@@ -55,7 +56,7 @@ const mapStateToProps = (state, ownProps: Props) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
fetchChangesetIfNeeded: (repository: Repository, id: string) => {
dispatch(fetchChangesetIfNeeded(repository, id));
@@ -63,9 +64,8 @@ const mapDispatchToProps = dispatch => {
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(ChangesetView))
);
export default compose(
withRouter,
connect(mapStateToProps, mapDispatchToProps),
withTranslation("repos")
)(ChangesetView);

View File

@@ -76,7 +76,7 @@ class Create extends React.Component<Props> {
}
}
const mapStateToProps = state => {
const mapStateToProps = (state: any) => {
const repositoryTypes = getRepositoryTypes(state);
const namespaceStrategies = getNamespaceStrategies(state);
const pageLoading = isFetchRepositoryTypesPending(state) || isFetchNamespaceStrategiesPending(state);
@@ -94,7 +94,7 @@ const mapStateToProps = state => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
fetchRepositoryTypesIfNeeded: () => {
dispatch(fetchRepositoryTypesIfNeeded());
@@ -111,7 +111,4 @@ const mapDispatchToProps = dispatch => {
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(Create));
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(Create));

View File

@@ -1,5 +1,6 @@
import React from "react";
import { connect } from "react-redux";
import { compose } from "redux";
import { withRouter } from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next";
import { History } from "history";
@@ -72,7 +73,7 @@ class DeleteRepo extends React.Component<Props> {
}
}
const mapStateToProps = (state, ownProps) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const { namespace, name } = ownProps.repository;
const loading = isDeleteRepoPending(state, namespace, name);
const error = getDeleteRepoFailure(state, namespace, name);
@@ -82,7 +83,7 @@ const mapStateToProps = (state, ownProps) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
deleteRepo: (repo: Repository, callback: () => void) => {
dispatch(deleteRepo(repo, callback));
@@ -90,7 +91,4 @@ const mapDispatchToProps = dispatch => {
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withRouter(withTranslation("repos")(DeleteRepo)));
export default compose(connect(mapStateToProps, mapDispatchToProps), withRouter, withTranslation("repos"))(DeleteRepo);

View File

@@ -8,6 +8,7 @@ import { modifyRepo, isModifyRepoPending, getModifyRepoFailure, modifyRepoReset
import { History } from "history";
import { ErrorNotification } from "@scm-manager/ui-components";
import { ExtensionPoint } from "@scm-manager/ui-extensions";
import { compose } from "redux";
type Props = {
loading: boolean;
@@ -71,7 +72,7 @@ class EditRepo extends React.Component<Props> {
}
}
const mapStateToProps = (state, ownProps) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const { namespace, name } = ownProps.repository;
const loading = isModifyRepoPending(state, namespace, name);
const error = getModifyRepoFailure(state, namespace, name);
@@ -81,7 +82,7 @@ const mapStateToProps = (state, ownProps) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
modifyRepo: (repo: Repository, callback: () => void) => {
dispatch(modifyRepo(repo, callback));
@@ -92,7 +93,4 @@ const mapDispatchToProps = dispatch => {
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withRouter(EditRepo));
export default compose(connect(mapStateToProps, mapDispatchToProps), withRouter)(EditRepo);

View File

@@ -1,6 +1,6 @@
import React from "react";
import { connect } from "react-redux";
import { withRouter } from "react-router-dom";
import { withRouter, RouteComponentProps } from "react-router-dom";
import { WithTranslation, withTranslation } from "react-i18next";
import { History } from "history";
import { RepositoryCollection } from "@scm-manager/ui-types";
@@ -23,7 +23,7 @@ import {
} from "../modules/repos";
import RepositoryList from "../components/list";
type Props = WithTranslation & {
type Props = WithTranslation & RouteComponentProps & {
loading: boolean;
error: Error;
showCreateButton: boolean;
@@ -103,7 +103,7 @@ class Overview extends React.Component<Props> {
}
}
const mapStateToProps = (state, ownProps) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const { match } = ownProps;
const collection = getRepositoryCollection(state);
const loading = isFetchReposPending(state);
@@ -121,14 +121,11 @@ const mapStateToProps = (state, ownProps) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
fetchReposByPage: (link: string, page: number, filter?: string) => {
dispatch(fetchReposByPage(link, page, filter));
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(withRouter(Overview)));
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(withRouter(Overview)));

View File

@@ -175,7 +175,7 @@ class Permissions extends React.Component<Props> {
}
}
const mapStateToProps = (state, ownProps) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const namespace = ownProps.namespace;
const repoName = ownProps.repoName;
const error =
@@ -216,7 +216,7 @@ const mapStateToProps = (state, ownProps) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
fetchPermissions: (link: string, namespace: string, repoName: string) => {
dispatch(fetchPermissions(link, namespace, repoName));
@@ -245,7 +245,4 @@ const mapDispatchToProps = dispatch => {
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(Permissions));
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(Permissions));

View File

@@ -208,7 +208,7 @@ class SinglePermission extends React.Component<Props, State> {
};
}
const mapStateToProps = (state, ownProps) => {
const mapStateToProps = (state: any, ownProps: Props) => {
const permission = ownProps.permission;
const loading = isModifyPermissionPending(state, ownProps.namespace, ownProps.repoName, permission);
const deleteLoading = isDeletePermissionPending(state, ownProps.namespace, ownProps.repoName, permission);
@@ -219,7 +219,7 @@ const mapStateToProps = (state, ownProps) => {
};
};
const mapDispatchToProps = dispatch => {
const mapDispatchToProps = (dispatch: any) => {
return {
modifyPermission: (permission: Permission, namespace: string, repoName: string) => {
dispatch(modifyPermission(permission, namespace, repoName));
@@ -229,7 +229,4 @@ const mapDispatchToProps = dispatch => {
}
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(SinglePermission));
export default connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(SinglePermission));

View File

@@ -174,10 +174,4 @@ const mapStateToProps = (state: any, ownProps: Props) => {
};
};
export default compose(
withRouter,
connect(
mapStateToProps,
mapDispatchToProps
)
)(withTranslation("repos")(FileTree));
export default compose(withRouter, connect(mapStateToProps, mapDispatchToProps))(withTranslation("repos")(FileTree));

View File

@@ -88,14 +88,16 @@ class FileTreeLeaf extends React.Component<Props> {
render() {
const { file } = this.props;
const renderFileSize = (file: File) => <FileSize bytes={file.length} />;
const renderFileSize = (file: File) => <FileSize bytes={file?.length ? file.length : 0} />;
const renderCommitDate = (file: File) => <DateFromNow date={file.commitDate} />;
return (
<tr>
<td>{this.createFileIcon(file)}</td>
<MinWidthTd className="is-word-break">{this.createFileName(file)}</MinWidthTd>
<NoWrapTd className="is-hidden-mobile">{file.directory ? "" : this.contentIfPresent(file, "length", renderFileSize)}</NoWrapTd>
<NoWrapTd className="is-hidden-mobile">
{file.directory ? "" : this.contentIfPresent(file, "length", renderFileSize)}
</NoWrapTd>
<td className="is-hidden-mobile">{this.contentIfPresent(file, "commitDate", renderCommitDate)}</td>
<MinWidthTd className={classNames("is-word-break", "is-hidden-touch")}>
{this.contentIfPresent(file, "description", file => file.description)}

View File

@@ -85,9 +85,4 @@ const mapDispatchToProps = (dispatch: any) => {
};
};
export default withRouter(
connect(
mapStateToProps,
mapDispatchToProps
)(withTranslation("repos")(SourceExtensions))
);
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(withTranslation("repos")(SourceExtensions)));