From 89291cdf46cda16275c04aff5a7355de02cbb4ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Mon, 26 Nov 2018 15:56:41 +0100 Subject: [PATCH] show history table of content --- scm-ui/src/containers/Main.js | 1 - .../src/repos/sources/containers/Content.js | 8 ++-- .../repos/sources/containers/FileHistory.js | 14 ------- .../repos/sources/containers/HistoryView.js | 34 ++++++++-------- .../repos/sources/containers/SourcesView.js | 9 ++--- .../src/repos/sources/containers/history.js | 16 ++++++++ .../repos/sources/containers/history.test.js | 39 +++++++++++++++++++ 7 files changed, 79 insertions(+), 42 deletions(-) create mode 100644 scm-ui/src/repos/sources/containers/history.js create mode 100644 scm-ui/src/repos/sources/containers/history.test.js diff --git a/scm-ui/src/containers/Main.js b/scm-ui/src/containers/Main.js index 4846c503aa..4bbdf6812a 100644 --- a/scm-ui/src/containers/Main.js +++ b/scm-ui/src/containers/Main.js @@ -19,7 +19,6 @@ import SingleGroup from "../groups/containers/SingleGroup"; import AddGroup from "../groups/containers/AddGroup"; import Config from "../config/containers/Config"; -import ChangeUserPassword from "./ChangeUserPassword"; import Profile from "./Profile"; type Props = { diff --git a/scm-ui/src/repos/sources/containers/Content.js b/scm-ui/src/repos/sources/containers/Content.js index 7202dbe928..ed62e67609 100644 --- a/scm-ui/src/repos/sources/containers/Content.js +++ b/scm-ui/src/repos/sources/containers/Content.js @@ -64,7 +64,7 @@ class Content extends React.Component { } showHeader() { - const { file, classes, t } = this.props; + const { file, classes } = this.props; const { showHistory, collapsed } = this.state; const icon = collapsed ? "fa-angle-right" : "fa-angle-down"; @@ -146,10 +146,12 @@ class Content extends React.Component { render() { const { file, revision, repository, path, classes } = this.props; - const {showHistory} = this.state; + const { showHistory } = this.state; const header = this.showHeader(); - const content = showHistory ? : ( + const content = showHistory ? ( + + ) : ( string + repository: Repository }; type State = { loaded: boolean, + changesets: Changeset[], error?: Error }; @@ -25,13 +21,14 @@ class HistoryView extends React.Component { super(props); this.state = { - loaded: false + loaded: false, + changesets: [] }; } componentDidMount() { const { file } = this.props; - /* getContentType(file._links.self.href) + getHistory(file._links.history.href) .then(result => { if (result.error) { this.setState({ @@ -42,21 +39,22 @@ class HistoryView extends React.Component { } else { this.setState({ ...this.state, - contentType: result.type, - language: result.language, - loaded: true + loaded: true, + changesets: result.changesets }); } }) - .catch(err => {});*/ + .catch(err => {}); } showHistory() { - return "Hallo"; + const { repository } = this.props; + const { changesets } = this.state; + return ; } render() { - const { classes, file } = this.props; + const { file } = this.props; const { loaded, error } = this.state; if (!file || !loaded) { @@ -72,4 +70,4 @@ class HistoryView extends React.Component { } } -export default translate("repos")(HistoryView); +export default (HistoryView); diff --git a/scm-ui/src/repos/sources/containers/SourcesView.js b/scm-ui/src/repos/sources/containers/SourcesView.js index 533d4bd2eb..1e76c6d6bf 100644 --- a/scm-ui/src/repos/sources/containers/SourcesView.js +++ b/scm-ui/src/repos/sources/containers/SourcesView.js @@ -1,6 +1,5 @@ // @flow import React from "react"; -import { translate } from "react-i18next"; import SourcecodeViewer from "../components/content/SourcecodeViewer"; import ImageViewer from "../components/content/ImageViewer"; @@ -14,9 +13,7 @@ type Props = { repository: Repository, file: File, revision: string, - path: string, - classes: any, - t: string => string + path: string }; type State = { @@ -81,7 +78,7 @@ class SourcesView extends React.Component { } render() { - const { classes, file } = this.props; + const { file } = this.props; const { loaded, error } = this.state; if (!file || !loaded) { @@ -97,4 +94,4 @@ class SourcesView extends React.Component { } } -export default translate("repos")(SourcesView); +export default SourcesView; diff --git a/scm-ui/src/repos/sources/containers/history.js b/scm-ui/src/repos/sources/containers/history.js new file mode 100644 index 0000000000..7135706f9b --- /dev/null +++ b/scm-ui/src/repos/sources/containers/history.js @@ -0,0 +1,16 @@ +//@flow +import { apiClient } from "@scm-manager/ui-components"; + +export function getHistory(url: string) { + return apiClient + .get(url) + .then(response => response.json()) + .then(result => { + return { + changesets: result._embedded.changesets + }; + }) + .catch(err => { + return { error: err }; + }); +} diff --git a/scm-ui/src/repos/sources/containers/history.test.js b/scm-ui/src/repos/sources/containers/history.test.js new file mode 100644 index 0000000000..f37567cd79 --- /dev/null +++ b/scm-ui/src/repos/sources/containers/history.test.js @@ -0,0 +1,39 @@ +//@flow +import fetchMock from "fetch-mock"; +import { getHistory } from "./history"; + +describe("get content type", () => { + const FILE_URL = "/repositories/scmadmin/TestRepo/history/file"; + + afterEach(() => { + fetchMock.reset(); + fetchMock.restore(); + }); + + it("should return history", done => { + let changesets: { + changesets: [ + { + id: "1234" + }, + { + id: "2345" + } + ] + }; + let history = { + _embedded: { + changesets + } + }; + + fetchMock.get("/api/v2" + FILE_URL, { + history + }); + + getHistory(FILE_URL).then(content => { + expect(content.changesets).toBe(changesets); + done(); + }); + }); +});