-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
23 changed files
with
517 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Submodule web-components
updated
1 files
+1 −1 | packages/ui-components/src/geodeepdive/reference-card.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export default { | ||
meta: { | ||
Page: { | ||
env: { | ||
client: true, | ||
server: false, | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.