Skip to content

Commit 687448e

Browse files
committed
Updated filtering approaches
1 parent b08e092 commit 687448e

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

pages/columns/+Page.ts

Lines changed: 25 additions & 7 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;
@@ -432,7 +437,7 @@ function LexFilters() {
432437
async function _fetchFilterItems(inputText: string) {
433438
// Fetch filter items from the API based on input text, using the PostgREST client API
434439
const res = postgrest
435-
.from("col_filter")
440+
.from("col_filters")
436441
.select("*")
437442
.ilike("name", `%${inputText}%`)
438443
.limit(5);
@@ -473,6 +478,10 @@ function routeForFilterKey(key: ColumnFilterKey): string {
473478
return "strat-names";
474479
case "intervals":
475480
return "intervals";
481+
case "concepts":
482+
return "concepts";
483+
case "environments":
484+
return "environments";
476485
}
477486
}
478487

@@ -484,33 +493,42 @@ function filterKeyFromType(type: string): ColumnFilterKey | null {
484493
return "stratNames";
485494
case "interval":
486495
return "intervals";
496+
case "concept":
497+
return "concepts";
498+
case "environment":
499+
return "environments";
487500
default:
488501
return null;
489502
}
490503
}
491504

492-
function paramNameForFilterKey(key: ColumnFilterKey): string {
505+
function paramNameForFilterKey(
506+
key: ColumnFilterKey
507+
): keyof ColumnFilterOptions {
493508
switch (key) {
494509
case "liths":
495510
return "liths";
496511
case "stratNames":
497512
return "strat_names";
498513
case "intervals":
499514
return "intervals";
515+
case "concepts":
516+
return "strat_name_concepts";
517+
case "environments":
518+
return "environments";
500519
}
501520
}
502521

503522
function buildParamsFromFilters(
504-
filters: ColumnFilterDef[],
505-
// Allow multiple filters per category (not supported in API v2)
506-
allowMultiple = false
523+
filters: ColumnFilterDef[]
507524
): Partial<ColumnFilterOptions> {
508525
const params: Record<string, string> = {};
509526
if (filters == null) return params;
510527
let filterData: Partial<ColumnFilterOptions> = {};
511528
for (const filter of filters) {
512529
const key = paramNameForFilterKey(filter.type);
513-
if (allowMultiple) {
530+
if (key == "strat_names" || key == "strat_name_concepts") {
531+
// We can add multiple parameters of each type
514532
filterData[key] ??= [];
515533
} else {
516534
filterData[key] = [];

pages/columns/grouped-cols.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export interface ColumnFilterOptions {
6666
status_code?: string;
6767
empty?: boolean;
6868
strat_names?: number[];
69+
strat_name_concepts?: number[];
70+
environments?: number[];
6971
intervals?: number[];
7072
liths?: number[];
7173
nameFuzzyMatch?: string;
@@ -84,8 +86,19 @@ async function fetchColumns(opts: ColumnFilterOptions) {
8486

8587
// Empty and name fuzzy match are not supported yet
8688
if (opts.strat_names) {
87-
for (const sn of opts.strat_names) {
88-
params.append("strat_name_id", sn.toString());
89+
params.append("strat_name_id", buildQueryArg(opts.strat_names));
90+
}
91+
92+
if (opts.strat_name_concepts) {
93+
params.append(
94+
"strat_name_concept_id",
95+
buildQueryArg(opts.strat_name_concepts)
96+
);
97+
}
98+
99+
if (opts.environments) {
100+
for (const env of opts.environments) {
101+
params.append("env_id", env.toString());
89102
}
90103
}
91104

@@ -101,6 +114,11 @@ async function fetchColumns(opts: ColumnFilterOptions) {
101114
}
102115
}
103116

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

0 commit comments

Comments
 (0)