Skip to content

Commit

Permalink
Merge branch 'lexicon-rework'
Browse files Browse the repository at this point in the history
* lexicon-rework:
  Updated page breadcrumbs somewhat
  Created a basic admin component
  Started putting in place a page console
  Starting point for extractions management
  • Loading branch information
davenquinn committed Sep 17, 2024
2 parents 0977462 + 386cd28 commit c68f039
Show file tree
Hide file tree
Showing 23 changed files with 517 additions and 71 deletions.
34 changes: 34 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deps/web-components
2 changes: 2 additions & 0 deletions packages/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const macrostratInstance = getRuntimeConfig("MACROSTRAT_INSTANCE");

export const elevationLayerURL = getRuntimeConfig("ELEVATION_LAYER_URL");

export const enableAdmin = getRuntimeConfig("ENABLE_ADMIN", true);

/** Legacy settings object */
export const SETTINGS = {
cdrPrefix,
Expand Down
10 changes: 9 additions & 1 deletion pages/+Layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ReactNode } from "react";

import { AuthProvider } from "~/_providers/auth";
import { usePageContext } from "vike-react/usePageContext";
import { enableAdmin } from "@macrostrat-web/settings";

import "~/styles/blueprint-core";
import "~/styles/_theme.styl";
Expand All @@ -11,6 +12,8 @@ import "~/styles/padding.css";
//
import h from "./layout.module.sass";

import { PageAdminConsole } from "~/components";

export default function Layout({ children }: { children: ReactNode }) {
const pageContext = usePageContext();
const { exports = {}, config, user } = pageContext;
Expand All @@ -23,7 +26,12 @@ export default function Layout({ children }: { children: ReactNode }) {
h(
supportsDarkMode ? DarkModeProvider : NoOpDarkModeProvider,
{ followSystem: true },
h("div.app-shell", { className: pageStyle + "-page" }, children)
h("div.app-shell", { className: pageStyle + "-page" }, [
children,
h.if(enableAdmin)(PageAdminConsole, {
className: "page-admin-container",
}),
])
)
);
}
Expand Down
9 changes: 2 additions & 7 deletions pages/+Page.mdx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
export { ContentPage as default } from "~/layouts";
import { macrostratInstance } from "@macrostrat-web/settings";
import { PageHeader } from "~/components";
import { PageHeaderV2 } from "~/components";
import { LinkCard } from "~/components/cards";

<PageHeader title="Macrostrat">
<span className="subtitle">
<span className="secondary">v2</span>{" "}
<span className="tertiary">{macrostratInstance}</span>
</span>
</PageHeader>
<PageHeaderV2 title="Macrostrat"></PageHeaderV2>

<LinkCard href="/map" title="Map interface">
Macrostrat's main map interface showing a harmonized view of the Earth's crust
Expand Down
82 changes: 82 additions & 0 deletions pages/dev/xdd-extractions/+Page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import h from "@macrostrat/hyper";
import { PostgrestClient } from "@supabase/postgrest-js";

import { ContentPage } from "~/layouts";
import { PageHeaderV2 } from "~/components";
import { postgrestPrefix } from "@macrostrat-web/settings";
import { useEffect, useState } from "react";

const postgrest = new PostgrestClient(postgrestPrefix);

function usePostgresQuery(query) {
const [data, setData] = useState(null);
useEffect(() => {
postgrest
.from(query)
.select("n_matches,citation,paper_id")
.order("n_matches", { ascending: false })
.limit(100)
.then((res) => {
setData(res.data);
});
}, [query]);
return data;
}

export function Page() {
return h(ContentPage, [h(PageMain)]);
}

function PageMain() {
return h("div", [
h(PageHeaderV2, { title: "Stratigraphic name extractions" }),
h(ExtractionIndex),
]);
}

function ExtractionIndex() {
const data = usePostgresQuery("kg_publication_entities");
if (data == null) {
return h("div", "Loading...");
}

return h([
h(
data.map((d) => {
return h("div", [
h(xDDCitation, {
citation: d.citation,
href: `/dev/xdd-extractions/${d.paper_id}`,
}),
h("p", `${d.n_matches} stratigraphic name matches`),
]);
})
),
]);
}

function pruneEmptyCitationElements(citation): any {
const keys = [
"title",
"author",
"doi",
"journal",
"identifier",
"volume",
"number",
"year",
];
let newCitation = {};
for (let key of keys) {
if (citation[key] != null && citation[key] !== "") {
newCitation[key] = citation[key];
}
}
return newCitation;
}

function xDDCitation({ citation, href }) {
const newCitation = pruneEmptyCitationElements(citation);
const { title } = newCitation;
return h("div", [h("h2.title", h("a", { href }, title))]);
}
10 changes: 10 additions & 0 deletions pages/dev/xdd-extractions/+config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
meta: {
Page: {
env: {
client: true,
server: false,
},
},
},
};
113 changes: 113 additions & 0 deletions pages/dev/xdd-extractions/@paperId/+Page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import h from "@macrostrat/hyper";
import { PostgrestClient } from "@supabase/postgrest-js";

import { ContentPage } from "~/layouts";
import { PageBreadcrumbs } from "~/components";
import { postgrestPrefix } from "@macrostrat-web/settings";
import { useEffect, useState } from "react";
import { usePageContext } from "vike-react/usePageContext";
import { JSONView } from "@macrostrat/ui-components";

const postgrest = new PostgrestClient(postgrestPrefix);

function usePostgresQuery(query, { paperId }) {
const [data, setData] = useState(null);
useEffect(() => {
postgrest
.from(query)
.select()
.filter("paper_id", "eq", paperId)
.then((res) => {
setData(res.data);
});
}, [query]);
return data;
}

export function Page() {
return h(ContentPage, [h(PageBreadcrumbs), h(PageMain)]);
}

function PageMain() {
return h("div", [
h("h1", "xDD stratigraphic name extractions"),
h(ExtractionIndex),
]);
}

function ExtractionIndex() {
const { routeParams } = usePageContext();
const { paperId } = routeParams;

const data = usePostgresQuery("kg_context_entities", { paperId });
if (data == null) {
return h("div", "Loading...");
}

return h(data.map((d) => h(ExtractionContext, { data: d })));
}

function ExtractionContext({ data }) {
return h("div", [
h("p", data.paragraph_text),
h(
"ul.entities",
data.entities.map((d) => h(ExtractionInfo, { data: d }))
),
]);
}

type Match = any;

interface Entity {
id: number;
name: string;
type: "strat_name" | "lith" | "lith_att";
indices: [number, number];
children: Entity[];
match?: Match;
}

function ExtractionInfo({ data }: { data: Entity }) {
const children = data.children ?? [];

const match = data.match ?? null;

console.log(data);

return h("li.entity", { className: data.type }, [
h("span.name", data.name),
h(Match, { data: match }),
h.if(children.length > 0)([
h(
"ul.children",
children.map((d) => h(ExtractionInfo, { data: d }))
),
]),
]);
}

function Match({ data }) {
if (data == null) return null;
const href = buildHref(data);
return h([" ", h("a.match", { href }, data.name)]);
}

function buildHref(match) {
/** Build a URL for a matched term */
if (match == null) return null;

if (match.strat_name_id != null) {
return `/lex/strat-names/${match.strat_name_id}`;
}

if (match.lith_id != null) {
return `/lex/lithologies`;
}

if (match.lith_att_id != null) {
return `/lex/lithologies`;
}

return null;
}
10 changes: 9 additions & 1 deletion pages/layout.module.sass
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@
:global(.in-page-transition)
height: 100vh
overflow: hidden
position: relative
position: relative

// An admin console for the page
.page-admin-container
position: fixed
top: 0
right: 0
margin: 1em
z-index: 5000
36 changes: 0 additions & 36 deletions pages/lex/strat-names/+Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,39 +154,3 @@ function StratNamesList({ data }) {
data.map((d) => h(StratNameItem, { data: d, key: d.id })),
]);
}

const ranks = {
Fm: "Formation",
Mbr: "Member",
Gp: "Group",
Sgp: "Supergroup",
};

function StratNameItem({ data }) {
const { kg_liths, liths, units, id } = data;
return h("div.strat-name", {}, [
h(
Link,
{ href: `/lex/strat-names/${id}` },
h("h2.strat-name", [
data.strat_name,
" ",
h("span", ranks[data.rank] ?? data.rank),
])
),
h("p", [`in ${units.length} columns`]),
h("div.strat-name-details", [h(Liths, { liths })]),
h.if(kg_liths != null)("div.strat-name-details", [
h(Liths, { liths: kg_liths, candidate: true }),
]),
]);
}

function Liths({ liths, candidate = false }) {
return h(
"p.liths",
liths.map((lith, i) => {
return h(AttributedLithTag, { key: i, lith, candidate });
})
);
}
1 change: 0 additions & 1 deletion pages/lex/strat-names/@id/+Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Link, PageHeader } from "~/components";
import { AttributedLithTag } from "~/components";
import { AnchorButton, Icon, InputGroup, Tag } from "@blueprintjs/core";
import { GDDReferenceCard, CollapseCard } from "@macrostrat/ui-components";
import { useState } from "react";
import styles from "./main.module.sass";

const h = hyper.styled(styles);
Expand Down
5 changes: 4 additions & 1 deletion pages/map/map-interface/map-page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Suspense, useCallback, useEffect, useRef } from "react";
import { Spinner } from "@blueprintjs/core";
import loadable from "@loadable/component";
import { mapPagePrefix } from "@macrostrat-web/settings";
import { MapAreaContainer } from "@macrostrat/map-interface";
import { MapAreaContainer, MapBottomControls } from "@macrostrat/map-interface";
import classNames from "classnames";
import { useSelector } from "react-redux";
import { Route, Routes } from "react-router-dom";
Expand All @@ -18,6 +18,8 @@ import Searchbar from "../components/navbar";
import MapContainer from "./map-view";
import { MenuPage } from "./menu";
import h from "./main.module.styl";
import { PageAdminButton, PageAdminConsole } from "~/components";
import MapControls from "../../../../packages/sift/src/js/components/MapControls";

const ElevationChart = loadable(() => import("../components/elevation-chart"));
const InfoDrawer = loadable(() => import("../components/info-drawer"));
Expand Down Expand Up @@ -79,6 +81,7 @@ function MapPage({
detailPanel: h(InfoDrawerHolder),
detailPanelStyle: "floating",
bottomPanel: h(ElevationChart, null),
mapControls: h(MapBottomControls, [h(PageAdminButton)]),
contextPanelOpen: contextPanelOpen || inputFocus,
detailPanelOpen: infoDrawerOpen,
className: classNames(
Expand Down
Loading

0 comments on commit c68f039

Please sign in to comment.