diff --git a/scm-plugins/scm-git-plugin/src/main/js/RepositoryConfig.tsx b/scm-plugins/scm-git-plugin/src/main/js/RepositoryConfig.tsx index a23fc5040a..7d30bb58b4 100644 --- a/scm-plugins/scm-git-plugin/src/main/js/RepositoryConfig.tsx +++ b/scm-plugins/scm-git-plugin/src/main/js/RepositoryConfig.tsx @@ -1,7 +1,15 @@ import React, { FormEvent } from "react"; import { WithTranslation, withTranslation } from "react-i18next"; import { Branch, Repository, Link } from "@scm-manager/ui-types"; -import { apiClient, BranchSelector, ErrorPage, Loading, Subtitle, Level, SubmitButton } from "@scm-manager/ui-components"; +import { + apiClient, + BranchSelector, + ErrorPage, + Loading, + Subtitle, + Level, + SubmitButton +} from "@scm-manager/ui-components"; type Props = WithTranslation & { repository: Repository; @@ -13,7 +21,7 @@ type State = { submitPending: boolean; error?: Error; branches: Branch[]; - selectedBranchName?: string; + selectedBranchName: string; defaultBranchChanged: boolean; disabled: boolean; }; @@ -29,6 +37,7 @@ class RepositoryConfig extends React.Component { loadingDefaultBranch: true, submitPending: false, branches: [], + selectedBranchName: "", defaultBranchChanged: false, disabled: true }; @@ -87,16 +96,16 @@ class RepositoryConfig extends React.Component { if (!branch) { this.setState({ ...this.state, - selectedBranchName: undefined, + selectedBranchName: "", + defaultBranchChanged: false + }); + } else { + this.setState({ + ...this.state, + selectedBranchName: branch.name, defaultBranchChanged: false }); - return; } - this.setState({ - ...this.state, - selectedBranchName: branch.name, - defaultBranchChanged: false - }); }; submit = (event: FormEvent) => { @@ -164,7 +173,7 @@ class RepositoryConfig extends React.Component { diff --git a/scm-plugins/scm-legacy-plugin/src/main/js/index.tsx b/scm-plugins/scm-legacy-plugin/src/main/js/index.tsx index 418c3e7b21..2c9bbcc39e 100644 --- a/scm-plugins/scm-legacy-plugin/src/main/js/index.tsx +++ b/scm-plugins/scm-legacy-plugin/src/main/js/index.tsx @@ -8,9 +8,6 @@ import { Links, Link } from "@scm-manager/ui-types"; type Props = RouteComponentProps & { authenticated?: boolean; links: Links; - - //context objects - history: History; }; type State = { diff --git a/scm-ui/babel-preset/index.js b/scm-ui/babel-preset/index.js index 940dd71ff6..14d3d23731 100644 --- a/scm-ui/babel-preset/index.js +++ b/scm-ui/babel-preset/index.js @@ -1,4 +1,5 @@ module.exports = api => { + api.cache.using(() => process.env.NODE_ENV || "production"); return { presets: [ require("@babel/preset-env"), diff --git a/scm-ui/pom.xml b/scm-ui/pom.xml index 50bd414118..df60ce8c3e 100644 --- a/scm-ui/pom.xml +++ b/scm-ui/pom.xml @@ -19,6 +19,7 @@ build false + false typescript ui-extensions/src,ui-components/src,ui-webapp/src **/*.test.js,src/tests/** @@ -60,6 +61,7 @@ run + ${skipTypecheck} diff --git a/scm-ui/ui-components/src/BranchSelector.tsx b/scm-ui/ui-components/src/BranchSelector.tsx index 970417fc3c..2e4972e592 100644 --- a/scm-ui/ui-components/src/BranchSelector.tsx +++ b/scm-ui/ui-components/src/BranchSelector.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { FC } from "react"; import classNames from "classnames"; import styled from "styled-components"; import { Branch } from "@scm-manager/ui-types"; @@ -6,16 +6,12 @@ import DropDown from "./forms/DropDown"; type Props = { branches: Branch[]; - selected: (branch?: Branch) => void; + onSelectBranch: (branch: Branch | undefined) => void; selectedBranch?: string; label: string; disabled?: boolean; }; -type State = { - selectedBranch?: Branch; -}; - const ZeroflexFieldLabel = styled.div` flex-basis: inherit; flex-grow: 0; @@ -29,66 +25,31 @@ const NoBottomMarginField = styled.div` margin-bottom: 0 !important; `; -export default class BranchSelector extends React.Component { - constructor(props: Props) { - super(props); - this.state = {}; - } - - componentDidMount() { - const { branches } = this.props; - if (branches) { - const selectedBranch = branches.find(branch => branch.name === this.props.selectedBranch); - this.setState({ - selectedBranch - }); - } - } - - render() { - const { branches, label, disabled } = this.props; - - if (branches) { - return ( -
- - - -
- - - b.name)} - optionSelected={this.branchSelected} - disabled={!!disabled} - preselectedOption={this.state.selectedBranch ? this.state.selectedBranch.name : ""} - /> - - -
+const BranchSelector: FC = ({ branches, onSelectBranch, selectedBranch, label, disabled }) => { + if (branches) { + return ( +
+ + + +
+ + + b.name)} + optionSelected={branch => onSelectBranch(branches.filter(b => b.name === branch)[0])} + disabled={!!disabled} + preselectedOption={selectedBranch && selectedBranch} + /> + +
- ); - } else { - return null; - } +
+ ); + } else { + return null; } +}; - branchSelected = (branchName: string) => { - const { branches, selected } = this.props; - - if (!branchName) { - this.setState({ - selectedBranch: undefined - }); - selected(undefined); - return; - } - const branch = branches.find(b => b.name === branchName); - - selected(branch); - this.setState({ - selectedBranch: branch - }); - }; -} +export default BranchSelector; diff --git a/scm-ui/ui-components/src/CardColumn.tsx b/scm-ui/ui-components/src/CardColumn.tsx index fd84b9b11e..f7e7570d1d 100644 --- a/scm-ui/ui-components/src/CardColumn.tsx +++ b/scm-ui/ui-components/src/CardColumn.tsx @@ -5,7 +5,7 @@ import { Link } from "react-router-dom"; type Props = { title: string; - description: string; + description?: string; avatar: ReactNode; contentRight?: ReactNode; footerLeft: ReactNode; diff --git a/scm-ui/ui-components/src/OverviewPageActions.tsx b/scm-ui/ui-components/src/OverviewPageActions.tsx index bb9aea0ee6..ddf5e717b1 100644 --- a/scm-ui/ui-components/src/OverviewPageActions.tsx +++ b/scm-ui/ui-components/src/OverviewPageActions.tsx @@ -9,10 +9,6 @@ type Props = RouteComponentProps & { showCreateButton: boolean; link: string; label?: string; - - // context props - history: History; - location: any; }; class OverviewPageActions extends React.Component { diff --git a/scm-ui/ui-components/src/forms/DropDown.tsx b/scm-ui/ui-components/src/forms/DropDown.tsx index b65c48b49d..dac9af2880 100644 --- a/scm-ui/ui-components/src/forms/DropDown.tsx +++ b/scm-ui/ui-components/src/forms/DropDown.tsx @@ -13,10 +13,15 @@ type Props = { class DropDown extends React.Component { render() { const { options, optionValues, preselectedOption, className, disabled } = this.props; + + if (preselectedOption && !options.includes(preselectedOption)) { + options.unshift(preselectedOption); + } + return (