Skip to content

Commit

Permalink
#1269 | Handle dummy address level in hierarchical location select
Browse files Browse the repository at this point in the history
  • Loading branch information
1t5j0y committed Jul 2, 2024
1 parent c98028c commit 23983bd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 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.74",
"openchs-models": "1.31.81",
"popper.js": "^1.14.3",
"prismjs": "^1.17.1",
"prop-types": "^15.7.2",
Expand Down
23 changes: 8 additions & 15 deletions src/dataEntryApp/components/HierarchicalLocationSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import React, { useEffect, useState } from "react";
import _ from "lodash";
import { useSelector } from "react-redux";
import httpClient from "../../common/utils/httpClient";
import { Individual } from "openchs-models";

const HierarchicalLocationSelect = ({ minLevelTypeId, onSelect, selectedLocation }) => {
const allAddressLevelTypes = useSelector(
state => state.dataEntry.metadata.operationalModules.allAddressLevels
);
const allAddressLevelTypes = useSelector(state => state.dataEntry.metadata.operationalModules.allAddressLevels);
const selectedAddressLevelType =
_.isNil(selectedLocation) || _.isEqual(selectedLocation.uuid, "")
_.isNil(selectedLocation) ||
_.isEqual(selectedLocation.uuid, "") ||
_.isEqual(selectedLocation.uuid, Individual.getAddressLevelDummyUUID())
? _.find(allAddressLevelTypes, alt => _.isNil(alt.parent))
: _.find(allAddressLevelTypes, alt => alt.name === selectedLocation.type);
const [selectedAddressLevels, setSelectedAddressLevels] = useState([
Expand Down Expand Up @@ -51,9 +52,7 @@ const HierarchicalLocationSelect = ({ minLevelTypeId, onSelect, selectedLocation
addressLevel => addressLevel.addressLevelType.uuid === addressLevelType.uuid
);
const newSelectedAddressLevels =
indexToBeChanged === -1
? selectedAddressLevelsClone
: selectedAddressLevelsClone.splice(0, indexToBeChanged);
indexToBeChanged === -1 ? selectedAddressLevelsClone : selectedAddressLevelsClone.splice(0, indexToBeChanged);
newSelectedAddressLevels.push({ addressLevelType, value: addressLevel });
setSelectedAddressLevels(newSelectedAddressLevels);
if (finalValueAvailable(newSelectedAddressLevels)) {
Expand All @@ -69,14 +68,8 @@ const HierarchicalLocationSelect = ({ minLevelTypeId, onSelect, selectedLocation

const addNextLineIfRequired = newSelectedAddressLevels => {
const lastAddressLevel = _.last(newSelectedAddressLevels);
const nextAddressLevelType = _.find(
addressLevelTypes,
alt => alt.parent && alt.parent.uuid === lastAddressLevel.addressLevelType.uuid
);
setSelectedAddressLevels([
...newSelectedAddressLevels,
{ addressLevelType: nextAddressLevelType }
]);
const nextAddressLevelType = _.find(addressLevelTypes, alt => alt.parent && alt.parent.uuid === lastAddressLevel.addressLevelType.uuid);
setSelectedAddressLevels([...newSelectedAddressLevels, { addressLevelType: nextAddressLevelType }]);
};
return (
<div>
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].74:
version "1.31.74"
resolved "https://registry.yarnpkg.com/openchs-models/-/openchs-models-1.31.74.tgz#81164cb002b0bbe6aec86892b9b8eea524b7cad6"
integrity sha512-NdIBF0o69SNytOMYu0HS9PHbeHFmcDr2Zpa6+h24RrQeJLDxMN6fz8yQRyHDWqzuIisS0XQXieb3nQW9WnWjaQ==
[email protected].81:
version "1.31.81"
resolved "https://registry.yarnpkg.com/openchs-models/-/openchs-models-1.31.81.tgz#8c873420df888aaae5529a7a66055f1dad70f807"
integrity sha512-V+s6vzD9F0kMzExxe09tTo2Q2Fs9fuDjgOArMjvnRPa4GNC1rPk8Eod9Uf61C48Ke1NXIR8oW40s7IUTScZRpA==
dependencies:
uuid "^9.0.1"

Expand Down Expand Up @@ -16939,6 +16939,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 23983bd

Please sign in to comment.