fix review findings

This commit is contained in:
Eduard Heimbuch
2020-09-24 10:26:07 +02:00
parent ff6aaf7bc5
commit 804a6498a7
19 changed files with 176 additions and 128 deletions

View File

@@ -26,20 +26,20 @@ import { connect } from "react-redux";
import { WithTranslation, withTranslation } from "react-i18next";
import styled from "styled-components";
import { apiClient, Image, Loading, Subtitle, Title } from "@scm-manager/ui-components";
import { getAppVersion, getReleaseInfoLink } from "../../modules/indexResource";
import { getAppVersion, getUpdateInfoLink } from "../../modules/indexResource";
type Props = WithTranslation & {
version: string;
releaseInfoLink?: string;
updateInfoLink?: string;
};
type State = {
loading: boolean;
releaseInfo?: ReleaseInfo;
updateInfo?: UpdateInfo;
};
type ReleaseInfo = {
version: string;
type UpdateInfo = {
latestVersion: string;
link: string;
};
@@ -69,58 +69,67 @@ class AdminDetails extends React.Component<Props, State> {
}
componentDidMount() {
const { releaseInfoLink } = this.props;
const { updateInfoLink } = this.props;
if (releaseInfoLink) {
this.setState({ loading: true });
apiClient
.get(releaseInfoLink)
.then(r => r.json())
.then(releaseInfo => this.setState({ releaseInfo }))
.then(() => this.setState({ loading: false }))
// ignore errors for this action
.catch(() => this.setState({ loading: false }));
if (updateInfoLink) {
this.setState({ loading: true }, () =>
apiClient
.get(updateInfoLink)
.then(r => r.json())
.then(updateInfo => this.setState({ updateInfo }))
.then(() => this.setState({ loading: false }))
// ignore errors for this action
.catch(() => this.setState({ loading: false }))
);
}
}
render() {
const { version, t } = this.props;
const { loading, releaseInfo } = this.state;
renderUpdateInfo() {
const { loading, updateInfo } = this.state;
const { t } = this.props;
if (loading) {
return <Loading />;
}
return (
updateInfo && (
<>
<BoxShadowBox className="box">
<article className="media">
<ImageWrapper className="media-left image is-96x96">
<Image src="/images/blib.jpg" alt={t("admin.info.logo")} />
</ImageWrapper>
<div className="media-content">
<div className="content">
<h3 className="has-text-weight-medium">{t("admin.info.newRelease.title")}</h3>
<p>
{t("admin.info.newRelease.description", {
version: updateInfo?.latestVersion
})}
</p>
<a className="button is-warning is-pulled-right" target="_blank" href={updateInfo?.link}>
{t("admin.info.newRelease.downloadButton")}
</a>
</div>
</div>
</article>
</BoxShadowBox>
<hr />
</>
)
);
}
render() {
const { version, t } = this.props;
return (
<>
<Title title={t("admin.info.title")} />
<NoBottomMarginSubtitle subtitle={t("admin.info.currentAppVersion")} />
<BottomMarginDiv>{version}</BottomMarginDiv>
{releaseInfo && (
<>
<BoxShadowBox className="box">
<article className="media">
<ImageWrapper className="media-left image is-96x96">
<Image src="/images/blib.jpg" alt={t("admin.info.logo")} />
</ImageWrapper>
<div className="media-content">
<div className="content">
<h3 className="has-text-weight-medium">{t("admin.info.newRelease.title")}</h3>
<p>
{t("admin.info.newRelease.description", {
version: releaseInfo?.version
})}
</p>
<a className="button is-info is-pulled-right" target="_blank" href={releaseInfo?.link}>
{t("admin.info.newRelease.downloadButton")}
</a>
</div>
</div>
</article>
</BoxShadowBox>
<hr />
</>
)}
{this.renderUpdateInfo()}
<BoxShadowBox className="box">
<article className="media">
<ImageWrapper className="media-left">
@@ -168,10 +177,10 @@ class AdminDetails extends React.Component<Props, State> {
const mapStateToProps = (state: any) => {
const version = getAppVersion(state);
const releaseInfoLink = getReleaseInfoLink(state);
const updateInfoLink = getUpdateInfoLink(state);
return {
version,
releaseInfoLink
updateInfoLink
};
};

View File

@@ -158,8 +158,8 @@ export function getAppVersion(state: object) {
return state.indexResources.version;
}
export function getReleaseInfoLink(state: object) {
return getLink(state, "releaseInfo");
export function getUpdateInfoLink(state: object) {
return getLink(state, "updateInfo");
}
export function getUiPluginsLink(state: object) {