Skip to content

Commit

Permalink
Add optional 'to' prop for LinkToEdit component
Browse files Browse the repository at this point in the history
Use case:
when using several dashboards with several contexts to create and render
documents at it becomes handy to have optional ability to pass 'to'
component from DashboardInstance

Ref breeoot/ehr#278
  • Loading branch information
alexlipovka committed Nov 26, 2024
1 parent 7a3bb36 commit 46addd9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import { Resource, Provenance } from 'fhir/r4b';
import { Link, useLocation } from 'react-router-dom';
import { fromFHIRReference } from 'sdc-qrf';

export function LinkToEdit(props: { name?: string; resource: Resource; provenanceList: Provenance[] }) {
const { name, resource, provenanceList } = props;
interface LinkToEditProps {
name?: string;
resource: Resource;
provenanceList: Provenance[];
to?: string;
}
export function LinkToEdit(props: LinkToEditProps) {
const { name, resource, provenanceList, to } = props;
const location = useLocation();
const provenance = provenanceList.find(
(p) =>
Expand All @@ -14,7 +20,7 @@ export function LinkToEdit(props: { name?: string; resource: Resource; provenanc
const qrId = fromFHIRReference(entity)?.id;

if (qrId) {
return <Link to={`${location.pathname}/documents/${qrId}`}>{name}</Link>;
return <Link to={to ? `${to}/${qrId}` : `${location.pathname}/documents/${qrId}`}>{name}</Link>;
}

return <>{name}</>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function prepareAllergies(
allergies: AllergyIntolerance[],
provenanceList: Provenance[],
total?: number,
to?: string,
): OverviewCard<AllergyIntolerance> {
return {
title: t`Allergies`,
Expand All @@ -46,6 +47,7 @@ export function prepareAllergies(
name={resource.code?.coding?.[0]?.display}
resource={resource}
provenanceList={provenanceList}
to={to}
/>
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export interface OverviewCard<T extends Resource | Resource[]> {
}

export type PrepareFunction<T extends Resource> =
| ((resources: T[], provenances: Provenance[], total: number) => OverviewCard<T>)
| ((resources: T[], provenances: Provenance[], total: number, to?: string) => OverviewCard<T>)
| ((resources: T[]) => OverviewCard<T[]>);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function useStandardCard<T extends Resource>(
patient: Patient,
query: Query,
prepareFunction: PrepareFunction<T>,
to?: string,
) {
const [response] = useService(async () => {
return mapSuccess(
Expand All @@ -29,6 +30,7 @@ export function useStandardCard<T extends Resource>(
resource as T[],
provenance,
resource.length,
to,
);
return { card };
},
Expand Down

0 comments on commit 46addd9

Please sign in to comment.