Skip to content

Commit

Permalink
avniproject/avni-client#1530 | During edit/create of filters, add sub…
Browse files Browse the repository at this point in the history
…jectType filter if needed
  • Loading branch information
himeshr committed Nov 28, 2024
1 parent 084cd8e commit ef162c7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const CreateEditDashboard = ({ edit, history, operationalModules, getOperational
};

const showFilterDialog = event => {
setSelectedFilter(null);
setShowAddFilterModal(true);
event.stopPropagation();
};
Expand Down
24 changes: 20 additions & 4 deletions src/formDesigner/components/Dashboard/DashboardReducer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _, { concat, reject } from "lodash";
import { ModelGeneral as General } from "openchs-models";
import _, { concat, every, reject, some } from "lodash";
import { CustomFilter, DashboardFilterConfig, ModelGeneral as General } from "openchs-models";
import WebDashboardSection from "../../../common/model/reports/WebDashboardSection";
import WebDashboard from "../../../common/model/reports/WebDashboard";

Expand Down Expand Up @@ -31,7 +31,7 @@ const setData = (thisIsNotNecessaryInThisCase, dashboard) => {
const addFilter = (dashboard, { modifiedFilter }) => {
modifiedFilter.uuid = General.randomUUID();
const newFilters = concat(dashboard.filters, modifiedFilter);
return { ...dashboard, filters: newFilters };
return { ...dashboard, filters: addSubjectTypeFilterIfNeeded(newFilters) };
};

const editFilter = (dashboard, { modifiedFilter, selectedFilter }) => {
Expand All @@ -41,7 +41,23 @@ const editFilter = (dashboard, { modifiedFilter, selectedFilter }) => {
modifiedFilter.uuid = selectedFilter.uuid;
}
filters.push(modifiedFilter);
return { ...dashboard, filters };
return { ...dashboard, filters: addSubjectTypeFilterIfNeeded(filters) };
};

const addSubjectTypeFilterIfNeeded = dashboardFilters => {
if (
some(dashboardFilters, x => x.filterConfig.subjectType) &&
every(dashboardFilters, x => x.filterConfig.type !== CustomFilter.type.SubjectType)
) {
const dashboardFilter = {
uuid: General.randomUUID(),
name: "Subject Type",
filterConfig: new DashboardFilterConfig()
};
dashboardFilter.filterConfig.type = CustomFilter.type.SubjectType;
dashboardFilters.push(dashboardFilter);
}
return dashboardFilters;
};

const deleteFilter = (dashboard, { selectedFilter }) => {
Expand Down

0 comments on commit ef162c7

Please sign in to comment.