Skip to content

Commit

Permalink
Merge pull request #250 from UW-Macrostrat/extractions-updates
Browse files Browse the repository at this point in the history
Updates to extractions web app
  • Loading branch information
davenquinn authored Sep 30, 2024
2 parents 1bd1dd7 + d47ff16 commit 763e6f1
Show file tree
Hide file tree
Showing 5 changed files with 246 additions and 46 deletions.
15 changes: 2 additions & 13 deletions pages/dev/legend-affinity/+Page.client.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import h from "./main.module.sass";
import { mapboxAccessToken, tileserverDomain } from "@macrostrat-web/settings";
import {
buildQueryString,
useDarkMode,
useStoredState,
} from "@macrostrat/ui-components";
import { useDarkMode } from "@macrostrat/ui-components";
import { Select, SelectProps } from "@blueprintjs/select";
import mapboxgl from "mapbox-gl";
import { useCallback, useState, useEffect, useMemo } from "react";
Expand Down Expand Up @@ -158,14 +154,6 @@ export function Page() {
);
}

function isValidMapPosition(data: any): boolean {
if (data == null) return false;
if (typeof data !== "object") return false;
if (data?.camera?.lng == null) return false;
if (data?.camera?.lat == null) return false;
return true;
}

interface StyleParams {
inDarkMode: boolean;
term: string | null;
Expand Down Expand Up @@ -360,6 +348,7 @@ function useMapPosition(startPos) {
setMapPosition_(position);
let params = getQueryString(window.location.search) ?? {};
applyMapPositionToHash(params, position);
console.log(params);
setQueryString(params);
}, []);

Expand Down
63 changes: 57 additions & 6 deletions pages/integrations/xdd/extractions/+Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import { ContentPage } from "~/layouts";
import { PageHeaderV2 } from "~/components";
import { postgrestPrefix } from "@macrostrat-web/settings";
import { useEffect, useState } from "react";
import { InfiniteScroll, LoadingPlaceholder } from "@macrostrat/ui-components";
import {
AuthorList,
InfiniteScroll,
LoadingPlaceholder,
} from "@macrostrat/ui-components";
import { create } from "zustand";

const postgrest = new PostgrestClient(postgrestPrefix);
Expand All @@ -33,8 +37,8 @@ const useStore = create<DataStore>((set, get) => ({

let req = postgrest
.from("kg_publication_entities")
.select("citation,paper_id")
.order("paper_id", { ascending: true });
.select("*")
.order("n_matches", { ascending: false });

if (lastID != null) {
req = req.gt("paper_id", lastID);
Expand Down Expand Up @@ -73,19 +77,33 @@ function ExtractionIndex() {
]);
}

function NameMatch({ type, count, pluralSuffix = "s" }) {
let pluralType = type;
if (count > 1) {
pluralType += pluralSuffix;
}

return `${count} ${pluralType}`;
}

function PaperList({ data }) {
const ctx = usePageContext();
const pageLink = ctx.urlPathname;
return h("div.paper-list", [
data.map((d) => {
console.log(d);
return h("div", [
h(xDDCitation, {
citation: d.citation,
href: pageLink + `/${d.paper_id}`,
}),
h.if(d.n_matches != null)(
"p",
`${d.n_matches} stratigraphic name matches`
h(NameMatch, {
type: "stratigraphic name match",
count: d.n_matches,
pluralSuffix: "es",
})
),
]);
}),
Expand Down Expand Up @@ -114,6 +132,39 @@ function pruneEmptyCitationElements(citation): any {

function xDDCitation({ citation, href }) {
const newCitation = pruneEmptyCitationElements(citation);
const { title } = newCitation;
return h("div", [h("h2.title", h("a", { href }, title))]);
const { title, author, journal, identifier } = newCitation;
const names = author?.map((d) => d.name);
return h("div", [
h("h2.title", h("a", { href }, title)),
h("h3.journal", null, journal),
h(AuthorList, { names }),
h(IdentLink, { identifier: getBestIdentifier(identifier) }),
]);
}

function IdentLink({ identifier }) {
if (identifier == null) return null;
const { type, id } = identifier;

let ident = h("code.identifier", id);
if (type == "doi") {
ident = h("a", { href: "https://dx.doi.org/doi/" + id }, ident);
}

return h("p", [h("span.label", type), " ", ident]);
}

type Identifier = {
id: string;
type: string;
};

function getBestIdentifier(identifier: Identifier[] | null): Identifier | null {
if (identifier == null || identifier.length == 0) return null;
for (const ident of identifier) {
if (ident.type == "doi") {
return ident;
}
}
return identifier[0];
}
Loading

0 comments on commit 763e6f1

Please sign in to comment.