Skip to content

Commit 9c08061

Browse files
authored
Merge pull request #80 from UW-Macrostrat/lith-tag-update
Unit Details Clickable
2 parents 8d228c9 + 1f9e893 commit 9c08061

File tree

9 files changed

+75
-11
lines changed

9 files changed

+75
-11
lines changed

packages/column-views/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
88

9+
- `UnitDetailsContent` automatically handles clicks on Lithologies, Intervals, and Environment tags and routes to their specific individual lexicon page.
910
- Add mouseover handlers to allow age cursor to be reported
1011
- Add an `AgeCursor` component
1112
- Reactivate carbon isotopes column rendering

packages/column-views/src/unit-details/panel.ts

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { Button, ButtonGroup } from "@blueprintjs/core";
55
import { ReactNode, useMemo, useState } from "react";
66
import {
77
DataField,
8-
EnvironmentsList,
8+
// EnvironmentsList,
99
IntervalShort,
1010
IntervalTag,
1111
ItemList,
12-
LithologyList,
12+
// LithologyList,
1313
LithologyTagFeature,
1414
Parenthetical,
1515
Value,
1616
} from "@macrostrat/data-components";
17+
import { LithologyList, EnvironmentsList } from "../../../data-components/src";
1718
import { useMacrostratData, useMacrostratDefs } from "../data-provider";
1819
import { Environment, UnitLong, UnitLongFull } from "@macrostrat/api-types";
1920
import { defaultNameFunction } from "../units/names";
@@ -35,6 +36,7 @@ export function UnitDetailsPanel({
3536
actions,
3637
selectUnit,
3738
columnUnits,
39+
onClickItem,
3840
}: {
3941
unit: any;
4042
onClose?: any;
@@ -45,14 +47,15 @@ export function UnitDetailsPanel({
4547
lithologyFeatures?: Set<LithologyTagFeature>;
4648
columnUnits?: UnitLong[];
4749
selectUnit?: (unitID: number) => void;
50+
onClickItem?: (item: any) => void;
4851
}) {
4952
const [showJSON, setShowJSON] = useState(false);
5053

5154
let content = null;
5255
if (showJSON) {
5356
content = h(JSONView, { data: unit, showRoot: false });
5457
} else {
55-
content = h(UnitDetailsContent, { unit, features, lithologyFeatures });
58+
content = h(UnitDetailsContent, { unit, features, lithologyFeatures, onClickItem });
5659
}
5760

5861
let title = defaultNameFunction(unit);
@@ -136,12 +139,14 @@ function UnitDetailsContent({
136139
UnitDetailsFeature.AdjacentUnits,
137140
UnitDetailsFeature.OutcropType,
138141
]),
142+
onClickItem,
139143
}: {
140144
unit: UnitLong;
141145
selectUnit?: (unitID: number) => void;
142146
columnUnits?: UnitLong[];
143147
lithologyFeatures?: Set<LithologyTagFeature>;
144148
features?: Set<UnitDetailsFeature>;
149+
onClickItem?: (event: any) => void;
145150
}) {
146151
const lithMap = useMacrostratDefs("lithologies");
147152
const envMap = useMacrostratDefs("environments");
@@ -215,12 +220,19 @@ function UnitDetailsContent({
215220
label: "Lithology",
216221
lithologies,
217222
features: lithologyFeatures,
223+
onClickItem,
218224
}),
219225
h(AgeField, { unit }, [
220226
h(Parenthetical, h(Duration, { value: unit.b_age - unit.t_age })),
221-
h(IntervalProportions, { unit }),
227+
h(IntervalProportions, {
228+
unit,
229+
onClickItem,
230+
}),
222231
]),
223-
h(EnvironmentsList, { environments }),
232+
h(EnvironmentsList, {
233+
environments,
234+
onClickItem,
235+
}),
224236
h.if(unit.strat_name_id != null)(
225237
DataField,
226238
{
@@ -470,7 +482,7 @@ function UnitIDList({ units, selectUnit }) {
470482
);
471483
}
472484

473-
function IntervalProportions({ unit }) {
485+
function IntervalProportions({ unit, onClickItem }) {
474486
const i0 = unit.b_int_id;
475487
const i1 = unit.t_int_id;
476488
let b_prop = unit.b_prop ?? 0;
@@ -498,14 +510,26 @@ function IntervalProportions({ unit }) {
498510
p0 = h("span.joint-proportion", [p0, h("span.sep", "to"), p1]);
499511
}
500512

513+
const clickable = onClickItem != null;
514+
515+
const handleClick = (event: MouseEvent) => {
516+
if (onClickItem) {
517+
onClickItem({ event, data: interval0 });
518+
}
519+
};
520+
501521
return h("div.interval-proportions", [
502522
h(IntervalTag, {
523+
className: clickable ? "clickable" : "",
524+
onClick: clickable ? handleClick : undefined,
503525
interval: interval0,
504526
prefix: p0,
505527
}),
506528
h.if(i0 != i1)("span.discourage-break", [
507529
h("span.sep", "to"),
508530
h(IntervalTag, {
531+
className: clickable ? "clickable" : "",
532+
onClick: clickable ? handleClick : undefined,
509533
interval: {
510534
...int1,
511535
id: i1,

packages/column-views/stories/unit-details.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function UnitDetailsExt({
3131
return h(Spinner);
3232
}
3333

34-
return h(LithologiesProvider, h(UnitDetailsPanel, { unit, ...rest }));
34+
return h(LithologiesProvider, h(UnitDetailsPanel, { onClickItem: (e) => console.log(e), unit, ...rest }));
3535
}
3636

3737
type Story = StoryObj<typeof UnitDetailsExt>;

packages/data-components/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## [unreleased]
4+
5+
- onClick capability added to LithologyTag, IntervalTag, and EnvironmentList, returning event and associated data
6+
37
## [0.1.0] - 2025-04-09
48

59
- Added fields for data and tags, which can be used for rendering lists of

packages/data-components/src/components/unit-details/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ export function IntervalTag({
102102
interval,
103103
showAgeRange = false,
104104
color,
105+
onClick,
105106
...rest
106107
}: IntervalTagProps) {
107108
return h(Tag, {
109+
onClick,
108110
name: interval.name,
109111
color: color ?? interval.color,
110112
...rest,
@@ -126,10 +128,12 @@ export function TagField({
126128
label,
127129
className,
128130
children,
131+
onClick,
129132
}: {
130133
label?: string;
131134
className?: string;
132135
children?: ReactNode;
136+
onClick?: () => void;
133137
}) {
134138
return h(
135139
DataField,

packages/data-components/src/components/unit-details/lithology-tag.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ interface LithologyTagProps {
1010
expandOnHover?: boolean;
1111
size?: TagSize;
1212
features?: Set<LithologyTagFeature>;
13+
onClick?: (event: any) => void;
1314
}
1415

1516
export enum LithologyTagFeature {
@@ -22,6 +23,7 @@ export function LithologyTag({
2223
color,
2324
features,
2425
size,
26+
onClick,
2527
}: LithologyTagProps) {
2628
let proportion = null;
2729
const showProportion = features?.has(LithologyTagFeature.Proportion) ?? false;
@@ -40,16 +42,26 @@ export function LithologyTag({
4042
});
4143
}
4244

45+
const clickable = onClick != null;
46+
47+
const handleClick = (event: MouseEvent) => {
48+
if (onClick) {
49+
onClick({ event, data });
50+
}
51+
};
52+
4353
return h(Tag, {
4454
prefix: atts,
4555
details: proportion,
4656
name: data.name,
47-
className: "lithology-tag",
57+
className: clickable ? " clickable" : "",
4858
size,
4959
color: color ?? data.color,
60+
onClick: clickable ? handleClick : undefined,
5061
});
5162
}
5263

64+
5365
function List({ items, commaSeparated = false, lastSep = null, className }) {
5466
let items1 = items;
5567
if (commaSeparated) {
@@ -81,10 +93,12 @@ export function LithologyList({
8193
LithologyTagFeature.Proportion,
8294
LithologyTagFeature.Attributes,
8395
]),
96+
onClickItem,
8497
}: {
8598
label?: string;
8699
lithologies: any[];
87100
features?: Set<LithologyTagFeature>;
101+
onClickItem?: (data: any) => void;
88102
}) {
89103
const sortedLiths = useMemo(() => {
90104
const l1 = [...lithologies];
@@ -104,6 +118,9 @@ export function LithologyList({
104118
return h(LithologyTag, {
105119
data: l1,
106120
features,
121+
onClick: onClickItem
122+
? (data) => onClickItem({ ...data, data: l1 })
123+
: undefined,
107124
});
108125
})
109126
);
@@ -120,12 +137,14 @@ function lithologyComparison(a, b) {
120137
return dx;
121138
}
122139

123-
export function EnvironmentsList({ environments }) {
140+
export function EnvironmentsList({ environments, onClickItem }) {
141+
142+
124143
return h(
125144
TagField,
126-
{ label: "Environments", className: "environments-list" },
145+
{ label: "Environments", className: "environments-list"},
127146
environments.map((lith: any) => {
128-
return h(LithologyTag, { data: lith });
147+
return h(LithologyTag, { data: lith, onClick: onClickItem});
129148
})
130149
);
131150
}

packages/data-components/src/components/unit-details/tag.module.sass

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
.tight-list
77
padding-left: 1em
88

9+
.clickable
10+
cursor: pointer
11+
912
.tag
1013
font-size: var(--font-size)
1114
align-items: center

packages/data-components/src/components/unit-details/tag.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface BaseTagProps {
2626
children?: ReactNode;
2727
size?: TagSize;
2828
color?: chroma.ChromaInput;
29+
onClick?: (data: any) => void;
2930
}
3031

3132
export function Tag(props: BaseTagProps) {
@@ -39,6 +40,7 @@ export function Tag(props: BaseTagProps) {
3940
children,
4041
size,
4142
color,
43+
onClick,
4244
} = props;
4345

4446
let _details = null;
@@ -62,6 +64,7 @@ export function Tag(props: BaseTagProps) {
6264
{
6365
className,
6466
style: buildTagStyle({ color, size, inDarkMode }),
67+
onClick,
6568
},
6669
[_prefix, mainTag]
6770
);

packages/data-components/src/components/unit-details/unit-details.stories.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ LithologyTag.args = {
5757
},
5858
expandOnHover: false,
5959
size: "normal",
60+
onClick: (e) => {
61+
console.log("Clicked lith id:", e.lith_id);
62+
}
6063
};
6164

6265
export { LithologyTag };
@@ -103,5 +106,8 @@ export function LithologyList() {
103106
lith_id: 2,
104107
},
105108
],
109+
onClickItem: (e) => {
110+
console.log("Clicked lith id:", e.lithId);
111+
}
106112
});
107113
}

0 commit comments

Comments
 (0)