Skip to content

Commit 41dddc7

Browse files
authored
File Tree Diff: updates to UI (info and PR link) (#551)
This is what I understood we agreed on in our meetting. [Peek 2025-02-20 11-45.webm](https://github.com/user-attachments/assets/904062f9-aeb3-4662-abf7-6037a5e5e3bd) * Closes #549 * Closes #548 ## ToDo - [x] add tests - [x] require build URL in data validation
1 parent d2d7f7b commit 41dddc7

File tree

6 files changed

+77
-2
lines changed

6 files changed

+77
-2
lines changed

src/data-validation.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,17 @@ const addons_filetreediff = {
291291
properties: {
292292
current: {
293293
type: "object",
294-
required: ["type"],
294+
required: ["type", "slug", "urls"],
295295
properties: {
296296
type: { type: "string" },
297+
slug: { type: "string" },
298+
urls: {
299+
type: "object",
300+
required: ["vcs"],
301+
properties: {
302+
vcs: { type: "string" },
303+
},
304+
},
297305
},
298306
},
299307
},

src/filetreediff.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@
7676
min-width: 2.5rem;
7777
}
7878

79+
:host > div > div > a {
80+
width: 0.8rem;
81+
color: var(--addons-filetreediff-color);
82+
}
83+
84+
:host > div > div > a.version {
85+
width: auto;
86+
text-decoration: none;
87+
color: var(--readthedocs-filetreediff-chunks-color, #27ae60);
88+
}
89+
7990
/* Expand to full width on smaller screens */
8091
@media (max-width: 768px) {
8192
:host > div {

src/filetreediff.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { library, icon } from "@fortawesome/fontawesome-svg-core";
2-
import { faArrowUp, faArrowDown } from "@fortawesome/free-solid-svg-icons";
2+
import {
3+
faArrowUp,
4+
faArrowDown,
5+
faCircleInfo,
6+
} from "@fortawesome/free-solid-svg-icons";
37
import { html, nothing, LitElement } from "lit";
48
import { default as objectPath } from "object-path";
59
import styleSheet from "./filetreediff.css";
@@ -43,6 +47,9 @@ export class FileTreeDiffElement extends LitElement {
4347
this.iconArrowDown = icon(faArrowDown, {
4448
classes: ["icon"],
4549
});
50+
this.iconCircleInfo = icon(faCircleInfo, {
51+
classes: ["icon"],
52+
});
4653
}
4754

4855
loadConfig(config) {
@@ -202,6 +209,19 @@ export class FileTreeDiffElement extends LitElement {
202209
${renderSection(diffData.added, "Added")}
203210
${renderSection(diffData.modified, "Changed")}
204211
</select>
212+
<a
213+
href="${this.config.versions.current.urls.vcs}"
214+
title="Go to pull request"
215+
target="_blank"
216+
class="version"
217+
>#${this.config.versions.current.slug}</a
218+
>
219+
<a
220+
href="https://docs.readthedocs.com/platform/stable/visual-diff.html"
221+
title="Open documentation"
222+
target="_blank"
223+
>${this.iconCircleInfo.node[0]}</a
224+
>
205225
</div>
206226
</div>
207227
`;

tests/__snapshots__/filetreediff.test.snap.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ snapshots["Filetreediff tests snapshot filetreediff completely"] =
2727
</option>
2828
</optgroup>
2929
</select>
30+
<a
31+
class="version"
32+
href="https://github.com/organization/repository/pull/1234/"
33+
target="_blank"
34+
title="Go to pull request"
35+
>
36+
#1234
37+
</a>
38+
<a
39+
href="https://docs.readthedocs.com/platform/stable/visual-diff.html"
40+
target="_blank"
41+
title="Open documentation"
42+
>
43+
</a>
3044
</div>
3145
</div>
3246
`;
@@ -66,6 +80,20 @@ snapshots["Filetreediff tests toggle Show diff checkbox"] =
6680
</option>
6781
</optgroup>
6882
</select>
83+
<a
84+
class="version"
85+
href="https://github.com/organization/repository/pull/1234/"
86+
target="_blank"
87+
title="Go to pull request"
88+
>
89+
#1234
90+
</a>
91+
<a
92+
href="https://docs.readthedocs.com/platform/stable/visual-diff.html"
93+
target="_blank"
94+
title="Open documentation"
95+
>
96+
</a>
6997
</div>
7098
</div>
7199
`;

tests/filetreediff.test.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
versions: {
1919
current: {
2020
type: "external",
21+
slug: "1234",
22+
urls: {
23+
vcs: "https://github.com/organization/repository/pull/1234/",
24+
},
2125
},
2226
},
2327
addons: {

tests/filetreediff.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ describe("FileTreeDiff addon", () => {
5353
versions: {
5454
current: {
5555
type: "external",
56+
slug: "1234",
57+
urls: {
58+
vcs: "https://github.com/organization/repository/pull/1234/",
59+
},
5660
},
5761
},
5862
}),

0 commit comments

Comments
 (0)