diff --git a/moped-editor/src/components/GridTable/FiltersCommonOperators.js b/moped-editor/src/components/GridTable/FiltersCommonOperators.js index 708875d09f..0f5ede3767 100644 --- a/moped-editor/src/components/GridTable/FiltersCommonOperators.js +++ b/moped-editor/src/components/GridTable/FiltersCommonOperators.js @@ -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, + }, }; diff --git a/moped-editor/src/components/GridTable/helpers.js b/moped-editor/src/components/GridTable/helpers.js index 47f634e818..1cd6e792cd 100644 --- a/moped-editor/src/components/GridTable/helpers.js +++ b/moped-editor/src/components/GridTable/helpers.js @@ -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); } diff --git a/moped-editor/src/views/projects/projectsListView/ProjectsListViewFiltersConf.js b/moped-editor/src/views/projects/projectsListView/ProjectsListViewFiltersConf.js index e2ba654c90..fe302b2072 100644 --- a/moped-editor/src/views/projects/projectsListView/ProjectsListViewFiltersConf.js +++ b/moped-editor/src/views/projects/projectsListView/ProjectsListViewFiltersConf.js @@ -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", ]; /** @@ -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"], @@ -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: { diff --git a/moped-editor/src/views/projects/projectsListView/useProjectListViewQuery/useAdvancedSearch.js b/moped-editor/src/views/projects/projectsListView/useProjectListViewQuery/useAdvancedSearch.js index c5b96b3a5b..236fa19d76 100644 --- a/moped-editor/src/views/projects/projectsListView/useProjectListViewQuery/useAdvancedSearch.js +++ b/moped-editor/src/views/projects/projectsListView/useProjectListViewQuery/useAdvancedSearch.js @@ -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;