diff --git a/src/adminApp/user.js b/src/adminApp/user.js
index 774e1cd78..477ee1e1c 100644
--- a/src/adminApp/user.js
+++ b/src/adminApp/user.js
@@ -167,7 +167,7 @@ const formatLang = lang =>
.map(lang => lang.name)
.join("");
-const SubjectTypeSyncAttributeShow = ({ subjectType, ...props }) => (
+const SubjectTypeSyncAttributeShow = ({ subjectType, syncConceptValueMap, ...props }) => (
{`Sync settings for Subject Type: ${
subjectType.name
@@ -176,6 +176,7 @@ const SubjectTypeSyncAttributeShow = ({ subjectType, ...props }) => (
)}
@@ -183,39 +184,34 @@ const SubjectTypeSyncAttributeShow = ({ subjectType, ...props }) => (
)}
);
-const ConceptSyncAttributeShow = ({ subjectType, syncAttributeName, ...props }) => {
+const ConceptSyncAttributeShow = ({
+ subjectType,
+ syncConceptValueMap,
+ syncAttributeName,
+ ...props
+}) => {
const syncSettings = get(props.record, ["syncSettings", subjectType.name], {});
const conceptUUID = get(syncSettings, [syncAttributeName]);
if (isEmpty(conceptUUID)) return null;
- const [syncConceptValueMap, setSyncConceptValueMap] = useState(new Map());
- useEffect(() => {
- let isMounted = true;
- const newValMap = new Map();
-
- ConceptService.getAnswerConcepts(conceptUUID).then(content => {
- content.forEach(val => newValMap.set(val.id, val.name));
- if (isMounted) {
- setSyncConceptValueMap(newValMap);
- }
- });
- return () => {
- isMounted = false;
- };
- }, [conceptUUID]);
return (
{startCase(syncAttributeName)}
{map(get(syncSettings, `${syncAttributeName}Values`, []), value => (
-
+
))}
);
@@ -258,7 +254,11 @@ export const UserDetail = ({ user, hasEditUserPrivilege, ...props }) => {
/>
{map(syncAttributesData.subjectTypes, st => (
-
+
))}
{
+ const syncConceptValueMap = new Map();
+ const codedConceptUUIDSet = new Set();
+ sortedSubjectTypes.forEach(subject => {
+ const syncAttribute1UUID =
+ subject.syncAttribute1 &&
+ subject.syncAttribute1.dataType === "Coded" &&
+ subject.syncAttribute1.id;
+ const syncAttribute2UUID =
+ subject.syncAttribute2 &&
+ subject.syncAttribute2.dataType === "Coded" &&
+ subject.syncAttribute2.id;
+ syncAttribute1UUID && codedConceptUUIDSet.add(syncAttribute1UUID);
+ syncAttribute2UUID && codedConceptUUIDSet.add(syncAttribute2UUID);
+ });
+
+ for (const conceptUUID of codedConceptUUIDSet) {
+ const content = await ConceptService.getAnswerConcepts(conceptUUID);
+ content.forEach(val => {
+ syncConceptValueMap.set(val.id, val.name);
+ });
+ }
+ return syncConceptValueMap;
+};
+
function fetchSyncAttributeData(setSyncAttributesData) {
useEffect(() => {
+ let isMounted = true;
http.get("/subjectType/syncAttributesData").then(res => {
const {
subjectTypes,
@@ -459,12 +485,21 @@ function fetchSyncAttributeData(setSyncAttributesData) {
anySubjectTypeSyncByLocation
} = res.data;
const sortedSubjectTypes = sortBy(subjectTypes, "id");
- setSyncAttributesData({
- subjectTypes: sortedSubjectTypes,
- anySubjectTypeDirectlyAssignable,
- anySubjectTypeSyncByLocation
+
+ getSyncConceptValueMap(sortedSubjectTypes).then(syncConceptValueMap => {
+ if (isMounted) {
+ setSyncAttributesData({
+ subjectTypes: sortedSubjectTypes,
+ anySubjectTypeDirectlyAssignable,
+ anySubjectTypeSyncByLocation,
+ syncConceptValueMap
+ });
+ }
});
});
+ return () => {
+ isMounted = false;
+ };
}, []);
}