Skip to content

Commit

Permalink
#1204 | Allow setting subjectType on custom dashboard filter
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed May 29, 2024
1 parent d502627 commit 8c5478f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
74 changes: 27 additions & 47 deletions src/adminApp/components/CreateEditFiltersV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div style={{ width: 400 }}>
<AvniFormLabel label={name} toolTipKey={toolTipKey} position={"top"} />
<Select
isMulti
placeholder={placeholder}
value={selectedValues}
options={options}
onChange={onChange}
maxMenuHeight={200}
/>
<Select isMulti placeholder={placeholder} value={selectedValues} options={options} onChange={onChange} maxMenuHeight={200} />
</div>
);
}
Expand All @@ -46,23 +32,17 @@ function SingleSelect({ name, placeholder, value, options, onChange, toolTipKey
return (
<div style={{ width: 400 }}>
<AvniFormLabel label={name} toolTipKey={toolTipKey} position={"top"} />
<Select
placeholder={placeholder}
value={selectValue}
options={options}
onChange={onChange}
maxMenuHeight={200}
/>
<Select placeholder={placeholder} value={selectValue} options={options} onChange={onChange} maxMenuHeight={200} />
</div>
);
}

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 (
<div style={{ width: 400 }}>
<AvniFormLabel label={name} toolTipKey={toolTipKey} position={"top"} />
<Select placeholder={placeholder} value={selectValue} options={options} onChange={onChange} />
<Select placeholder={placeholder} value={selectValue} options={options} onChange={onChange} isClearable={isClearable} />
</div>
);
}
Expand All @@ -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 => ({
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -178,6 +150,22 @@ export const CreateEditFiltersV2 = ({
toolTipKey="APP_DESIGNER_FILTER_TYPE"
/>
<Box m={1} />
{!_.isEmpty(filterConfig.type) && !filterConfig.isSubjectTypeFilter() && subjectTypeOptions.length > 0 && (
<SingleEntitySelect
name="Subject Type"
placeholder="Select Subject Type"
selectedEntity={filterConfig.subjectType}
options={subjectTypeOptions}
onChange={x => {
console.log(x);
filterConfig.setSubjectType(x && x.value);
updateFilterConfig(filterConfig);
}}
toolTipKey="APP_DESIGNER_FILTER_SUBJECT_TYPE"
isClearable={true}
/>
)}
<Box m={1} />
{filterConfig.isGroupSubjectTypeFilter() && groupSubjectTypeOptions.length > 0 && (
<SingleEntitySelect
name="Group Subject Type"
Expand All @@ -194,11 +182,7 @@ export const CreateEditFiltersV2 = ({
<Box m={1} />
{filterConfig.isConceptTypeFilter() && (
<div style={{ width: 400 }}>
<AvniFormLabel
label={"Select Concept"}
toolTipKey={"APP_DESIGNER_FILTER_CONCEPT_SEARCH"}
position={"top"}
/>
<AvniFormLabel label={"Select Concept"} toolTipKey={"APP_DESIGNER_FILTER_CONCEPT_SEARCH"} position={"top"} />
<AsyncSelect
cacheOptions
defaultOptions={conceptSuggestions}
Expand Down Expand Up @@ -276,11 +260,7 @@ export const CreateEditFiltersV2 = ({
<Box m={1} />
</div>
<Box m={1}>
<SaveComponent
name={t("save")}
onSubmit={saveFilter}
disabledFlag={isSaveDisabled(filterConfig, filterName)}
/>
<SaveComponent name={t("save")} onSubmit={saveFilter} disabledFlag={isSaveDisabled(filterConfig, filterName)} />
</Box>
<p />
</Box>
Expand Down
3 changes: 2 additions & 1 deletion src/common/service/DashboardService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/formDesigner/components/Dashboard/ShowDashboardFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand All @@ -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 => {
Expand Down
21 changes: 17 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13611,10 +13611,10 @@ open@^7.1.0:
grunt "^1.0.3"
webpack "^4.13.0"

[email protected].75:
version "1.31.75"
resolved "https://registry.yarnpkg.com/openchs-models/-/openchs-models-1.31.75.tgz#4d4c007692616a01eb94819fe4dc7c5dca8881de"
integrity sha512-mQEyV0eHqLXcyArq4zw745gdiEFu9vp925KOHJajwS+l58PRkzdDc1wq6EwAm3jajFxOYucp2gd6aGH81Op5xQ==
[email protected].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"

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 8c5478f

Please sign in to comment.