Skip to content

Commit

Permalink
(fix) O3-3713: fix infinite loading when conceptId is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
NethmiRodrigo committed Aug 8, 2024
1 parent 43d8af7 commit 913aca8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/interactive-builder/edit-question.modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
);
const [programWorkflows, setProgramWorkflows] = useState<Array<ProgramWorkflow>>([]);

const hasConceptChanged = selectedConcept && questionToEdit?.questionOptions?.concept !== selectedConcept?.uuid;
const hasConceptChanged =
selectedConcept &&
questionToEdit?.questionOptions.concept &&
questionToEdit?.questionOptions?.concept !== selectedConcept?.uuid;
const [addInlineDate, setAddInlineDate] = useState(false);

// Maps the data type of a concept to a date picker type.
Expand Down Expand Up @@ -276,8 +279,8 @@ const EditQuestionModal: React.FC<EditQuestionModalProps> = ({
rendering: fieldType ? fieldType : questionToEdit.questionOptions.rendering,
...((selectedConcept || questionToEdit.questionOptions.concept) && {
concept: selectedConcept ? selectedConcept.uuid : questionToEdit.questionOptions.concept,
conceptMappings: conceptMappings?.length ? conceptMappings : questionToEdit.questionOptions.conceptMappings,
}),
conceptMappings: conceptMappings?.length ? conceptMappings : questionToEdit.questionOptions.conceptMappings,
answers: mappedAnswers,
...(questionType === 'patientIdentifier' && {
identifierType: selectedPatientIdentifierType
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useConceptName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import useSWR from 'swr';
import { openmrsFetch, restBaseUrl } from '@openmrs/esm-framework';
import { isEmpty } from '@openmrs/openmrs-form-engine-lib';

export function useConceptName(conceptId: string | undefined) {
const customRepresentation = 'custom:(name:(display))';
Expand All @@ -10,6 +11,6 @@ export function useConceptName(conceptId: string | undefined) {
return {
conceptName: data?.data?.name?.display ?? null,
conceptNameLookupError: error,
isLoadingConceptName: (!data && !error) || false,
isLoadingConceptName: !conceptId || isEmpty(conceptId) ? false : (!data && !error) || false,
};
}

0 comments on commit 913aca8

Please sign in to comment.