Skip to content

Commit

Permalink
Merge pull request #1277 from cityofaustin/add-council-districts-to-a…
Browse files Browse the repository at this point in the history
…dvanced-search

Add council districts to advanced search
  • Loading branch information
johnclary authored Feb 15, 2024
2 parents 693bb3d + edc111f commit a6d1399
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
28 changes: 28 additions & 0 deletions moped-editor/src/components/GridTable/FiltersCommonOperators.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,32 @@ export const FiltersCommonOperators = {
type: "array",
envelope: "false",
},
council_districts_array_is_null: {
operator: "_is_null",
label: "is blank",
description: "Project has no mapped components in council districts",
type: "array",
envelope: "true",
},
council_districts_array_is_not_null: {
operator: "_is_null",
label: "is not blank",
description: "Project has components in council districts",
type: "array",
envelope: "false",
},
council_districts_array_contains: {
operator: "_contains",
label: "contains",
description: "Project has components in a given council district",
type: "array",
envelope: false,
},
council_districts_array_is: {
operator: "_eq",
label: "is",
description: "Project has components in, and only in, specific council districts",
type: "array",
envelope: false,
},
};
4 changes: 2 additions & 2 deletions moped-editor/src/components/GridTable/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export const generateEmptyFilter = () => {
* @returns {boolean}
*/
export const checkIsValidInput = (filterParameter, type) => {
// If we are testing a number type field with a non null value
if (type === "number" && !!filterParameter.value) {
// If we are testing a number or array type field with a non null value
if (["number", "array"].includes(type) && !!filterParameter.value) {
// Return whether string only contains digits
return !/[^0-9]/.test(filterParameter.value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export const OPERATORS_WITHOUT_SEARCH_VALUES = [
"subprojects_array_is_not_null",
"string_is_blank",
"string_is_not_blank",
"council_districts_array_is_null",
"council_districts_array_is_not_null",
];

/**
Expand Down Expand Up @@ -398,7 +400,7 @@ export const PROJECT_LIST_VIEW_FILTERS_CONFIG = {
},
{
name: "children_project_ids",
label: "Has Subprojects",
label: "Has subprojects",
placeholder: "Subproject",
type: "array",
operators: ["subprojects_array_is_null", "subprojects_array_is_not_null"],
Expand All @@ -414,6 +416,18 @@ export const PROJECT_LIST_VIEW_FILTERS_CONFIG = {
"string_is_not_null",
],
},
{
name: "project_and_child_project_council_districts",
label: "Council districts",
placeholder: "District",
type: "array",
operators: [
"council_districts_array_is_null",
"council_districts_array_is_not_null",
"council_districts_array_contains",
"council_districts_array_is",
],
},
],

operators: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const makeAdvancedSearchWhereFilters = (filters) =>

// If it is a number or boolean, it does not need quotation marks
// Otherwise, add quotation marks for the query to identify as string
value = type in ["number", "boolean"] ? value : `"${value}"`;
if (type === "array") {
value = `[${value}]`;
} else if (!["number", "boolean"].includes(type)) {
value = `"${value}"`;
}
} else {
// We don't have a value
return null;
Expand Down

0 comments on commit a6d1399

Please sign in to comment.