Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions pages/columns/+Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ function ColumnMapContainer(props) {
);
}

type ColumnFilterKey = "liths" | "stratNames" | "intervals";
type ColumnFilterKey =
| "liths"
| "stratNames"
| "intervals"
| "concepts"
| "environments";

type ColumnFilterDef = {
type: ColumnFilterKey;
Expand Down Expand Up @@ -366,9 +371,18 @@ function ColumnGroup({ data, linkPrefix }) {
}

function ColumnItem({ data, linkPrefix = "/" }) {
const { col_id, col_name, units } = data;
const { col_id, col_name, t_units, t_sections } = data;

const unitsText = units?.length > 0 ? `${units?.length} units` : "empty";
const unitsText = t_units > 0 ? `${t_units} units` : "no units";

let gbpTag = null;
if (t_sections > 0) {
gbpTag = h(
Tag,
{ minimal: true, color: "goldenrod", size: "small" },
`${t_sections} packages`
);
}

const href = linkPrefix + `columns/${col_id}`;
return h(
Expand All @@ -388,13 +402,13 @@ function ColumnItem({ data, linkPrefix = "/" }) {
{ minimal: true, color: "lightgreen", size: "small" },
"in process"
),
" ",
gbpTag,
h(
Tag,
{
minimal: true,
size: "small",
color: units?.length === 0 ? "orange" : "dodgerblue",
color: t_units == 0 ? "orange" : "dodgerblue",
},
unitsText
),
Expand Down Expand Up @@ -432,7 +446,7 @@ function LexFilters() {
async function _fetchFilterItems(inputText: string) {
// Fetch filter items from the API based on input text, using the PostgREST client API
const res = postgrest
.from("col_filter")
.from("col_filters")
.select("*")
.ilike("name", `%${inputText}%`)
.limit(5);
Expand Down Expand Up @@ -473,6 +487,10 @@ function routeForFilterKey(key: ColumnFilterKey): string {
return "strat-names";
case "intervals":
return "intervals";
case "concepts":
return "concepts";
case "environments":
return "environments";
}
}

Expand All @@ -484,33 +502,42 @@ function filterKeyFromType(type: string): ColumnFilterKey | null {
return "stratNames";
case "interval":
return "intervals";
case "concept":
return "concepts";
case "environment":
return "environments";
default:
return null;
}
}

function paramNameForFilterKey(key: ColumnFilterKey): string {
function paramNameForFilterKey(
key: ColumnFilterKey
): keyof ColumnFilterOptions {
switch (key) {
case "liths":
return "liths";
case "stratNames":
return "strat_names";
case "intervals":
return "intervals";
case "concepts":
return "strat_name_concepts";
case "environments":
return "environments";
}
}

function buildParamsFromFilters(
filters: ColumnFilterDef[],
// Allow multiple filters per category (not supported in API v2)
allowMultiple = false
filters: ColumnFilterDef[]
): Partial<ColumnFilterOptions> {
const params: Record<string, string> = {};
if (filters == null) return params;
let filterData: Partial<ColumnFilterOptions> = {};
for (const filter of filters) {
const key = paramNameForFilterKey(filter.type);
if (allowMultiple) {
if (key == "strat_names" || key == "strat_name_concepts") {
// We can add multiple parameters of each type
filterData[key] ??= [];
} else {
filterData[key] = [];
Expand Down
24 changes: 22 additions & 2 deletions pages/columns/grouped-cols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface ColumnResponseShort {
col_area: number;
col_type: "column" | "section";
refs: number[];
t_units: number;
t_sections: number;
}

export interface ColumnGroup {
Expand Down Expand Up @@ -66,6 +68,8 @@ export interface ColumnFilterOptions {
status_code?: string;
empty?: boolean;
strat_names?: number[];
strat_name_concepts?: number[];
environments?: number[];
intervals?: number[];
liths?: number[];
nameFuzzyMatch?: string;
Expand All @@ -84,8 +88,19 @@ async function fetchColumns(opts: ColumnFilterOptions) {

// Empty and name fuzzy match are not supported yet
if (opts.strat_names) {
for (const sn of opts.strat_names) {
params.append("strat_name_id", sn.toString());
params.append("strat_name_id", buildQueryArg(opts.strat_names));
}

if (opts.strat_name_concepts) {
params.append(
"strat_name_concept_id",
buildQueryArg(opts.strat_name_concepts)
);
}

if (opts.environments) {
for (const env of opts.environments) {
params.append("env_id", env.toString());
}
}

Expand All @@ -101,6 +116,11 @@ async function fetchColumns(opts: ColumnFilterOptions) {
}
}

function buildQueryArg(values: number[]) {
d;
return values.map((v) => v.toString()).join(",");
}

return (await fetchAPIV2Result("/columns", params)) as Promise<{
data: ColumnResponseShort[];
refs: { [key: number]: string };
Expand Down
Loading