mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
Implement option to load rest of files completely
This commit is contained in:
@@ -199,7 +199,7 @@ describe("with hunks the diff expander", () => {
|
||||
});
|
||||
|
||||
it("should return a really bix number for the expand bottom range of the last hunk", () => {
|
||||
expect(diffExpander.getHunk(3).maxExpandBottomRange).toBeGreaterThan(99999);
|
||||
expect(diffExpander.getHunk(3).maxExpandBottomRange).toBe(-1);
|
||||
});
|
||||
it("should expand hunk with new line from api client at the bottom", async () => {
|
||||
expect(diffExpander.getHunk(1).hunk.changes.length).toBe(7);
|
||||
@@ -251,6 +251,18 @@ describe("with hunks the diff expander", () => {
|
||||
await fetchMock.flush(true);
|
||||
expect(newFile.hunks[3].fullyExpanded).toBe(true);
|
||||
});
|
||||
it("should set end to -1 if requested to expand to the end", async () => {
|
||||
fetchMock.get(
|
||||
"http://localhost:8081/scm/api/v2/content/abc/CommitMessage.js?start=40&end=-1",
|
||||
"new line 40\nnew line 41\nnew line 42"
|
||||
);
|
||||
let newFile;
|
||||
diffExpander.getHunk(3).expandBottom(-1, 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", () => {
|
||||
|
||||
@@ -61,7 +61,7 @@ class DiffExpander {
|
||||
if (this.file.type === "add" || this.file.type === "delete") {
|
||||
return 0;
|
||||
} else if (n === this.file!.hunks!.length - 1) {
|
||||
return this.file!.hunks![this.file!.hunks!.length - 1].fullyExpanded ? 0 : Number.MAX_SAFE_INTEGER;
|
||||
return this.file!.hunks![this.file!.hunks!.length - 1].fullyExpanded ? 0 : -1;
|
||||
}
|
||||
return this.minLineNumber(n + 1) - this.maxLineNumber(n) - 1;
|
||||
};
|
||||
@@ -78,9 +78,10 @@ class DiffExpander {
|
||||
};
|
||||
|
||||
expandBottom = (n: number, count: number, callback: (newFile: File) => void) => {
|
||||
const maxExpandBottomRange = this.computeMaxExpandBottomRange(n);
|
||||
const lineRequestUrl = this.file._links.lines.href
|
||||
.replace("{start}", this.maxLineNumber(n))
|
||||
.replace("{end}", this.maxLineNumber(n) + Math.min(count, this.computeMaxExpandBottomRange(n)));
|
||||
.replace("{end}", count > 0 ? this.maxLineNumber(n) + Math.min(count, maxExpandBottomRange > 0? maxExpandBottomRange:Number.MAX_SAFE_INTEGER) : -1);
|
||||
apiClient
|
||||
.get(lineRequestUrl)
|
||||
.then(response => response.text())
|
||||
@@ -156,7 +157,7 @@ class DiffExpander {
|
||||
oldLines: hunk.oldLines + lines.length,
|
||||
newLines: hunk.newLines + lines.length,
|
||||
changes: newChanges,
|
||||
fullyExpanded: lines.length < requestedLines
|
||||
fullyExpanded: requestedLines < 0 || lines.length < requestedLines
|
||||
};
|
||||
const newHunks: Hunk[] = [];
|
||||
this.file.hunks.forEach((oldHunk: Hunk, i: number) => {
|
||||
|
||||
@@ -212,7 +212,7 @@ class DiffFile extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
createLastHunkFooter = (expandableHunk: ExpandableHunk) => {
|
||||
if (expandableHunk.maxExpandBottomRange > 0) {
|
||||
if (expandableHunk.maxExpandBottomRange != 0) {
|
||||
return (
|
||||
<Decoration>
|
||||
<HunkDivider>
|
||||
|
||||
Reference in New Issue
Block a user