fixed small review findings

This commit is contained in:
Sebastian Sdorra
2020-01-15 10:49:01 +01:00
parent 5e99ee92bf
commit c85e37c665
9 changed files with 33 additions and 28 deletions

View File

@@ -1,12 +1,12 @@
import React, { FC } from "react";
import styled from "styled-components";
import { RouteComponentProps, withRouter } from "react-router-dom";
import { useLocation } from "react-router-dom";
import { Level, BranchSelector } from "@scm-manager/ui-components";
import CodeViewSwitcher from "./CodeViewSwitcher";
import { useTranslation } from "react-i18next";
import { Branch } from "@scm-manager/ui-types";
const ActionBar = styled.div.attrs(() => ({}))`
const ActionBar = styled.div`
background-color: whitesmoke;
border: 1px solid #dbdbdb;
border-radius: 4px;
@@ -18,15 +18,16 @@ const ActionBar = styled.div.attrs(() => ({}))`
margin-bottom: 1em;
`;
type Props = RouteComponentProps & {
type Props = {
selectedBranch?: string;
branches: Branch[];
onSelectBranch: () => void;
switchViewLink: string;
};
const CodeActionBar: FC<Props> = ({ selectedBranch, branches, onSelectBranch, switchViewLink, location }) => {
const CodeActionBar: FC<Props> = ({ selectedBranch, branches, onSelectBranch, switchViewLink }) => {
const { t } = useTranslation("repos");
const location = useLocation();
return (
<ActionBar>
@@ -47,4 +48,4 @@ const CodeActionBar: FC<Props> = ({ selectedBranch, branches, onSelectBranch, sw
);
};
export default withRouter(CodeActionBar);
export default CodeActionBar;

View File

@@ -2,9 +2,8 @@ import React, { FC } from "react";
import styled from "styled-components";
import { Button, ButtonAddons } from "@scm-manager/ui-components";
import { useTranslation } from "react-i18next";
import { Branch } from "@scm-manager/ui-types";
const SmallButton = styled(Button).attrs(() => ({}))`
const SmallButton = styled(Button)`
border-radius: 4px;
font-size: 1rem;
font-weight: 600;
@@ -20,7 +19,7 @@ type Props = {
};
const CodeViewSwitcher: FC<Props> = ({ currentUrl, switchViewLink }) => {
const [t] = useTranslation("repos");
const { t } = useTranslation("repos");
const resolveLocation = () => {
if (currentUrl.includes("/code/branch") || currentUrl.includes("/code/changesets")) {
@@ -52,7 +51,7 @@ const CodeViewSwitcher: FC<Props> = ({ currentUrl, switchViewLink }) => {
label={t("code.sources")}
icon="fa fa-code"
color={isSourcesTab() ? "link is-selected" : undefined}
link={isChangesetsTab() ? switchViewLink: undefined}
link={isChangesetsTab() ? switchViewLink : undefined}
/>
</ButtonAddonsMarginRight>
);

View File

@@ -50,7 +50,7 @@ class CodeOverview extends React.Component<Props> {
}
return (
<div>
<>
<Route
path={`${url}/sources`}
exact={true}
@@ -77,7 +77,7 @@ class CodeOverview extends React.Component<Props> {
/>
)}
/>
</div>
</>
);
}
}

View File

@@ -22,7 +22,7 @@ class ChangesetsRoot extends React.Component<Props> {
return url;
};
isSelectedBranchNotABranch = () => {
isBranchAvailable = () => {
const { branches, selectedBranch } = this.props;
return branches?.filter(b => b.name === selectedBranch).length === 0;
};
@@ -38,10 +38,10 @@ class ChangesetsRoot extends React.Component<Props> {
onSelectBranch = (branch?: Branch) => {
const { baseUrl, history } = this.props;
if (branch) {
let url = `${baseUrl}/branch/${encodeURIComponent(branch.name)}/changesets/`;
const url = `${baseUrl}/branch/${encodeURIComponent(branch.name)}/changesets/`;
history.push(url);
} else {
history.push(`${baseUrl}/changesets/`)
history.push(`${baseUrl}/changesets/`);
}
};
@@ -58,7 +58,7 @@ class ChangesetsRoot extends React.Component<Props> {
<>
<CodeActionBar
branches={branches}
selectedBranch={!this.isSelectedBranchNotABranch() ? selectedBranch : undefined}
selectedBranch={!this.isBranchAvailable() ? selectedBranch : undefined}
onSelectBranch={this.onSelectBranch}
switchViewLink={this.evaluateSwitchViewLink()}
/>

View File

@@ -122,11 +122,14 @@ class RepositoryRoot extends React.Component<Props> {
<div className="column is-three-quarters">
<Switch>
<Redirect exact from={this.props.match.url} to={redirectedUrl} />
{/* redirect pre 2.0.0-rc2 links */}
<Redirect from={`${url}/changeset/:id`} to={`${url}/code/changeset/:id`} />
<Redirect exact from={`${url}/sources`} to={`${url}/code/sources`} />
<Redirect from={`${url}/sources/:revision/:path*`} to={`${url}/code/sources/:revision/:path*`} />
<Redirect exact from={`${url}/changesets`} to={`${url}/code/changesets`} />
<Redirect from={`${url}/branch/:branch/changesets`} to={`${url}/code/branch/:branch/changesets/`} />
<Route path={`${url}/info`} exact component={() => <RepositoryDetails repository={repository} />} />
<Route path={`${url}/settings/general`} component={() => <EditRepo repository={repository} />} />
<Route

View File

@@ -1,7 +1,7 @@
import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import { apiClient, ErrorNotification, Loading, SyntaxHighlighter } from "@scm-manager/ui-components";
import { File } from "@scm-manager/ui-types";
import { File, Link } from "@scm-manager/ui-types";
type Props = WithTranslation & {
file: File;
@@ -27,14 +27,14 @@ class SourcecodeViewer extends React.Component<Props, State> {
}
componentDidMount() {
const { file } = this.props;
const { currentFileRevision } = this.state;
if (file.revision !== currentFileRevision) {
this.fetchContent();
}
this.fetchContentIfChanged();
}
componentDidUpdate() {
this.fetchContentIfChanged();
}
private fetchContentIfChanged() {
const { file } = this.props;
const { currentFileRevision } = this.state;
if (file.revision !== currentFileRevision) {
@@ -44,7 +44,7 @@ class SourcecodeViewer extends React.Component<Props, State> {
fetchContent = () => {
const { file } = this.props;
getContent(file._links.self.href)
getContent((file._links.self as Link).href)
.then(content => {
this.setState({
content,

View File

@@ -1,5 +1,5 @@
import React from "react";
import { Changeset, File, PagedCollection, Repository } from "@scm-manager/ui-types";
import { Changeset, File, PagedCollection, Repository, Link } from "@scm-manager/ui-types";
import { ChangesetList, ErrorNotification, Loading, StatePaginator } from "@scm-manager/ui-components";
import { getHistory } from "./history";
@@ -31,14 +31,16 @@ class HistoryView extends React.Component<Props, State> {
componentDidMount() {
const { file } = this.props;
file && this.updateHistory(file._links.history.href);
if (file) {
this.updateHistory((file._links.history as Link).href);
}
}
componentDidUpdate() {
const { file } = this.props;
const { currentRevision } = this.state;
if (file?.revision !== currentRevision) {
this.updateHistory(file._links.history.href);
this.updateHistory((file._links.history as Link).href);
}
}
@@ -67,7 +69,7 @@ class HistoryView extends React.Component<Props, State> {
updatePage(page: number) {
const { file } = this.props;
const internalPage = page - 1;
this.updateHistory(file._links.history.href + "?page=" + internalPage.toString());
this.updateHistory((file._links.history as Link).href + "?page=" + internalPage.toString());
}
showHistory() {

View File

@@ -24,7 +24,7 @@ type Props = WithTranslation &
sources?: File | null;
// dispatch props
fetchSources: (repository: Repository, revision: string | undefined, path: string | undefined) => void;
fetchSources: (repository: Repository, revision?: string, path?: string) => void;
};
const extensionPointName = "repos.sources.extensions";

View File

@@ -25,7 +25,7 @@ type Props = WithTranslation &
selectedBranch: string;
// dispatch props
fetchSources: (p1: Repository, p2: string, p3: string) => void;
fetchSources: (repository: Repository, revision: string, path: string) => void;
};
class Sources extends React.Component<Props> {