e2corporation commented on code in PR #3297:
URL: https://github.com/apache/incubator-devlake/pull/3297#discussion_r992406188


##########
config-ui/src/pages/configure/settings/jira.jsx:
##########
@@ -177,58 +177,35 @@ export default function JiraSettings(props) {
   }, [typeMappingAll, onSettingsChange, configuredBoard?.id])
 
   useEffect(() => {
-    if (typeMappingBug && typeMappingIncident && typeMappingRequirement) {
-      const RequirementMappings =
-        typeMappingRequirement !== ''
-          ? typeMappingRequirement.map((r) =>
-              createTypeMapObject(r.value, MAPPING_TYPES.Requirement)
-            )
-          : []
-      const IncidentMappings =
-        typeMappingIncident !== ''
-          ? typeMappingIncident.map((i) =>
-              createTypeMapObject(i.value, MAPPING_TYPES.Incident)
-            )
-          : []
-      const BugMappings =
-        typeMappingBug !== ''
-          ? typeMappingBug.map((b) =>
-              createTypeMapObject(b.value, MAPPING_TYPES.Bug)
-            )
-          : []
-      const CombinedMappings = [
-        ...RequirementMappings,
-        ...IncidentMappings,
-        ...BugMappings
-      ].filter((m) => m !== null)
-      const MappingTypeObjects = CombinedMappings.reduce((pV, cV) => {
-        return { ...cV, ...pV }
-      }, {})
-      setTypeMappingAll(MappingTypeObjects)
-      console.log(
-        '>> INCIDENT TYPE MAPPING OBJECTS....',
-        RequirementMappings,
-        IncidentMappings,
-        BugMappings
-      )
-      console.log('>> ALL MAPPINGS COMBINED...', CombinedMappings)
-      console.log(
-        '>> FINAL MAPPING OBJECTS FOR API REQUEST...',
-        MappingTypeObjects
-      )
-    }
-  }, [typeMappingBug, typeMappingIncident, typeMappingRequirement])
+    setTypeMappingAll((ma) => ({
+      ...ma,
+      ...(typeMappingBug || [])
+        .map((r) => createTypeMapObject(r.value, MAPPING_TYPES.Bug))
+        .reduce((c, p) => ({ ...c, ...p }), {})
+    }))
+  }, [typeMappingBug])
 
   useEffect(() => {
-    console.log('>> CONN SETTINGS OBJECT ', connection)
-    if (connection && connection.id) {
-      // Parse Type Mappings (V2)
-      // setStatusMappings([])
-    }
-  }, [connection])
+    setTypeMappingAll((ma) => ({
+      ...ma,
+      ...(typeMappingIncident || [])
+        .map((r) => createTypeMapObject(r.value, MAPPING_TYPES.Incident))
+        .reduce((c, p) => ({ ...c, ...p }), {})
+    }))
+  }, [typeMappingIncident])
+
+  useEffect(() => {
+    setTypeMappingAll((ma) => ({
+      ...ma,
+      ...(typeMappingRequirement || [])
+        .map((r) => createTypeMapObject(r.value, MAPPING_TYPES.Requirement))
+        .reduce((c, p) => ({ ...c, ...p }), {})
+    }))
+  }, [typeMappingRequirement])

Review Comment:
   @mintsweet In the past I recalled using 3 separate Effects only to find out 
that it caused a sync-issue on the UI when selectors were used rapidly, 
resulting in `typeMappingAll` being overwritten. I am willing to try 3 separate 
Effects again, assuming it directly addresses the bug reported on issue 3295.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to