Initiatives: add URLs to remote files in node descriptions (#1670)

Small UI improvement, making it easier to inspect and reference initiatives.
This commit is contained in:
Robin van Boven 2020-02-28 04:58:04 -07:00 committed by GitHub
parent 57f66c50b6
commit 1f41fc3003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 3 deletions

View File

@ -18,16 +18,20 @@ import {
contributesToEdgeType,
championsEdgeType,
} from "./declaration";
import {initiativeFileURL} from "./initiativesDirectory";
function initiativeAddress(initiative: Initiative): NodeAddressT {
return addressFromId(initiative.id);
}
function initiativeNode(initiative: Initiative): Node {
const address = initiativeAddress(initiative);
const url = initiativeFileURL(address);
return {
address: initiativeAddress(initiative),
address,
timestampMs: initiative.timestampMs,
description: initiative.title,
description:
url == null ? initiative.title : `[${initiative.title}](${url})`,
};
}

View File

@ -8,7 +8,7 @@ import {
} from "../../core/graph";
import type {ReferenceDetector, URL} from "../../core/references";
import type {Initiative, InitiativeRepository} from "./initiative";
import {createId} from "./initiative";
import {createId, addressFromId} from "./initiative";
import {createGraph} from "./createGraph";
import {
initiativeNodeType,
@ -135,6 +135,25 @@ describe("plugins/initiatives/createGraph", () => {
]);
});
it("should add initiative file urls to the description", () => {
// Given
const {repo, refs} = example();
const remoteUrl = "http://foo.bar/dir";
const fileName = "sample.json";
const id = createId("INITIATIVE_FILE", remoteUrl, fileName);
const addres = addressFromId(id);
repo.addInitiative({id});
// When
const graph = createGraph(repo, refs);
// Then
const node = graph.node(addres);
expect(node).toMatchObject({
description: `[Example Initiative 1](${remoteUrl}/${fileName})`,
});
});
describe("reference detection attempts", () => {
it("should attempt to resolve dependency URLs", () => {
// Given