From 8c5478fe6871a10992861643b67213d94368fefc Mon Sep 17 00:00:00 2001 From: Joy A Date: Wed, 29 May 2024 10:28:38 +0530 Subject: [PATCH] #1204 | Allow setting subjectType on custom dashboard filter --- package.json | 2 +- .../components/CreateEditFiltersV2.js | 74 +++++++------------ src/common/service/DashboardService.js | 3 +- .../Dashboard/ShowDashboardFilters.js | 10 +++ yarn.lock | 21 +++++- 5 files changed, 57 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index cafaffb3d..daff79af0 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "material-table": "1.43.0", "moment": "^2.22.2", "openchs-idi": "git+https://github.com/avniproject/openchs-idi#b6c57e051b91ed4bc2634f4f087dba51cc3a01c8", - "openchs-models": "1.31.75", + "openchs-models": "1.31.77", "popper.js": "^1.14.3", "prismjs": "^1.17.1", "prop-types": "^15.7.2", diff --git a/src/adminApp/components/CreateEditFiltersV2.js b/src/adminApp/components/CreateEditFiltersV2.js index f19829342..fd94f85d0 100644 --- a/src/adminApp/components/CreateEditFiltersV2.js +++ b/src/adminApp/components/CreateEditFiltersV2.js @@ -15,28 +15,14 @@ import { AvniFormLabel } from "../../common/components/AvniFormLabel"; import { AvniTextField } from "../../common/components/AvniTextField"; import ConceptService from "../../common/service/ConceptService"; -function MultipleEntitySelect({ - name, - placeholder, - selectedEntities, - options, - onChange, - toolTipKey -}) { +function MultipleEntitySelect({ name, placeholder, selectedEntities, options, onChange, toolTipKey }) { const selectedValues = _.intersectionWith(options, selectedEntities, (a, b) => { return a.value.uuid === b.uuid; }); return (
-
); } @@ -46,23 +32,17 @@ function SingleSelect({ name, placeholder, value, options, onChange, toolTipKey return (
-
); } -function SingleEntitySelect({ name, placeholder, selectedEntity, options, onChange, toolTipKey }) { +function SingleEntitySelect({ name, placeholder, selectedEntity, options, onChange, toolTipKey, isClearable = false }) { const selectValue = _.find(options, x => x.value.uuid === _.get(selectedEntity, "uuid")); return (
-
); } @@ -75,12 +55,7 @@ function isSaveDisabled(filterConfig, filterName) { return !filterConfig.isValid() || _.isEmpty(filterName); } -export const CreateEditFiltersV2 = ({ - selectedFilter, - operationalModules, - documentationFileName, - dashboardFilterSave -}) => { +export const CreateEditFiltersV2 = ({ selectedFilter, operationalModules, documentationFileName, dashboardFilterSave }) => { const isNew = _.isNil(_.get(selectedFilter, "uuid")); const { t } = useTranslation(); const typeOptions = values(CustomFilter.getDashboardFilterTypes()).map(s => ({ @@ -100,9 +75,8 @@ export const CreateEditFiltersV2 = ({ isNew ? new DashboardFilterConfig() : selectedFilter.filterConfig ); - const programOptions = mapToOptions( - MetaDataService.getProgramsForSubjectType(programs, null, formMappings) - ); + const subjectTypeOptions = mapToOptions(subjectTypes); + const programOptions = mapToOptions(MetaDataService.getProgramsForSubjectType(programs, null, formMappings)); const encounterTypeOptions = mapToOptions( MetaDataService.getEncounterTypes_For_SubjectTypeAndPrograms( encounterTypes, @@ -111,9 +85,7 @@ export const CreateEditFiltersV2 = ({ formMappings ) ); - const groupSubjectTypeOptions = mapToOptions( - MetaDataService.getPossibleGroupSubjectTypesFor(subjectTypes, filterConfig.subjectType) - ); + const groupSubjectTypeOptions = mapToOptions(MetaDataService.getPossibleGroupSubjectTypesFor(subjectTypes, filterConfig.subjectType)); const [messageStatus] = useState({ message: "", display: false }); const [snackBarStatus, setSnackBarStatus] = useState(true); @@ -178,6 +150,22 @@ export const CreateEditFiltersV2 = ({ toolTipKey="APP_DESIGNER_FILTER_TYPE" /> + {!_.isEmpty(filterConfig.type) && !filterConfig.isSubjectTypeFilter() && subjectTypeOptions.length > 0 && ( + { + console.log(x); + filterConfig.setSubjectType(x && x.value); + updateFilterConfig(filterConfig); + }} + toolTipKey="APP_DESIGNER_FILTER_SUBJECT_TYPE" + isClearable={true} + /> + )} + {filterConfig.isGroupSubjectTypeFilter() && groupSubjectTypeOptions.length > 0 && ( {filterConfig.isConceptTypeFilter() && (
- +
- +

diff --git a/src/common/service/DashboardService.js b/src/common/service/DashboardService.js index 1cc1a2bcc..2dea58f17 100644 --- a/src/common/service/DashboardService.js +++ b/src/common/service/DashboardService.js @@ -67,7 +67,8 @@ class DashboardService { const { subjectTypes, programs, encounterTypes } = operationalModules; const filterConfigInResponse = x.filterConfig; - filterConfig.subjectType = EntityService.findByUuid(subjectTypes, filterConfigInResponse.subjectTypeUUID); + filterConfig.subjectType = + filterConfigInResponse.subjectTypeUUID && EntityService.findByUuid(subjectTypes, filterConfigInResponse.subjectTypeUUID); filterConfig.widget = filterConfigInResponse.widget; filterConfig.type = filterConfigInResponse.type; if (filterConfigInResponse.type === CustomFilter.type.GroupSubject) { diff --git a/src/formDesigner/components/Dashboard/ShowDashboardFilters.js b/src/formDesigner/components/Dashboard/ShowDashboardFilters.js index 093e30d67..8b76bbf98 100644 --- a/src/formDesigner/components/Dashboard/ShowDashboardFilters.js +++ b/src/formDesigner/components/Dashboard/ShowDashboardFilters.js @@ -4,6 +4,7 @@ import _ from "lodash"; import Edit from "@material-ui/icons/Edit"; import Delete from "@material-ui/icons/DeleteOutline"; import materialTableIcons from "../../../common/material-table/MaterialTableIcons"; +import EntityService from "../../../common/service/EntityService"; function getFilterColumns(operationalModules) { if (_.isNil(operationalModules.subjectTypes)) return []; @@ -15,6 +16,15 @@ function getFilterColumns(operationalModules) { return rowData.name; } }, + { + title: "Subject Type", + render: rowData => { + const subjectType = + rowData.filterConfig.subjectType && + EntityService.findByUuid(operationalModules.subjectTypes, rowData.filterConfig.subjectType.uuid); + return subjectType ? subjectType.name : ""; + } + }, { title: "Filter Type", render: rowData => { diff --git a/yarn.lock b/yarn.lock index 299dccc82..1c3687a99 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13611,10 +13611,10 @@ open@^7.1.0: grunt "^1.0.3" webpack "^4.13.0" -openchs-models@1.31.75: - version "1.31.75" - resolved "https://registry.yarnpkg.com/openchs-models/-/openchs-models-1.31.75.tgz#4d4c007692616a01eb94819fe4dc7c5dca8881de" - integrity sha512-mQEyV0eHqLXcyArq4zw745gdiEFu9vp925KOHJajwS+l58PRkzdDc1wq6EwAm3jajFxOYucp2gd6aGH81Op5xQ== +openchs-models@1.31.77: + version "1.31.77" + resolved "https://registry.yarnpkg.com/openchs-models/-/openchs-models-1.31.77.tgz#e3edb6c275e6477acd1eefdf36968ab0a80f3bfe" + integrity sha512-hZHPtlyzoP+euqhGC+6hN6Ziy3Bt4zBH2I8OdSSzd6AgloJVmB8IgL26QKo0HioqS1xQ7hujECXH536zaikrXA== dependencies: uuid "^9.0.1" @@ -16934,6 +16934,19 @@ rsvp@^4.8.4: "rules-config@github:avniproject/rules-config#fe552da405368bfd138e2f38e605c1d307e3ebe4": version "0.0.1" resolved "https://codeload.github.com/avniproject/rules-config/tar.gz/fe552da405368bfd138e2f38e605c1d307e3ebe4" + dependencies: + "@quasar/babel-preset-app" "^2.0.1" + babel-preset-env "^1.7.0" + babel-register "^6.26.0" + chai "^4.1.2" + lodash "^4.17.11" + moment "^2.29.4" + superagent "^3.8.3" + test "^0.6.0" + uglifyjs-webpack-plugin "^1.2.5" + webpack "^3.12.0" + webpack-cli "^3.0.3" + webpack-node-externals "1.6.0" run-async@^2.2.0, run-async@^2.4.0: version "2.4.1"