Skip to content

Commit bf1faba

Browse files
authored
Merge pull request #393 from UW-Macrostrat/column-filter-updates
Column filter updates
2 parents 785d95e + 9bc455e commit bf1faba

File tree

26 files changed

+60
-2627
lines changed

26 files changed

+60
-2627
lines changed

pages/columns/+Page.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ function ColumnMapContainer(props) {
5050
);
5151
}
5252

53-
type ColumnFilterKey = "liths" | "stratNames" | "intervals";
53+
type ColumnFilterKey =
54+
| "liths"
55+
| "stratNames"
56+
| "intervals"
57+
| "concepts"
58+
| "environments";
5459

5560
type ColumnFilterDef = {
5661
type: ColumnFilterKey;
@@ -366,9 +371,18 @@ function ColumnGroup({ data, linkPrefix }) {
366371
}
367372

368373
function ColumnItem({ data, linkPrefix = "/" }) {
369-
const { col_id, col_name, units } = data;
374+
const { col_id, col_name, t_units, t_sections } = data;
370375

371-
const unitsText = units?.length > 0 ? `${units?.length} units` : "empty";
376+
const unitsText = t_units > 0 ? `${t_units} units` : "no units";
377+
378+
let gbpTag = null;
379+
if (t_sections > 0) {
380+
gbpTag = h(
381+
Tag,
382+
{ minimal: true, color: "goldenrod", size: "small" },
383+
`${t_sections} packages`
384+
);
385+
}
372386

373387
const href = linkPrefix + `columns/${col_id}`;
374388
return h(
@@ -388,13 +402,13 @@ function ColumnItem({ data, linkPrefix = "/" }) {
388402
{ minimal: true, color: "lightgreen", size: "small" },
389403
"in process"
390404
),
391-
" ",
405+
gbpTag,
392406
h(
393407
Tag,
394408
{
395409
minimal: true,
396410
size: "small",
397-
color: units?.length === 0 ? "orange" : "dodgerblue",
411+
color: t_units == 0 ? "orange" : "dodgerblue",
398412
},
399413
unitsText
400414
),
@@ -432,7 +446,7 @@ function LexFilters() {
432446
async function _fetchFilterItems(inputText: string) {
433447
// Fetch filter items from the API based on input text, using the PostgREST client API
434448
const res = postgrest
435-
.from("col_filter")
449+
.from("col_filters")
436450
.select("*")
437451
.ilike("name", `%${inputText}%`)
438452
.limit(5);
@@ -473,6 +487,10 @@ function routeForFilterKey(key: ColumnFilterKey): string {
473487
return "strat-names";
474488
case "intervals":
475489
return "intervals";
490+
case "concepts":
491+
return "concepts";
492+
case "environments":
493+
return "environments";
476494
}
477495
}
478496

@@ -484,33 +502,42 @@ function filterKeyFromType(type: string): ColumnFilterKey | null {
484502
return "stratNames";
485503
case "interval":
486504
return "intervals";
505+
case "concept":
506+
return "concepts";
507+
case "environment":
508+
return "environments";
487509
default:
488510
return null;
489511
}
490512
}
491513

492-
function paramNameForFilterKey(key: ColumnFilterKey): string {
514+
function paramNameForFilterKey(
515+
key: ColumnFilterKey
516+
): keyof ColumnFilterOptions {
493517
switch (key) {
494518
case "liths":
495519
return "liths";
496520
case "stratNames":
497521
return "strat_names";
498522
case "intervals":
499523
return "intervals";
524+
case "concepts":
525+
return "strat_name_concepts";
526+
case "environments":
527+
return "environments";
500528
}
501529
}
502530

503531
function buildParamsFromFilters(
504-
filters: ColumnFilterDef[],
505-
// Allow multiple filters per category (not supported in API v2)
506-
allowMultiple = false
532+
filters: ColumnFilterDef[]
507533
): Partial<ColumnFilterOptions> {
508534
const params: Record<string, string> = {};
509535
if (filters == null) return params;
510536
let filterData: Partial<ColumnFilterOptions> = {};
511537
for (const filter of filters) {
512538
const key = paramNameForFilterKey(filter.type);
513-
if (allowMultiple) {
539+
if (key == "strat_names" || key == "strat_name_concepts") {
540+
// We can add multiple parameters of each type
514541
filterData[key] ??= [];
515542
} else {
516543
filterData[key] = [];

pages/columns/grouped-cols.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ interface ColumnResponseShort {
1212
col_area: number;
1313
col_type: "column" | "section";
1414
refs: number[];
15+
t_units: number;
16+
t_sections: number;
1517
}
1618

1719
export interface ColumnGroup {
@@ -66,6 +68,8 @@ export interface ColumnFilterOptions {
6668
status_code?: string;
6769
empty?: boolean;
6870
strat_names?: number[];
71+
strat_name_concepts?: number[];
72+
environments?: number[];
6973
intervals?: number[];
7074
liths?: number[];
7175
nameFuzzyMatch?: string;
@@ -84,8 +88,19 @@ async function fetchColumns(opts: ColumnFilterOptions) {
8488

8589
// Empty and name fuzzy match are not supported yet
8690
if (opts.strat_names) {
87-
for (const sn of opts.strat_names) {
88-
params.append("strat_name_id", sn.toString());
91+
params.append("strat_name_id", buildQueryArg(opts.strat_names));
92+
}
93+
94+
if (opts.strat_name_concepts) {
95+
params.append(
96+
"strat_name_concept_id",
97+
buildQueryArg(opts.strat_name_concepts)
98+
);
99+
}
100+
101+
if (opts.environments) {
102+
for (const env of opts.environments) {
103+
params.append("env_id", env.toString());
89104
}
90105
}
91106

@@ -101,6 +116,11 @@ async function fetchColumns(opts: ColumnFilterOptions) {
101116
}
102117
}
103118

119+
function buildQueryArg(values: number[]) {
120+
d;
121+
return values.map((v) => v.toString()).join(",");
122+
}
123+
104124
return (await fetchAPIV2Result("/columns", params)) as Promise<{
105125
data: ColumnResponseShort[];
106126
refs: { [key: number]: string };

0 commit comments

Comments
 (0)