mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 00:15:44 +01:00
Add "annotations" button to sources view
This commit is contained in:
@@ -24,20 +24,27 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { WithTranslation, withTranslation } from "react-i18next";
|
import { WithTranslation, withTranslation } from "react-i18next";
|
||||||
import { Button, ButtonAddons } from "@scm-manager/ui-components";
|
import { Button, ButtonAddons } from "@scm-manager/ui-components";
|
||||||
|
import { SourceViewSelection } from "../../containers/Content";
|
||||||
|
|
||||||
type Props = WithTranslation & {
|
type Props = WithTranslation & {
|
||||||
className?: string;
|
className?: string;
|
||||||
historyIsSelected: boolean;
|
selected: SourceViewSelection;
|
||||||
showHistory: (p: boolean) => void;
|
showSources: () => void;
|
||||||
|
showHistory: () => void;
|
||||||
|
showAnnotations: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FileButtonAddons extends React.Component<Props> {
|
class FileButtonAddons extends React.Component<Props> {
|
||||||
showHistory = () => {
|
showHistory = () => {
|
||||||
this.props.showHistory(true);
|
this.props.showHistory();
|
||||||
};
|
};
|
||||||
|
|
||||||
showSources = () => {
|
showSources = () => {
|
||||||
this.props.showHistory(false);
|
this.props.showSources();
|
||||||
|
};
|
||||||
|
|
||||||
|
showAnnotations = () => {
|
||||||
|
this.props.showAnnotations();
|
||||||
};
|
};
|
||||||
|
|
||||||
color = (selected: boolean) => {
|
color = (selected: boolean) => {
|
||||||
@@ -45,19 +52,26 @@ class FileButtonAddons extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className, t, historyIsSelected } = this.props;
|
const { className, t, selected, showSources, showHistory, showAnnotations } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ButtonAddons className={className}>
|
<ButtonAddons className={className}>
|
||||||
<div title={t("sources.content.sourcesButton")}>
|
<div title={t("sources.content.sourcesButton")}>
|
||||||
<Button action={this.showSources} color={this.color(!historyIsSelected)}>
|
<Button action={showSources} color={this.color(selected === "source")}>
|
||||||
<span className="icon">
|
<span className="icon">
|
||||||
<i className="fas fa-code" />
|
<i className="fas fa-code" />
|
||||||
</span>
|
</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
<div title={t("sources.content.annotateButton")}>
|
||||||
|
<Button action={showAnnotations} color={this.color(selected === "annotations")}>
|
||||||
|
<span className="icon">
|
||||||
|
<i className="fas fa-user-clock" />
|
||||||
|
</span>
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
<div title={t("sources.content.historyButton")}>
|
<div title={t("sources.content.historyButton")}>
|
||||||
<Button action={this.showHistory} color={this.color(historyIsSelected)}>
|
<Button action={showHistory} color={this.color(selected === "history")}>
|
||||||
<span className="icon">
|
<span className="icon">
|
||||||
<i className="fas fa-history" />
|
<i className="fas fa-history" />
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* MIT License
|
||||||
|
*
|
||||||
|
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React, { FC, useEffect, useState } from "react";
|
||||||
|
import { Link, Repository, File } from "@scm-manager/ui-types";
|
||||||
|
import { Annotate, apiClient, ErrorNotification, Loading } from "@scm-manager/ui-components";
|
||||||
|
import { getContentType } from "./contentType";
|
||||||
|
import { AnnotatedSource } from "@scm-manager/ui-components/src/Annotate";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
file: File;
|
||||||
|
repository: Repository;
|
||||||
|
};
|
||||||
|
|
||||||
|
const AnnotateView: FC<Props> = ({ file, repository }) => {
|
||||||
|
const [annotation, setAnnotation] = useState<AnnotatedSource>(undefined);
|
||||||
|
const [error, setError] = useState<Error | undefined>(undefined);
|
||||||
|
const [language, setLanguage] = useState<string | undefined>(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getContentType(file._links.self.href)
|
||||||
|
.then(result => {
|
||||||
|
setLanguage(result.language);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
setError(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
apiClient
|
||||||
|
.get((file._links.annotate as Link).href)
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(content => {
|
||||||
|
setAnnotation(content);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
setError(error);
|
||||||
|
});
|
||||||
|
}, [file]);
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return <ErrorNotification error={error} />;
|
||||||
|
} else if (annotation && language) {
|
||||||
|
return <Annotate source={{ ...annotation, language }} repository={repository} />;
|
||||||
|
} else {
|
||||||
|
return <Loading />;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AnnotateView;
|
||||||
@@ -33,6 +33,7 @@ import { getSources } from "../modules/sources";
|
|||||||
import FileButtonAddons from "../components/content/FileButtonAddons";
|
import FileButtonAddons from "../components/content/FileButtonAddons";
|
||||||
import SourcesView from "./SourcesView";
|
import SourcesView from "./SourcesView";
|
||||||
import HistoryView from "./HistoryView";
|
import HistoryView from "./HistoryView";
|
||||||
|
import AnnotateView from "./AnnotateView";
|
||||||
|
|
||||||
type Props = WithTranslation & {
|
type Props = WithTranslation & {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@@ -45,7 +46,7 @@ type Props = WithTranslation & {
|
|||||||
|
|
||||||
type State = {
|
type State = {
|
||||||
collapsed: boolean;
|
collapsed: boolean;
|
||||||
showHistory: boolean;
|
selected: SourceViewSelection;
|
||||||
errorFromExtension?: Error;
|
errorFromExtension?: Error;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,13 +82,15 @@ const LighterGreyBackgroundTable = styled.table`
|
|||||||
background-color: #fbfbfb;
|
background-color: #fbfbfb;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
export type SourceViewSelection = "source" | "history" | "annotations";
|
||||||
|
|
||||||
class Content extends React.Component<Props, State> {
|
class Content extends React.Component<Props, State> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
collapsed: true,
|
collapsed: true,
|
||||||
showHistory: false
|
selected: "source"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,13 +100,6 @@ class Content extends React.Component<Props, State> {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
setShowHistoryState(showHistory: boolean) {
|
|
||||||
this.setState({
|
|
||||||
...this.state,
|
|
||||||
showHistory
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleExtensionError = (error: Error) => {
|
handleExtensionError = (error: Error) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
errorFromExtension: error
|
errorFromExtension: error
|
||||||
@@ -112,14 +108,15 @@ class Content extends React.Component<Props, State> {
|
|||||||
|
|
||||||
showHeader() {
|
showHeader() {
|
||||||
const { repository, file, revision } = this.props;
|
const { repository, file, revision } = this.props;
|
||||||
const { showHistory, collapsed } = this.state;
|
const { selected, collapsed } = this.state;
|
||||||
const icon = collapsed ? "angle-right" : "angle-down";
|
const icon = collapsed ? "angle-right" : "angle-down";
|
||||||
|
|
||||||
const selector = file._links.history ? (
|
const selector = file._links.history ? (
|
||||||
<RightMarginFileButtonAddons
|
<RightMarginFileButtonAddons
|
||||||
file={file}
|
selected={selected}
|
||||||
historyIsSelected={showHistory}
|
showSources={() => this.setState({ selected: "source" })}
|
||||||
showHistory={(changeShowHistory: boolean) => this.setShowHistoryState(changeShowHistory)}
|
showHistory={() => this.setState({ selected: "history" })}
|
||||||
|
showAnnotations={() => this.setState({ selected: "annotations" })}
|
||||||
/>
|
/>
|
||||||
) : null;
|
) : null;
|
||||||
|
|
||||||
@@ -212,15 +209,26 @@ class Content extends React.Component<Props, State> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { file, revision, repository, path, breadcrumb } = this.props;
|
const { file, revision, repository, path, breadcrumb } = this.props;
|
||||||
const { showHistory, errorFromExtension } = this.state;
|
const { selected, errorFromExtension } = this.state;
|
||||||
|
|
||||||
const header = this.showHeader();
|
const header = this.showHeader();
|
||||||
const content =
|
let content;
|
||||||
showHistory && file._links.history ? (
|
switch (selected) {
|
||||||
<HistoryView file={file} repository={repository} />
|
case "source":
|
||||||
) : (
|
content = (
|
||||||
<SourcesView revision={revision} file={file} repository={repository} path={path} />
|
<SourcesView revision={revision} file={file} repository={repository} path={path}/>
|
||||||
);
|
);
|
||||||
|
break;
|
||||||
|
case "history":
|
||||||
|
content = (
|
||||||
|
<HistoryView file={file} repository={repository}/>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case "annotations":
|
||||||
|
content = (
|
||||||
|
<AnnotateView file={file} repository={repository} />
|
||||||
|
);
|
||||||
|
}
|
||||||
const moreInformation = this.showMoreInformation();
|
const moreInformation = this.showMoreInformation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import java.util.List;
|
|||||||
@Data
|
@Data
|
||||||
public class BlameDto extends HalRepresentation {
|
public class BlameDto extends HalRepresentation {
|
||||||
|
|
||||||
private List<BlameLineDto> blameLines;
|
private List<BlameLineDto> lines;
|
||||||
|
|
||||||
public BlameDto(Links links) {
|
public BlameDto(Links links) {
|
||||||
super(links);
|
super(links);
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public abstract class BlameResultToBlameDtoMapper implements InstantAttributeMap
|
|||||||
|
|
||||||
BlameDto map(BlameResult result, NamespaceAndName namespaceAndName, String revision, String path) {
|
BlameDto map(BlameResult result, NamespaceAndName namespaceAndName, String revision, String path) {
|
||||||
BlameDto dto = createDto(namespaceAndName, revision, path);
|
BlameDto dto = createDto(namespaceAndName, revision, path);
|
||||||
dto.setBlameLines(result.getBlameLines().stream().map(this::map).collect(Collectors.toList()));
|
dto.setLines(result.getBlameLines().stream().map(this::map).collect(Collectors.toList()));
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user