Skip to content

Commit 0153344

Browse files
committed
Make column unit selection entirely optional
1 parent 09ca161 commit 0153344

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

packages/column-views/src/column.ts

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface ColumnProps extends BaseColumnProps, ColumnHeightScaleOptions {
5353
b_age?: number;
5454
mergeSections?: MergeSectionsMode;
5555
showUnitPopover?: boolean;
56+
allowUnitSelection?: boolean;
5657
selectedUnit?: number | null;
5758
onUnitSelected?: (unitID: number | null, unit: any) => void;
5859
// Unconformity height in pixels
@@ -77,6 +78,7 @@ export function Column(props: ColumnProps) {
7778
minPixelScale = 0.2,
7879
minSectionHeight = 50,
7980
collapseSmallUnconformities = true,
81+
allowUnitSelection,
8082
...rest
8183
} = props;
8284
const ref = useRef<HTMLElement>();
@@ -106,18 +108,37 @@ export function Column(props: ColumnProps) {
106108
);
107109
}
108110

111+
let main: any = h(ColumnInner, { columnRef: ref, ...rest }, [
112+
children,
113+
h.if(showUnitPopover)(UnitSelectionPopover),
114+
h.if(keyboardNavigation)(UnitKeyboardNavigation, { units }),
115+
]);
116+
117+
/* By default, unit selection is disabled. However, if any related props are passed,
118+
we enable it.
119+
*/
120+
let _allowUnitSelection = allowUnitSelection ?? false;
121+
if (showUnitPopover || selectedUnit != null || onUnitSelected != null) {
122+
_allowUnitSelection = true;
123+
}
124+
125+
if (_allowUnitSelection) {
126+
main = h(
127+
UnitSelectionProvider,
128+
{
129+
columnRef: ref,
130+
onUnitSelected,
131+
selectedUnit,
132+
units,
133+
},
134+
main
135+
);
136+
}
137+
109138
return h(
110139
MacrostratColumnDataProvider,
111140
{ units, sections, totalHeight, axisType },
112-
h(
113-
UnitSelectionProvider,
114-
{ columnRef: ref, onUnitSelected, selectedUnit, units },
115-
h(ColumnInner, { columnRef: ref, ...rest }, [
116-
children,
117-
h.if(showUnitPopover)(UnitSelectionPopover),
118-
h.if(keyboardNavigation)(UnitKeyboardNavigation, { units }),
119-
])
120-
)
141+
main
121142
);
122143
}
123144

packages/column-views/src/units/selection.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ export function useUnitSelectionStore<T>(
3636
): T {
3737
const store = useContext(UnitSelectionContext);
3838
if (store == null) {
39-
throw new Error(
40-
"useUnitSelectionStore must be used within a UnitSelectionProvider"
41-
);
39+
return null;
4240
}
4341
return useStore(store, selector);
4442
}

packages/column-views/stories/carbon-isotopes.stories.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ function StableIsotopesOverlay(props) {
1818
label: "δ¹³C",
1919
width: 100,
2020
nTicks: 4,
21-
showAxis: true,
2221
}),
2322
h(IsotopesColumn, {
2423
parameter: "D18O",
@@ -27,7 +26,6 @@ function StableIsotopesOverlay(props) {
2726
domain: [-40, 0],
2827
width: 100,
2928
nTicks: 4,
30-
showAxis: true,
3129
}),
3230
]);
3331
}
@@ -57,6 +55,7 @@ export const BasicCarbonIsotopesColumn = {
5755
inProcess: true,
5856
showTimescale: false,
5957
showLabelColumn: false,
58+
allowUnitSelection: false,
6059
},
6160
};
6261

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ export function ColumnClickHandler() {
236236

237237
return h(FlexRow, { gap: "2em" }, [
238238
h(
239-
BasicColumn,
239+
StandaloneColumn,
240240
{
241241
id: 483,
242242
showLabelColumn: false,

packages/column-views/stories/sections.stories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Meta, StoryObj } from "@storybook/react";
33
import { ColoredUnitComponent } from "@macrostrat/column-views";
44
import "@macrostrat/style-system";
55
import { ColumnAxisType } from "@macrostrat/column-components";
6-
import { StandaloneColumn, StandaloneColumnProps } from "./standalone-column";
6+
import { StandaloneColumn, StandaloneColumnProps } from "./column-ui";
77

88
type Story = StoryObj<typeof StandaloneColumn>;
99

0 commit comments

Comments
 (0)