Skip to content

Commit

Permalink
(fix) Add optional chaining to extensions mapping in VisitSummary com…
Browse files Browse the repository at this point in the history
…ponent

This fix addresses a potential runtime error in the VisitSummary component when a visit has no extensions. The error occurs due to recent changes in the [useConnectedExtensions](openmrs/openmrs-esm-core#1154) hook, which possibly now loads extensions asynchronously.

The [current implementation](https://github.com/openmrs/openmrs-esm-patient-chart/blob/3b13b5b5d7ce39dbe54508a2041ececb28f2d33e/packages/esm-patient-chart-app/src/visit/visits-widget/past-visits-components/visit-summary.component.tsx#L157) assumes extensions are always available when rendering. If extensions are not yet loaded when the component renders, it throws an error.

I've remedied this by adding optional chaining to the extensions mapping.
This ensures the component gracefully handles cases where extensions are undefined or not yet loaded.
  • Loading branch information
denniskigen authored and senthil-athiban committed Nov 19, 2024
1 parent 928fe4d commit 07fd68a
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const VisitSummary: React.FC<VisitSummaryProps> = ({ visit, patientUuid }) => {
>
{t('encounters_title', 'Encounters')}
</Tab>
{extensions.map((extension, index) => (
{extensions?.map((extension, index) => (
<Tab key={index} className={styles.tab} id={`${extension.meta.title || index}-tab`}>
{t(extension.meta.title, {
ns: extension.moduleName,
Expand Down

0 comments on commit 07fd68a

Please sign in to comment.