Skip to content

Commit 850b6a4

Browse files
committed
Added basic unit_boundaries view
1 parent 6410c1a commit 850b6a4

File tree

3 files changed

+176
-0
lines changed

3 files changed

+176
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
import { FullscreenPage } from "~/layouts";
2+
import hyper from "@macrostrat/hyper";
3+
import styles from "./main.module.sass";
4+
import { DataSheetDensity, PostgRESTTableView } from "@macrostrat/data-sheet";
5+
import { postgrestPrefix } from "@macrostrat-web/settings";
6+
import { PageBreadcrumbs } from "~/components";
7+
import {
8+
LongTextViewer,
9+
lithologyRenderer,
10+
ExpandedLithologies,
11+
} from "~/components/data-table";
12+
import { IntervalCell } from "@macrostrat/data-sheet";
13+
import { usePageContext } from "vike-react/usePageContext";
14+
import {
15+
MacrostratDataProvider,
16+
useMacrostratData,
17+
useMacrostratStore,
18+
} from "@macrostrat/column-views";
19+
import { apiV2Prefix } from "@macrostrat-web/settings";
20+
import { useCallback, useMemo } from "react";
21+
import { Cell } from "@blueprintjs/table";
22+
import { Spinner } from "@blueprintjs/core";
23+
24+
const h = hyper.styled(styles);
25+
26+
export function Page() {
27+
const { routeParams } = usePageContext();
28+
const { section_id } = routeParams as { section_id: string };
29+
30+
return h(FullscreenPage, { className: "main" }, [
31+
h(PageBreadcrumbs),
32+
h("h1", "Unit boundaries"),
33+
h(
34+
MacrostratDataProvider,
35+
{ baseURL: apiV2Prefix },
36+
h(SectionPostgRESTTable, { section_id })
37+
),
38+
]);
39+
}
40+
41+
function SectionPostgRESTTable(props) {
42+
const { section_id } = props;
43+
const filter = useCallback(
44+
(query) => query.eq("section_id", section_id),
45+
[section_id]
46+
);
47+
48+
// Force the loading of intervals data
49+
// This is a hack due to poor design of the data loading system
50+
useMacrostratData("intervals");
51+
52+
return h(PostgRESTTableView, {
53+
endpoint: postgrestPrefix,
54+
table: "unit_boundaries",
55+
order: { key: "t1_age", ascending: true },
56+
columnOptions,
57+
filter,
58+
density: DataSheetDensity.MEDIUM,
59+
editable: true,
60+
});
61+
}
62+
63+
function IntervalIDCell(props) {
64+
const { value } = props;
65+
66+
const intervalsMap = useMacrostratStore((d) => d.intervals);
67+
const val = useMemo(
68+
() => intervalsMap.get(parseInt(value)),
69+
[intervalsMap, value]
70+
);
71+
72+
if (val == null) return h(Cell, props);
73+
74+
return h(IntervalCell, { ...props, value: val });
75+
}
76+
77+
const columnOptions = {
78+
overrides: {
79+
id: {
80+
editable: false,
81+
},
82+
name: "Unit name",
83+
comments: "Comments",
84+
legend_id: "Legend ID",
85+
strat_name: "Stratigraphic names",
86+
t1: {
87+
name: "Interval",
88+
cellComponent: IntervalIDCell,
89+
},
90+
t1_prop: {
91+
name: "Proportion",
92+
width: 80,
93+
},
94+
unit_id: {
95+
name: "Lower unit",
96+
},
97+
unit_id_2: {
98+
name: "Upper unit",
99+
},
100+
descrip: {
101+
name: "Description",
102+
dataEditor: LongTextViewer,
103+
},
104+
},
105+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
meta: {
3+
Page: {
4+
env: {
5+
client: true,
6+
server: false,
7+
},
8+
},
9+
},
10+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
.main
2+
padding: 2em 8em
3+
display: flex
4+
flex-direction: column
5+
position: fixed
6+
width: 100vw
7+
height: 100vh
8+
top: 0
9+
left: 0
10+
11+
.data-sheet-container
12+
display: flex
13+
flex-direction: column
14+
flex: 1
15+
position: relative
16+
min-height: 0
17+
18+
.lithology
19+
font-weight: bold
20+
display: inline-block
21+
padding: 0 0.5em
22+
border-radius: 0.5em
23+
24+
.inline-lithology .lithology
25+
line-height: 1.2em
26+
27+
.basis-panel
28+
:global(.bp5-tag)
29+
margin: 0 0.5em 0.5em 0
30+
td
31+
vertical-align: top
32+
th
33+
text-align: left
34+
font-weight: 400
35+
font-size: 0.9em
36+
font-style: italic
37+
color: var(--secondary-color)
38+
39+
.basis-panel, .long-text
40+
max-width: 20em
41+
padding: 8px
42+
max-height: 30em
43+
overflow-y: scroll
44+
pointer-events: all
45+
46+
.description
47+
font-style: italic
48+
49+
50+
.tag-header
51+
font-weight: bold
52+
text-transform: small-caps
53+
font-size: 0.8em
54+
color: var(--secondary-color)
55+
56+
.basis-col
57+
max-width: 15em
58+
59+
.liths :global(.bp5-tag)
60+
padding: 0px 4px
61+
min-height: 16px

0 commit comments

Comments
 (0)