Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend curie expansion experiment #653

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified frontend/bun.lockb
100644 → 100755
Binary file not shown.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"test:e2e": "playwright test"
},
"dependencies": {
"@biopragmatics/curies": "^0.1.1",
"@floating-ui/dom": "^1.6.3",
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-brands-svg-icons": "^6.5.1",
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import "wicg-inert";
import "@/global/icons";
import "@/global/meta";
import "normalize.css";
import "@/global/styles.scss"; /** keep these last so they take priority */
import "@/global/styles.scss";
import { initCurieConverter } from "@/util/url";

groupLog("Env variables", import.meta.env);

Expand Down Expand Up @@ -48,6 +49,7 @@ if (new URL(window.location.href).hostname.endsWith("monarchinitiative.org")) {
app.use(VueGtag, { config: { id: "G-TWM5ED4QJB" } }, router);
}


(async () => {
/** mock api */
if (
Expand All @@ -62,6 +64,8 @@ if (new URL(window.location.href).hostname.endsWith("monarchinitiative.org")) {
await setupWorker(...handlers).start();
}

await initCurieConverter();

/** start app */
app.mount("#app");
})();
8 changes: 8 additions & 0 deletions frontend/src/pages/node/AssociationsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<span v-else class="empty">No info</span>
</template>

<template #original_subject="{ row }">
<AppLink :to="expandCurie(row.original_subject)">
{{ row.original_subject }}
</AppLink>
</template>

<!-- button to show details -->
<template #details="{ cell, row }">
<AppButton
Expand Down Expand Up @@ -128,6 +134,7 @@ import type { Cols, Sort } from "@/components/AppTable.vue";
import { snackbar } from "@/components/TheSnackbar.vue";
import { useQuery } from "@/composables/use-query";
import { getBreadcrumbs } from "@/pages/node/AssociationsSummary.vue";
import { expandCurie } from "@/util/url";

type Props = {
/** current node */
Expand Down Expand Up @@ -244,6 +251,7 @@ const cols = computed((): Cols<Datum> => {
sortable: true,
},
{
slot: "original_subject",
key: "original_subject",
heading: "Original Subject",
sortable: true,
Expand Down
42 changes: 42 additions & 0 deletions frontend/src/util/url.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import init, {Converter, getOboConverter, getBioregistryConverter} from "@biopragmatics/curies";

/** is url absolute (as opposed to relative) */
export const isAbsolute = (url = ""): boolean =>
["http:", "https:", "ftp:", "mailto:"].some((prefix) =>
Expand All @@ -24,3 +26,43 @@ export const getUrl = (
type KeysMatching<T, V> = {
[K in keyof T]-?: T[K] extends V ? K : never;
}[keyof T];

const curieMap: Record<string, string> = {
"MONDO": "http://purl.obolibrary.org/obo/MONDO_",
"HP": "http://purl.obolibrary.org/obo/HP_",
"GO": "http://purl.obolibrary.org/obo/GO_",
"CL": "http://purl.obolibrary.org/obo/CL_",
"OMIM": "http://purl.obolibrary.org/obo/OMIM_",
"NCIT": "http://purl.obolibrary.org/obo/NCIT_",
"DOID": "http://purl.obolibrary.org/obo/DOID_",
"Orphanet": "http://purl.obolibrary.org/obo/Orphanet_",
}

//@ts-expect-error
let curieConverter;

export async function initCurieConverter() {
//@ts-ignore
await init();
curieConverter = await Converter.fromExtendedPrefixMap("https://raw.githubusercontent.com/biopragmatics/bioregistry/main/exports/contexts/bioregistry.epm.json")
}

export function expandCurie(curie: string | undefined): string {
if (!curie) {
return "";
}

//@ts-expect-error
return curieConverter.expand(curie);
}

export const expand = (curie: string): string => {
if (!curie.includes(":")) {
return curie;
}
const [prefix, id] = curie.split(":");
if (!curieMap[prefix]) {
return curie;
}
return curieMap[prefix] + id;
}