Skip to content

Commit

Permalink
fix: add fallback for v39 and v40
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Aug 13, 2024
1 parent 97d11ba commit 656b471
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { subValueGetterByElementType } from '../utils/getSubValueForDataValue';
import { makeQuerySingleResource } from '../../../utils/api';

type Props = {|
linkedEventId: string,
linkedEventId: ?string,
dataValues: Array<{| dataElement: string, value: any |}>,
formFoundation: ?RenderFoundation,
|}
Expand Down Expand Up @@ -75,6 +75,7 @@ export const useClientDataValues = ({
// $FlowFixMe
formFoundation,
querySingleResource,
// $FlowFixMe
linkedEventId,
buildUrl(baseUrl, `api/${apiVersion}`),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,31 @@ export const useLinkedEventByOriginId = ({ originEventId }: Props) => {
};
}, [data]);

// Add fallback query if relationship is missing eventData
const {
data: fallbackDataValues,
isLoading: isLoadingFallback,
isError: isErrorFallback,
} = useApiDataQuery(
['linkedEventDataValuesFallback', linkedEvent?.event],
{
resource: 'tracker/events',
id: linkedEvent?.event,
params: {
fields: 'event,dataValues,occurredAt,scheduledAt,status,orgUnit,programStage,program',
},
},
{
enabled: !!linkedEvent?.event && !dataValues,
},
);

return {
linkedEvent,
linkedEvent: dataValues ? linkedEvent : fallbackDataValues,
relationshipType,
dataValues,
isLoading,
isError,
dataValues: dataValues || fallbackDataValues?.dataValues,
isLoading: isLoading || isLoadingFallback,
isError: isError || isErrorFallback,
error,
};
};

0 comments on commit 656b471

Please sign in to comment.