mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
merge with default branch
This commit is contained in:
@@ -2,7 +2,6 @@ import React from "react";
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import MarkdownView from "./MarkdownView";
|
||||
import styled from "styled-components";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
|
||||
import TestPage from "./__resources__/test-page.md";
|
||||
import MarkdownWithoutLang from "./__resources__/markdown-without-lang.md";
|
||||
@@ -12,7 +11,6 @@ const Spacing = styled.div`
|
||||
`;
|
||||
|
||||
storiesOf("MarkdownView", module)
|
||||
.addDecorator(story => <MemoryRouter initialEntries={["/"]}>{story()}</MemoryRouter>)
|
||||
.add("Default", () => (
|
||||
<Spacing>
|
||||
<MarkdownView content={TestPage} skipHtml={false} />
|
||||
|
||||
18
scm-ui/ui-components/src/__resources__/Diff.binary.ts
Normal file
18
scm-ui/ui-components/src/__resources__/Diff.binary.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export default `diff --git a/Main.java b/Main.java
|
||||
index 9b5ca13..7ced845 100644
|
||||
--- a/Main.java
|
||||
+++ b/Main.java
|
||||
@@ -1,5 +1,5 @@
|
||||
class Main {
|
||||
- public static void main(String[] args) {
|
||||
+ public static void main(String[] arguments) {
|
||||
System.out.println("Expect nothing more to happen.");
|
||||
}
|
||||
}
|
||||
diff --git a/conflict.png b/conflict.png
|
||||
new file mode 100644
|
||||
index 0000000..7c77c7f
|
||||
--- /dev/null
|
||||
+++ b/conflict.png
|
||||
Binary files differ
|
||||
`;
|
||||
36
scm-ui/ui-components/src/__resources__/Diff.hunks.ts
Normal file
36
scm-ui/ui-components/src/__resources__/Diff.hunks.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
export default `diff --git a/src/main/java/com/cloudogu/scm/review/pullrequest/service/DefaultPullRequestService.java b/src/main/java/com/cloudogu/scm/review/pullrequest/service/DefaultPullRequestService.java
|
||||
index 17c35f6..cdf70f1 100644
|
||||
--- a/src/main/java/com/cloudogu/scm/review/pullrequest/service/DefaultPullRequestService.java
|
||||
+++ b/src/main/java/com/cloudogu/scm/review/pullrequest/service/DefaultPullRequestService.java
|
||||
@@ -25,6 +25,8 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
+import static com.cloudogu.scm.review.pullrequest.service.PullRequestApprovalEvent.ApprovalCause.APPROVAL_REMOVED;
|
||||
+import static com.cloudogu.scm.review.pullrequest.service.PullRequestApprovalEvent.ApprovalCause.APPROVED;
|
||||
import static com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.MERGED;
|
||||
import static com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.OPEN;
|
||||
import static com.cloudogu.scm.review.pullrequest.service.PullRequestStatus.REJECTED;
|
||||
@@ -200,6 +202,7 @@ public class DefaultPullRequestService implements PullRequestService {
|
||||
PullRequest pullRequest = getPullRequestFromStore(repository, pullRequestId);
|
||||
pullRequest.addApprover(user.getId());
|
||||
getStore(repository).update(pullRequest);
|
||||
+ eventBus.post(new PullRequestApprovalEvent(repository, pullRequest, APPROVED));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -211,8 +214,12 @@ public class DefaultPullRequestService implements PullRequestService {
|
||||
approver.stream()
|
||||
.filter(recipient -> user.getId().equals(recipient))
|
||||
.findFirst()
|
||||
- .ifPresent(pullRequest::removeApprover);
|
||||
- getStore(repository).update(pullRequest);
|
||||
+ .ifPresent(
|
||||
+ approval -> {
|
||||
+ pullRequest.removeApprover(approval);
|
||||
+ getStore(repository).update(pullRequest);
|
||||
+ eventBus.post(new PullRequestApprovalEvent(repository, pullRequest, APPROVAL_REMOVED));
|
||||
+ });
|
||||
}
|
||||
|
||||
@Override`;
|
||||
171
scm-ui/ui-components/src/__resources__/Diff.simple.ts
Normal file
171
scm-ui/ui-components/src/__resources__/Diff.simple.ts
Normal file
@@ -0,0 +1,171 @@
|
||||
export default `diff --git a/src/main/java/com/cloudogu/scm/review/events/EventListener.java b/src/main/java/com/cloudogu/scm/review/events/EventListener.java
|
||||
index f889f9c..95e3b10 100644
|
||||
--- a/src/main/java/com/cloudogu/scm/review/events/EventListener.java
|
||||
+++ b/src/main/java/com/cloudogu/scm/review/events/EventListener.java
|
||||
@@ -1,20 +1,12 @@
|
||||
package com.cloudogu.scm.review.events;
|
||||
|
||||
-import com.cloudogu.scm.review.comment.service.BasicComment;
|
||||
-import com.cloudogu.scm.review.comment.service.BasicCommentEvent;
|
||||
-import com.cloudogu.scm.review.comment.service.CommentEvent;
|
||||
-import com.cloudogu.scm.review.comment.service.ReplyEvent;
|
||||
import com.cloudogu.scm.review.pullrequest.service.BasicPullRequestEvent;
|
||||
import com.cloudogu.scm.review.pullrequest.service.PullRequest;
|
||||
-import com.cloudogu.scm.review.pullrequest.service.PullRequestEvent;
|
||||
import com.github.legman.Subscribe;
|
||||
-import lombok.Data;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.subject.PrincipalCollection;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import sonia.scm.EagerSingleton;
|
||||
-import sonia.scm.HandlerEventType;
|
||||
-import sonia.scm.event.HandlerEvent;
|
||||
import sonia.scm.plugin.Extension;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.security.SessionId;
|
||||
diff --git a/src/main/js/ChangeNotification.tsx b/src/main/js/ChangeNotification.tsx
|
||||
index f6d61a9..5f371e4 100644
|
||||
--- a/src/main/js/ChangeNotification.tsx
|
||||
+++ b/src/main/js/ChangeNotification.tsx
|
||||
@@ -2,6 +2,7 @@ import React, { FC, useEffect, useState } from "react";
|
||||
import { Link } from "@scm-manager/ui-types";
|
||||
import { apiClient, Toast, ToastButtons, ToastButton } from "@scm-manager/ui-components";
|
||||
import { PullRequest } from "./types/PullRequest";
|
||||
+import { useTranslation } from "react-i18next";
|
||||
|
||||
type HandlerProps = {
|
||||
url: string;
|
||||
@@ -15,14 +16,19 @@ const EventNotificationHandler: FC<HandlerProps> = ({ url, reload }) => {
|
||||
pullRequest: setEvent
|
||||
});
|
||||
}, [url]);
|
||||
+ const { t } = useTranslation("plugins");
|
||||
if (event) {
|
||||
return (
|
||||
- <Toast type="warning" title="New Changes">
|
||||
- <p>The underlying Pull-Request has changed. Press reload to see the changes.</p>
|
||||
- <p>Warning: Non saved modification will be lost.</p>
|
||||
+ <Toast type="warning" title={t("scm-review-plugin.changeNotification.title")}>
|
||||
+ <p>{t("scm-review-plugin.changeNotification.description")}</p>
|
||||
+ <p>{t("scm-review-plugin.changeNotification.modificationWarning")}</p>
|
||||
<ToastButtons>
|
||||
- <ToastButton icon="redo" onClick={reload}>Reload</ToastButton>
|
||||
- <ToastButton icon="times" onClick={() => setEvent(undefined)}>Ignore</ToastButton>
|
||||
+ <ToastButton icon="redo" onClick={reload}>
|
||||
+ {t("scm-review-plugin.changeNotification.buttons.reload")}
|
||||
+ </ToastButton>
|
||||
+ <ToastButton icon="times" onClick={() => setEvent(undefined)}>
|
||||
+ {t("scm-review-plugin.changeNotification.buttons.ignore")}
|
||||
+ </ToastButton>
|
||||
</ToastButtons>
|
||||
</Toast>
|
||||
);
|
||||
diff --git a/src/main/resources/locales/de/plugins.json b/src/main/resources/locales/de/plugins.json
|
||||
index 80f84a1..2c63ab3 100644
|
||||
--- a/src/main/resources/locales/de/plugins.json
|
||||
+++ b/src/main/resources/locales/de/plugins.json
|
||||
@@ -181,6 +181,15 @@
|
||||
"titleClickable": "Der Kommentar bezieht sich auf eine ältere Version des Source- oder Target-Branches. Klicken Sie hier, um den ursprünglichen Kontext zu sehen."
|
||||
}
|
||||
}
|
||||
+ },
|
||||
+ "changeNotification": {
|
||||
+ "title": "Neue Änderungen",
|
||||
+ "description": "An diesem Pull Request wurden Änderungen vorgenommen. Laden Sie die Seite neu um diese anzuzeigen.",
|
||||
+ "modificationWarning": "Warnung: Nicht gespeicherte Eingaben gehen verloren.",
|
||||
+ "buttons": {
|
||||
+ "reload": "Neu laden",
|
||||
+ "ignore": "Ignorieren"
|
||||
+ }
|
||||
}
|
||||
},
|
||||
"permissions": {
|
||||
diff --git a/src/main/resources/locales/en/plugins.json b/src/main/resources/locales/en/plugins.json
|
||||
index d020fcd..e3c1630 100644
|
||||
--- a/src/main/resources/locales/en/plugins.json
|
||||
+++ b/src/main/resources/locales/en/plugins.json
|
||||
@@ -181,6 +181,15 @@
|
||||
"titleClickable": "The comment is related to an older of the source or target branch. Click here to see the original context."
|
||||
}
|
||||
}
|
||||
+ },
|
||||
+ "changeNotification": {
|
||||
+ "title": "New Changes",
|
||||
+ "description": "The underlying Pull-Request has changed. Press reload to see the changes.",
|
||||
+ "modificationWarning": "Warning: Non saved modification will be lost.",
|
||||
+ "buttons": {
|
||||
+ "reload": "Reload",
|
||||
+ "ignore": "Ignore"
|
||||
+ }
|
||||
}
|
||||
},
|
||||
"permissions": {
|
||||
diff --git a/src/test/java/com/cloudogu/scm/review/events/ClientTest.java b/src/test/java/com/cloudogu/scm/review/events/ClientTest.java
|
||||
index 889cc49..d5a4811 100644
|
||||
--- a/src/test/java/com/cloudogu/scm/review/events/ClientTest.java
|
||||
+++ b/src/test/java/com/cloudogu/scm/review/events/ClientTest.java
|
||||
@@ -7,19 +7,16 @@ import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import sonia.scm.security.SessionId;
|
||||
+
|
||||
import javax.ws.rs.sse.OutboundSseEvent;
|
||||
import javax.ws.rs.sse.SseEventSink;
|
||||
-
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.temporal.ChronoField;
|
||||
-import java.time.temporal.ChronoUnit;
|
||||
-import java.time.temporal.TemporalField;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
-import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static java.time.temporal.ChronoUnit.MINUTES;
|
||||
@@ -83,7 +80,7 @@ class ClientTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
- void shouldCloseEventSinkOnFailure() throws InterruptedException {
|
||||
+ void shouldCloseEventSinkOnFailure() {
|
||||
CompletionStage future = CompletableFuture.supplyAsync(() -> {
|
||||
throw new RuntimeException("failed to send message");
|
||||
});
|
||||
@@ -91,9 +88,7 @@ class ClientTest {
|
||||
|
||||
client.send(message);
|
||||
|
||||
- Thread.sleep(50L);
|
||||
-
|
||||
- verify(eventSink).close();
|
||||
+ verify(eventSink, timeout(50L)).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
diff --git a/Main.java b/Main.java
|
||||
index e77e6da..f183b7c 100644
|
||||
--- a/Main.java
|
||||
+++ b/Main.java
|
||||
@@ -1,9 +1,18 @@
|
||||
+import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
|
||||
class Main {
|
||||
+ private static final PrintStream OUT = System.out;
|
||||
+
|
||||
public static void main(String[] args) {
|
||||
+<<<<<<< HEAD
|
||||
System.out.println("Expect nothing more to happen.");
|
||||
System.out.println("The command line parameters are:");
|
||||
Arrays.stream(args).map(arg -> "- " + arg).forEach(System.out::println);
|
||||
+=======
|
||||
+ OUT.println("Expect nothing more to happen.");
|
||||
+ OUT.println("Parameters:");
|
||||
+ Arrays.stream(args).map(arg -> "- " + arg).forEach(OUT::println);
|
||||
+>>>>>>> feature/use_constant
|
||||
}
|
||||
}
|
||||
`;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,6 @@ import React, { ReactNode } from "react";
|
||||
import Button from "./Button";
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import styled from "styled-components";
|
||||
import { MemoryRouter } from "react-router-dom";
|
||||
import AddButton from "./AddButton";
|
||||
import CreateButton from "./CreateButton";
|
||||
import DeleteButton from "./DeleteButton";
|
||||
@@ -17,14 +16,9 @@ const Spacing = styled.div`
|
||||
padding: 1em;
|
||||
`;
|
||||
|
||||
type StoryFn = () => ReactNode;
|
||||
|
||||
const RoutingDecorator = (story: StoryFn) => <MemoryRouter initialEntries={["/"]}>{story()}</MemoryRouter>;
|
||||
|
||||
const SpacingDecorator = (story: StoryFn) => <Spacing>{story()}</Spacing>;
|
||||
const SpacingDecorator = (story: () => ReactNode) => <Spacing>{story()}</Spacing>;
|
||||
|
||||
storiesOf("Buttons|Button", module)
|
||||
.addDecorator(RoutingDecorator)
|
||||
.add("Colors", () => (
|
||||
<div>
|
||||
{colors.map(color => (
|
||||
@@ -44,7 +38,6 @@ storiesOf("Buttons|Button", module)
|
||||
|
||||
const buttonStory = (name: string, storyFn: () => ReactElement) => {
|
||||
return storiesOf("Buttons|" + name, module)
|
||||
.addDecorator(RoutingDecorator)
|
||||
.addDecorator(SpacingDecorator)
|
||||
.add("Default", storyFn);
|
||||
};
|
||||
@@ -53,7 +46,7 @@ buttonStory("CreateButton", () => <CreateButton>Create</CreateButton>);
|
||||
buttonStory("DeleteButton", () => <DeleteButton>Delete</DeleteButton>);
|
||||
buttonStory("DownloadButton", () => <DownloadButton displayName="Download" disabled={false} url="" />).add(
|
||||
"Disabled",
|
||||
() => <DownloadButton displayName="Download" disabled={true} url=""></DownloadButton>
|
||||
() => <DownloadButton displayName="Download" disabled={true} url="" />
|
||||
);
|
||||
buttonStory("EditButton", () => <EditButton>Edit</EditButton>);
|
||||
buttonStory("SubmitButton", () => <SubmitButton>Submit</SubmitButton>);
|
||||
|
||||
60
scm-ui/ui-components/src/repos/Diff.stories.tsx
Normal file
60
scm-ui/ui-components/src/repos/Diff.stories.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { storiesOf } from "@storybook/react";
|
||||
import Diff from "./Diff";
|
||||
// @ts-ignore
|
||||
import parser from "gitdiff-parser";
|
||||
import simpleDiff from "../__resources__/Diff.simple";
|
||||
import hunksDiff from "../__resources__/Diff.hunks";
|
||||
import binaryDiff from "../__resources__/Diff.binary";
|
||||
import Button from "../buttons/Button";
|
||||
import { DiffEventContext } from "./DiffTypes";
|
||||
import Toast from "../toast/Toast";
|
||||
|
||||
const diffFiles = parser.parse(simpleDiff);
|
||||
|
||||
storiesOf("Diff", module)
|
||||
.add("Default", () => <Diff diff={diffFiles} />)
|
||||
.add("Side-By-Side", () => <Diff diff={diffFiles} sideBySide={true} />)
|
||||
.add("Collapsed", () => <Diff diff={diffFiles} defaultCollapse={true} />)
|
||||
.add("File Controls", () => <Diff diff={diffFiles} fileControlFactory={() => <Button>Custom Control</Button>} />)
|
||||
.add("File Annotation", () => (
|
||||
<Diff
|
||||
diff={diffFiles}
|
||||
fileAnnotationFactory={file => [<p key={file.newPath}>Custom File annotation for {file.newPath}</p>]}
|
||||
/>
|
||||
))
|
||||
.add("Line Annotation", () => (
|
||||
<Diff
|
||||
diff={diffFiles}
|
||||
annotationFactory={ctx => {
|
||||
return {
|
||||
N2: <p key="N2">Line Annotation</p>
|
||||
};
|
||||
}}
|
||||
/>
|
||||
))
|
||||
.add("OnClick", () => {
|
||||
const OnClickDemo = () => {
|
||||
const [changeId, setChangeId] = useState();
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => setChangeId(undefined), 2000);
|
||||
return () => clearInterval(interval);
|
||||
});
|
||||
const onClick = (context: DiffEventContext) => setChangeId(context.changeId);
|
||||
return (
|
||||
<>
|
||||
{changeId && <Toast type="info" title={"Change " + changeId} />}
|
||||
<Diff diff={diffFiles} onClick={onClick} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
return <OnClickDemo />;
|
||||
})
|
||||
.add("Hunks", () => {
|
||||
const hunkDiffFiles = parser.parse(hunksDiff);
|
||||
return <Diff diff={hunkDiffFiles} />;
|
||||
})
|
||||
.add("Binaries", () => {
|
||||
const binaryDiffFiles = parser.parse(binaryDiff);
|
||||
return <Diff diff={binaryDiffFiles} />;
|
||||
});
|
||||
@@ -3,11 +3,13 @@ import { withTranslation, WithTranslation } from "react-i18next";
|
||||
import classNames from "classnames";
|
||||
import styled from "styled-components";
|
||||
// @ts-ignore
|
||||
import { Change, Diff as DiffComponent, getChangeKey, Hunk } from "react-diff-view";
|
||||
import { Diff as DiffComponent, getChangeKey, Hunk, Decoration } from "react-diff-view";
|
||||
import { Button, ButtonGroup } from "../buttons";
|
||||
import Tag from "../Tag";
|
||||
import Icon from "../Icon";
|
||||
import { File, Hunk as HunkType, DiffObjectProps } from "./DiffTypes";
|
||||
import { ChangeEvent, Change, File, Hunk as HunkType, DiffObjectProps } from "./DiffTypes";
|
||||
|
||||
const EMPTY_ANNOTATION_FACTORY = {};
|
||||
|
||||
type Props = DiffObjectProps &
|
||||
WithTranslation & {
|
||||
@@ -20,7 +22,7 @@ type Collapsible = {
|
||||
};
|
||||
|
||||
type State = Collapsible & {
|
||||
sideBySide: boolean;
|
||||
sideBySide?: boolean;
|
||||
};
|
||||
|
||||
const DiffFilePanel = styled.div`
|
||||
@@ -56,6 +58,10 @@ const ChangeTypeTag = styled(Tag)`
|
||||
`;
|
||||
|
||||
const ModifiedDiffComponent = styled(DiffComponent)`
|
||||
/* align line numbers */
|
||||
& .diff-gutter {
|
||||
text-align: right;
|
||||
}
|
||||
/* column sizing */
|
||||
> colgroup .diff-gutter-col {
|
||||
width: 3.25rem;
|
||||
@@ -80,14 +86,15 @@ const ModifiedDiffComponent = styled(DiffComponent)`
|
||||
|
||||
class DiffFile extends React.Component<Props, State> {
|
||||
static defaultProps: Partial<Props> = {
|
||||
defaultCollapse: false
|
||||
defaultCollapse: false,
|
||||
markConflicts: true
|
||||
};
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
collapsed: !!this.props.defaultCollapse,
|
||||
sideBySide: false
|
||||
sideBySide: props.sideBySide
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,7 +110,7 @@ class DiffFile extends React.Component<Props, State> {
|
||||
|
||||
toggleCollapse = () => {
|
||||
const { file } = this.props;
|
||||
if (file && !file.isBinary) {
|
||||
if (this.hasContent(file)) {
|
||||
this.setState(state => ({
|
||||
collapsed: !state.collapsed
|
||||
}));
|
||||
@@ -126,7 +133,8 @@ class DiffFile extends React.Component<Props, State> {
|
||||
if (i > 0) {
|
||||
return <HunkDivider />;
|
||||
}
|
||||
return null;
|
||||
// hunk header must be defined
|
||||
return <span />;
|
||||
};
|
||||
|
||||
collectHunkAnnotations = (hunk: HunkType) => {
|
||||
@@ -136,6 +144,8 @@ class DiffFile extends React.Component<Props, State> {
|
||||
hunk,
|
||||
file
|
||||
});
|
||||
} else {
|
||||
return EMPTY_ANNOTATION_FACTORY;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -152,29 +162,45 @@ class DiffFile extends React.Component<Props, State> {
|
||||
}
|
||||
};
|
||||
|
||||
createCustomEvents = (hunk: HunkType) => {
|
||||
createGutterEvents = (hunk: HunkType) => {
|
||||
const { onClick } = this.props;
|
||||
if (onClick) {
|
||||
return {
|
||||
gutter: {
|
||||
onClick: (change: Change) => {
|
||||
this.handleClickEvent(change, hunk);
|
||||
}
|
||||
onClick: (event: ChangeEvent) => {
|
||||
this.handleClickEvent(event.change, hunk);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
renderHunk = (hunk: HunkType, i: number) => {
|
||||
return (
|
||||
if (this.props.markConflicts && hunk.changes) {
|
||||
this.markConflicts(hunk);
|
||||
}
|
||||
return [
|
||||
<Decoration key={"decoration-" + hunk.content}>{this.createHunkHeader(hunk, i)}</Decoration>,
|
||||
<Hunk
|
||||
key={hunk.content}
|
||||
key={"hunk-" + hunk.content}
|
||||
hunk={hunk}
|
||||
header={this.createHunkHeader(hunk, i)}
|
||||
widgets={this.collectHunkAnnotations(hunk)}
|
||||
customEvents={this.createCustomEvents(hunk)}
|
||||
gutterEvents={this.createGutterEvents(hunk)}
|
||||
/>
|
||||
);
|
||||
];
|
||||
};
|
||||
|
||||
markConflicts = (hunk: HunkType) => {
|
||||
let inConflict = false;
|
||||
for (let i = 0; i < hunk.changes.length; ++i) {
|
||||
if (hunk.changes[i].content === "<<<<<<< HEAD") {
|
||||
inConflict = true;
|
||||
}
|
||||
if (inConflict) {
|
||||
hunk.changes[i].type = "conflict";
|
||||
}
|
||||
if (hunk.changes[i].content.startsWith(">>>>>>>")) {
|
||||
inConflict = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
renderFileTitle = (file: File) => {
|
||||
@@ -215,6 +241,16 @@ class DiffFile extends React.Component<Props, State> {
|
||||
return <ChangeTypeTag className={classNames("is-rounded", "has-text-weight-normal")} color={color} label={value} />;
|
||||
};
|
||||
|
||||
concat = (array: object[][]) => {
|
||||
if (array.length > 0) {
|
||||
return array.reduce((a, b) => a.concat(b));
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
hasContent = (file: File) => file && !file.isBinary && file.hunks && file.hunks.length > 0;
|
||||
|
||||
render() {
|
||||
const { file, fileControlFactory, fileAnnotationFactory, t } = this.props;
|
||||
const { collapsed, sideBySide } = this.state;
|
||||
@@ -228,13 +264,13 @@ class DiffFile extends React.Component<Props, State> {
|
||||
body = (
|
||||
<div className="panel-block is-paddingless">
|
||||
{fileAnnotations}
|
||||
<ModifiedDiffComponent className={viewType} viewType={viewType}>
|
||||
{file.hunks.map(this.renderHunk)}
|
||||
<ModifiedDiffComponent className={viewType} viewType={viewType} hunks={file.hunks} diffType={file.type}>
|
||||
{(hunks: HunkType[]) => this.concat(hunks.map(this.renderHunk))}
|
||||
</ModifiedDiffComponent>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const collapseIcon = file && !file.isBinary ? <Icon name={icon} color="inherit" /> : null;
|
||||
const collapseIcon = this.hasContent(file) ? <Icon name={icon} color="inherit" /> : null;
|
||||
|
||||
const fileControls = fileControlFactory ? fileControlFactory(file, this.setCollapse) : null;
|
||||
return (
|
||||
|
||||
@@ -27,7 +27,7 @@ export type Hunk = {
|
||||
content: string;
|
||||
};
|
||||
|
||||
export type ChangeType = "insert" | "delete" | "normal";
|
||||
export type ChangeType = "insert" | "delete" | "normal" | "conflict";
|
||||
|
||||
export type Change = {
|
||||
content: string;
|
||||
@@ -40,6 +40,10 @@ export type Change = {
|
||||
type: ChangeType;
|
||||
};
|
||||
|
||||
export type ChangeEvent = {
|
||||
change: Change;
|
||||
};
|
||||
|
||||
export type BaseContext = {
|
||||
hunk: Hunk;
|
||||
file: File;
|
||||
@@ -66,9 +70,10 @@ export type DiffEventHandler = (context: DiffEventContext) => void;
|
||||
export type FileControlFactory = (file: File, setCollapseState: (p: boolean) => void) => ReactNode | null | undefined;
|
||||
|
||||
export type DiffObjectProps = {
|
||||
sideBySide: boolean;
|
||||
sideBySide?: boolean;
|
||||
onClick?: DiffEventHandler;
|
||||
fileControlFactory?: FileControlFactory;
|
||||
fileAnnotationFactory?: FileAnnotationFactory;
|
||||
annotationFactory?: AnnotationFactory;
|
||||
markConflicts?: boolean;
|
||||
};
|
||||
|
||||
@@ -9,12 +9,13 @@ import Diff from "./Diff";
|
||||
import { DiffObjectProps, File } from "./DiffTypes";
|
||||
import { NotFoundError } from "../errors";
|
||||
import { Notification } from "../index";
|
||||
import {withTranslation, WithTranslation} from "react-i18next";
|
||||
import { withTranslation, WithTranslation } from "react-i18next";
|
||||
|
||||
type Props = WithTranslation & DiffObjectProps & {
|
||||
url: string;
|
||||
defaultCollapse?: boolean;
|
||||
};
|
||||
type Props = WithTranslation &
|
||||
DiffObjectProps & {
|
||||
url: string;
|
||||
defaultCollapse?: boolean;
|
||||
};
|
||||
|
||||
type State = {
|
||||
diff?: File[];
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
import path from "path";
|
||||
import initStoryshots from "@storybook/addon-storyshots";
|
||||
import initStoryshots, { snapshotWithOptions } from "@storybook/addon-storyshots";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const createNodeMock = (element: any) => {
|
||||
if (element.type === "tr") {
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
querySelector: (selector: string) => {}
|
||||
};
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
initStoryshots({
|
||||
configPath: path.resolve(__dirname, "..", ".storybook")
|
||||
configPath: path.resolve(__dirname, "..", ".storybook"),
|
||||
// fix snapshot tests with react-diff-view which uses a ref on tr
|
||||
// @see https://github.com/storybookjs/storybook/pull/1090
|
||||
test: snapshotWithOptions({
|
||||
createNodeMock
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user