Skip to content

Commit 5c53624

Browse files
authored
Merge pull request #212 from UW-Macrostrat/map-interface-fixes
Map interface fixes
2 parents 4ad5baf + ae9114b commit 5c53624

File tree

26 files changed

+427
-473
lines changed

26 files changed

+427
-473
lines changed

.vscode/settings.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@
1414
"editor.codeActionsOnSave": {
1515
"source.organizeImports": "never"
1616
}
17-
}
17+
},
18+
"cSpell.enableFiletypes": [
19+
"!javascript",
20+
"!javascriptreact",
21+
"!json",
22+
"!scss",
23+
"!typescript"
24+
]
1825
}

.yarn/sdks/typescript/lib/tsserver.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ const relPnpApiPath = "../../../../.pnp.cjs";
99
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010
const absRequire = createRequire(absPnpApiPath);
1111

12+
if (existsSync(absPnpApiPath)) {
13+
if (!process.versions.pnp) {
14+
// Setup the environment to be able to require typescript/lib/tsserver.js
15+
require(absPnpApiPath).setup();
16+
}
17+
}
18+
1219
const moduleWrapper = tsserver => {
1320
if (!process.versions.pnp) {
1421
return tsserver;
@@ -214,11 +221,11 @@ const moduleWrapper = tsserver => {
214221
return tsserver;
215222
};
216223

217-
if (existsSync(absPnpApiPath)) {
218-
if (!process.versions.pnp) {
219-
// Setup the environment to be able to require typescript/lib/tsserver.js
220-
require(absPnpApiPath).setup();
221-
}
224+
const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10));
225+
// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
226+
// Ref https://github.com/microsoft/TypeScript/pull/55326
227+
if (major > 5 || (major === 5 && minor >= 5)) {
228+
moduleWrapper(absRequire(`typescript`));
222229
}
223230

224231
// Defer to the real typescript/lib/tsserver.js your application uses

.yarn/sdks/typescript/lib/tsserverlibrary.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ const relPnpApiPath = "../../../../.pnp.cjs";
99
const absPnpApiPath = resolve(__dirname, relPnpApiPath);
1010
const absRequire = createRequire(absPnpApiPath);
1111

12+
if (existsSync(absPnpApiPath)) {
13+
if (!process.versions.pnp) {
14+
// Setup the environment to be able to require typescript/lib/tsserverlibrary.js
15+
require(absPnpApiPath).setup();
16+
}
17+
}
18+
1219
const moduleWrapper = tsserver => {
1320
if (!process.versions.pnp) {
1421
return tsserver;
@@ -214,11 +221,11 @@ const moduleWrapper = tsserver => {
214221
return tsserver;
215222
};
216223

217-
if (existsSync(absPnpApiPath)) {
218-
if (!process.versions.pnp) {
219-
// Setup the environment to be able to require typescript/lib/tsserverlibrary.js
220-
require(absPnpApiPath).setup();
221-
}
224+
const [major, minor] = absRequire(`typescript/package.json`).version.split(`.`, 2).map(value => parseInt(value, 10));
225+
// In TypeScript@>=5.5 the tsserver uses the public TypeScript API so that needs to be patched as well.
226+
// Ref https://github.com/microsoft/TypeScript/pull/55326
227+
if (major > 5 || (major === 5 && minor >= 5)) {
228+
moduleWrapper(absRequire(`typescript`));
222229
}
223230

224231
// Defer to the real typescript/lib/tsserverlibrary.js your application uses

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@
120120
"react-router-hash-link": "^2.4.3",
121121
"reduce-reducers": "^1.0.4",
122122
"redux": "^4.0.5",
123-
"regl": "^1.5.0",
124-
"resium": "^1.13.1",
125123
"sirv": "^2.0.3",
126-
"supports-color": "^9.4.0",
127124
"swagger-ui-react": "^5.12.3",
128125
"topojson-client": "^3.0.0",
129126
"transition-hook": "^1.5.2",

src/pages/dev/filtering/interface.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@ import { tileserverDomain, mapboxAccessToken } from "@macrostrat-web/settings";
44
import hyper from "@macrostrat/hyper";
55
import { DevMapPage } from "@macrostrat/map-interface";
66
import { buildMacrostratStyle } from "@macrostrat/mapbox-styles";
7-
import { useStoredState } from "@macrostrat/ui-components";
8-
import { Select, Omnibar } from "@blueprintjs/select";
7+
import { Select } from "@blueprintjs/select";
98
import mapboxgl from "mapbox-gl";
10-
import { useMemo, useState, useEffect } from "react";
9+
import { useMemo, useState } from "react";
1110
import styles from "./main.module.styl";
1211
import {
1312
replaceSourcesForTileset,
1413
LineSymbolManager,
1514
} from "~/_utils/map-layers.client";
16-
import {
17-
LithologyMultiSelect
18-
} from "./lithology-selector";
15+
import { LithologyMultiSelect } from "./lithology-selector";
1916

2017
export const h = hyper.styled(styles);
2118

@@ -27,7 +24,7 @@ enum Compilation {
2724
export function VectorMapInspectorPage({
2825
overlayStyle = _macrostratStyle,
2926
title = null,
30-
headerElement = null
27+
headerElement = null,
3128
}: {
3229
headerElement?: React.ReactElement;
3330
title?: string;
@@ -39,7 +36,9 @@ export function VectorMapInspectorPage({
3936
const { showLineSymbols } = state;
4037

4138
const _overlayStyle = useMemo(() => {
42-
return replaceSourcesForTileset(overlayStyle, state.compilation, {lithology: state.lithologies});
39+
return replaceSourcesForTileset(overlayStyle, state.compilation, {
40+
lithology: state.lithologies,
41+
});
4342
}, [overlayStyle, state.lithologies, state.compilation]) as mapboxgl.Style;
4443

4544
const controls = h([
@@ -55,14 +54,14 @@ export function VectorMapInspectorPage({
5554
compilation: state.compilation,
5655
setCompilation: (compilation) => {
5756
setState({ ...state, compilation });
58-
}
57+
},
5958
}),
6059
h(LithologyMultiSelect, {
6160
selectedLithologyNames: state.lithologies,
6261
onChange: (lithologies) => {
6362
setState({ ...state, lithologies });
64-
}
65-
})
63+
},
64+
}),
6665
]);
6766

6867
return h(
@@ -78,23 +77,31 @@ export function VectorMapInspectorPage({
7877
}
7978

8079
const CompilationSelector = ({ compilation, setCompilation }) => {
81-
return h(Select, {
82-
items: Object.values(Compilation),
83-
itemRenderer: (item: any, { handleClick }) => {
84-
return h(MenuItem, { onClick: handleClick, text: item });
85-
},
86-
onItemSelect: (item) => {
87-
setCompilation(item);
80+
return h(
81+
Select,
82+
{
83+
items: Object.values(Compilation),
84+
itemRenderer: (item: any, { handleClick }) => {
85+
return h(MenuItem, { onClick: handleClick, text: item });
86+
},
87+
onItemSelect: (item) => {
88+
setCompilation(item);
89+
},
90+
filterable: false,
91+
activeItem: compilation,
8892
},
89-
filterable: false,
90-
activeItem: compilation,
91-
}, [
92-
h(Button, {text: compilation, rightIcon: "double-caret-vertical", placeholder: "Select a film" })
93-
]);
94-
}
93+
[
94+
h(Button, {
95+
text: compilation,
96+
rightIcon: "double-caret-vertical",
97+
placeholder: "Select a film",
98+
}),
99+
]
100+
);
101+
};
95102

96103
const _macrostratStyle = buildMacrostratStyle({
97-
tileserverDomain
104+
tileserverDomain,
98105
}) as mapboxgl.Style;
99106

100107
function isStateValid(state) {
@@ -121,5 +128,5 @@ function isStateValid(state) {
121128
const defaultState = {
122129
showLineSymbols: false,
123130
compilation: "v2/carto",
124-
lithologies: []
131+
lithologies: [],
125132
};

src/pages/map/map-interface/app-state/handlers/fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function fetchFilteredColumns(
7171
// TODO: report errors
7272
return {
7373
type: "update-column-filters",
74-
columns: res.data,
74+
columns: res.data.features,
7575
};
7676
}
7777

src/pages/map/map-interface/app-state/handlers/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async function actionRunner(
4343
let coreState = s1.core;
4444

4545
const activePage = currentPageForPathName(pathname);
46-
console.log(pathname, "activePage", activePage);
4746

4847
// Harvest as much information as possible from the hash string
4948
let [coreState1, filters] = getInitialStateFromHash(

src/pages/map/map-interface/app-state/hooks.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import actionRunner from "./handlers";
33
import { useStore, useSelector, useDispatch } from "react-redux";
44
import { AppState } from ".";
55
import React from "react";
6-
import { useEffect } from "react";
76

87
function useActionDispatch() {
98
return useDispatch<React.Dispatch<AppAction>>();
@@ -20,55 +19,8 @@ function useAppActions(): (action: AppAction) => Promise<void> {
2019
};
2120
}
2221

23-
function useFilterState() {
24-
const { filters, filtersOpen } = useSelector((state) => state.core);
25-
return { filters, filtersOpen };
26-
}
27-
28-
function useSearchState() {
29-
return useSelector((state) => {
30-
const { searchResults, isSearching, term, inputFocus, infoDrawerOpen } =
31-
state.core;
32-
return { searchResults, isSearching, term, inputFocus, infoDrawerOpen };
33-
});
34-
}
35-
36-
function useMenuState() {
37-
const { menuOpen, infoDrawerOpen } = useSelector((state) => state.core);
38-
const menu = useSelector((state) => state.menu);
39-
return { menuOpen, infoDrawerOpen, ...menu };
40-
}
41-
4222
function useAppState<T>(selectorFn: (state: AppState) => T): T {
4323
return useSelector<AppState>(selectorFn) as T;
4424
}
4525

46-
interface OutsideClickI {
47-
ref: React.RefObject<HTMLElement>;
48-
fn: (event: Event) => void;
49-
}
50-
51-
function useOutsideClick(props: OutsideClickI) {
52-
const { ref, fn } = props;
53-
54-
useEffect(() => {
55-
function handleOutsideClick(event) {
56-
if (ref.current && !ref.current?.contains(event.target)) {
57-
return fn(event);
58-
}
59-
}
60-
document.addEventListener("mousedown", handleOutsideClick);
61-
return () => {
62-
document.removeEventListener("mousedown", handleOutsideClick);
63-
};
64-
}, [ref]);
65-
}
66-
67-
export {
68-
useAppActions,
69-
useFilterState,
70-
useSearchState,
71-
useMenuState,
72-
useAppState,
73-
useOutsideClick,
74-
};
26+
export { useAppActions, useAppState };

src/pages/map/map-interface/app-state/reducers/core/types.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ type CLOSE_INFODRAWER = { type: "close-infodrawer" };
4141

4242
type TOGGLE_FILTERS = { type: "toggle-filters" };
4343
type REMOVE_FILTER = { type: "remove-filter"; filter: any };
44-
type UPDATE_COLUMN_FILTERS = { type: "update-column-filters"; columns: any };
44+
type UPDATE_COLUMN_FILTERS = {
45+
type: "update-column-filters";
46+
columns: ColumnGeoJSONRecord[];
47+
};
4548
type CLEAR_FILTERS = { type: "clear-filters" };
4649

4750
type START_MAP_QUERY = {
@@ -263,7 +266,7 @@ export interface CoreState extends MapState, AsyncRequestState {
263266
mapUse3D: boolean;
264267
filtersOpen: boolean;
265268
filters: FilterData[];
266-
filteredColumns: object;
269+
filteredColumns: ColumnGeoJSONRecord[] | null;
267270
showExperimentsPanel: boolean;
268271
allColumns: ColumnGeoJSONRecord[] | null;
269272
data: [];

src/pages/map/map-interface/components/filter-panel/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import React, { useState } from "react";
22
import hyper from "@macrostrat/hyper";
33
import { Tag, Card, Button, Collapse, Switch } from "@blueprintjs/core";
44
import {
5-
useFilterState,
65
useAppActions,
6+
useAppState,
77
} from "~/pages/map/map-interface/app-state";
88
import { useAdmoinshments } from "./admonishments";
99
import styles from "./filters.module.styl";
@@ -54,7 +54,7 @@ function Filter({ filter }) {
5454
}
5555

5656
function Filters() {
57-
const { filters } = useFilterState();
57+
const { filters } = useAppState((state) => state.core.filters);
5858
const shouldFiltersBeOpen = filters.length > 0;
5959
return h("div.filter-container", [
6060
h.if(!shouldFiltersBeOpen)("div", [
@@ -94,7 +94,7 @@ function makeFilterString(filters) {
9494

9595
function FilterPanel() {
9696
const [open, setOpen] = useState(false);
97-
const { filters } = useFilterState();
97+
const filters = useAppState((s) => s.core.filters);
9898
const runAction = useAppActions();
9999
const admonishments = useAdmoinshments();
100100

src/pages/map/map-interface/components/info-drawer/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ function InfoDrawer(props) {
5656

5757
function InfoDrawerInterior(props) {
5858
const columnInfo = useAppState((state) => state.core.columnInfo);
59-
console.log("Column info", columnInfo);
60-
6159
return h(Routes, [
6260
h(Route, { path: "/column", element: h(StratColumn, { columnInfo }) }),
6361
h(Route, { path: "*", element: h(InfoDrawerMainPanel) }),

src/pages/map/map-interface/components/navbar/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Navbar, Button, InputGroup, Spinner, Card } from "@blueprintjs/core";
33
import hyper from "@macrostrat/hyper";
44
import {
55
useAppActions,
6-
useSearchState,
76
useAppState,
87
useContextPanelOpen,
98
} from "../../app-state";
@@ -71,7 +70,6 @@ function ResultList({ searchResults }) {
7170
{
7271
key,
7372
onClick() {
74-
console.log("Clicked", item);
7573
onSelectResult(item);
7674
},
7775
},
@@ -85,7 +83,7 @@ function ResultList({ searchResults }) {
8583
}
8684

8785
function SearchResults({ className }) {
88-
const { searchResults } = useSearchState();
86+
const searchResults = useAppState((s) => s.core.searchResults);
8987
className = classNames(className, "search-results-card");
9088

9189
return h(Card, { className }, h(ResultList, { searchResults }));

0 commit comments

Comments
 (0)