mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
Remove expand marker at bottom when fully expanded
This commit is contained in:
@@ -239,6 +239,18 @@ describe("with hunks the diff expander", () => {
|
|||||||
expect(newFile.hunks[1].changes[5].oldLineNumber).toBe(14);
|
expect(newFile.hunks[1].changes[5].oldLineNumber).toBe(14);
|
||||||
expect(newFile.hunks[1].changes[5].newLineNumber).toBe(14);
|
expect(newFile.hunks[1].changes[5].newLineNumber).toBe(14);
|
||||||
});
|
});
|
||||||
|
it("should set fully expanded to true if expanded completely", async () => {
|
||||||
|
fetchMock.get(
|
||||||
|
"http://localhost:8081/scm/api/v2/content/abc/CommitMessage.js?start=40&end=50",
|
||||||
|
"new line 40\nnew line 41\nnew line 42"
|
||||||
|
);
|
||||||
|
let newFile;
|
||||||
|
diffExpander.getHunk(3).expandBottom(10, file => {
|
||||||
|
newFile = file;
|
||||||
|
});
|
||||||
|
await fetchMock.flush(true);
|
||||||
|
expect(newFile.hunks[3].fullyExpanded).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("for a new file with text input the diff expander", () => {
|
describe("for a new file with text input the diff expander", () => {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class DiffExpander {
|
|||||||
if (this.file.type === "add" || this.file.type === "delete") {
|
if (this.file.type === "add" || this.file.type === "delete") {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (n === this.file!.hunks!.length - 1) {
|
} else if (n === this.file!.hunks!.length - 1) {
|
||||||
return Number.MAX_SAFE_INTEGER;
|
return this.file!.hunks![this.file!.hunks!.length - 1].fullyExpanded ? 0 : Number.MAX_SAFE_INTEGER;
|
||||||
}
|
}
|
||||||
return this.minLineNumber(n + 1) - this.maxLineNumber(n) - 1;
|
return this.minLineNumber(n + 1) - this.maxLineNumber(n) - 1;
|
||||||
};
|
};
|
||||||
@@ -85,7 +85,7 @@ class DiffExpander {
|
|||||||
.get(lineRequestUrl)
|
.get(lineRequestUrl)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(text => text.split("\n"))
|
.then(text => text.split("\n"))
|
||||||
.then(lines => this.expandHunkAtBottom(n, lines, callback));
|
.then(lines => this.expandHunkAtBottom(n, count, lines, callback));
|
||||||
};
|
};
|
||||||
|
|
||||||
expandHunkAtHead = (n: number, lines: string[], callback: (newFile: File) => void) => {
|
expandHunkAtHead = (n: number, lines: string[], callback: (newFile: File) => void) => {
|
||||||
@@ -130,7 +130,7 @@ class DiffExpander {
|
|||||||
callback(newFile);
|
callback(newFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
expandHunkAtBottom = (n: number, lines: string[], callback: (newFile: File) => void) => {
|
expandHunkAtBottom = (n: number, requestedLines: number, lines: string[], callback: (newFile: File) => void) => {
|
||||||
const hunk = this.file.hunks![n];
|
const hunk = this.file.hunks![n];
|
||||||
if (lines[lines.length - 1] === "") {
|
if (lines[lines.length - 1] === "") {
|
||||||
lines.pop();
|
lines.pop();
|
||||||
@@ -155,7 +155,8 @@ class DiffExpander {
|
|||||||
...hunk,
|
...hunk,
|
||||||
oldLines: hunk.oldLines + lines.length,
|
oldLines: hunk.oldLines + lines.length,
|
||||||
newLines: hunk.newLines + lines.length,
|
newLines: hunk.newLines + lines.length,
|
||||||
changes: newChanges
|
changes: newChanges,
|
||||||
|
fullyExpanded: lines.length < requestedLines
|
||||||
};
|
};
|
||||||
const newHunks: Hunk[] = [];
|
const newHunks: Hunk[] = [];
|
||||||
this.file.hunks.forEach((oldHunk: Hunk, i: number) => {
|
this.file.hunks.forEach((oldHunk: Hunk, i: number) => {
|
||||||
|
|||||||
@@ -211,6 +211,25 @@ class DiffFile extends React.Component<Props, State> {
|
|||||||
return <span />;
|
return <span />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
createLastHunkFooter = (expandableHunk: ExpandableHunk) => {
|
||||||
|
if (expandableHunk.maxExpandBottomRange > 0) {
|
||||||
|
return (
|
||||||
|
<Decoration>
|
||||||
|
<HunkDivider>
|
||||||
|
<span onClick={() => expandableHunk.expandBottom(10, this.diffExpanded)}>
|
||||||
|
{this.props.t("diff.expandLastBottomByLines")}
|
||||||
|
</span>{" "}
|
||||||
|
<span onClick={() => expandableHunk.expandBottom(expandableHunk.maxExpandBottomRange, this.diffExpanded)}>
|
||||||
|
{this.props.t("diff.expandLastBottomComplete")}
|
||||||
|
</span>
|
||||||
|
</HunkDivider>
|
||||||
|
</Decoration>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// hunk header must be defined
|
||||||
|
return <span />;
|
||||||
|
};
|
||||||
|
|
||||||
collectHunkAnnotations = (hunk: HunkType) => {
|
collectHunkAnnotations = (hunk: HunkType) => {
|
||||||
const { annotationFactory } = this.props;
|
const { annotationFactory } = this.props;
|
||||||
const { file } = this.state;
|
const { file } = this.state;
|
||||||
@@ -267,7 +286,11 @@ class DiffFile extends React.Component<Props, State> {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
if (file._links?.lines) {
|
if (file._links?.lines) {
|
||||||
items.push(this.createHunkFooter(expandableHunk));
|
if (i === file.hunks!.length - 1) {
|
||||||
|
items.push(this.createLastHunkFooter(expandableHunk));
|
||||||
|
} else {
|
||||||
|
items.push(this.createHunkFooter(expandableHunk));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items;
|
return items;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ export type Hunk = {
|
|||||||
newStart?: number;
|
newStart?: number;
|
||||||
oldLines?: number;
|
oldLines?: number;
|
||||||
newLines?: number;
|
newLines?: number;
|
||||||
|
fullyExpanded?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ChangeType = "insert" | "delete" | "normal" | "conflict";
|
export type ChangeType = "insert" | "delete" | "normal" | "conflict";
|
||||||
|
|||||||
@@ -206,7 +206,9 @@
|
|||||||
"expandBottomByLines": "> load {{count}} more line",
|
"expandBottomByLines": "> load {{count}} more line",
|
||||||
"expandBottomByLines_plural": "> load {{count}} more lines",
|
"expandBottomByLines_plural": "> load {{count}} more lines",
|
||||||
"expandBottomComplete": ">> load {{count}} line",
|
"expandBottomComplete": ">> load {{count}} line",
|
||||||
"expandBottomComplete_plural": ">> load all {{count}} lines"
|
"expandBottomComplete_plural": ">> load all {{count}} lines",
|
||||||
|
"expandLastBottomByLines": "> load up to 10 more lines",
|
||||||
|
"expandLastBottomComplete": ">> load all remaining lines"
|
||||||
},
|
},
|
||||||
"fileUpload": {
|
"fileUpload": {
|
||||||
"clickHere": "Click here to select your file",
|
"clickHere": "Click here to select your file",
|
||||||
|
|||||||
Reference in New Issue
Block a user