Skip to content

Commit

Permalink
Add defaultLaunchContext props to ResourceListPage
Browse files Browse the repository at this point in the history
  • Loading branch information
ir4y committed Dec 4, 2024
1 parent 2931ee3 commit 6531ba8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/uberComponents/ResourceListPage/actions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { t } from '@lingui/macro';
import { Button, notification } from 'antd';
import { Bundle, Resource } from 'fhir/r4b';
import { Bundle, ParametersParameter, Resource } from 'fhir/r4b';
import { useNavigate } from 'react-router-dom';

import { ModalTrigger } from 'src/components/ModalTrigger';
Expand Down Expand Up @@ -87,7 +87,13 @@ export function RecordQuestionnaireAction<R extends Resource>({
);
}

export function HeaderQuestionnaireAction({ action, reload }: { action: QuestionnaireActionType; reload: () => void }) {
interface HeaderQuestionnaireActionProps {
action: QuestionnaireActionType;
reload: () => void;
defaultLaunchContext: ParametersParameter[];
}

export function HeaderQuestionnaireAction({ action, reload, defaultLaunchContext }: HeaderQuestionnaireActionProps) {
return (
<ModalTrigger
title={action.title}
Expand All @@ -105,6 +111,7 @@ export function HeaderQuestionnaireAction({ action, reload }: { action: Question
notification.success({ message: t`Successfully saved` });
reload();
}}
launchContextParameters={defaultLaunchContext}
onCancel={closeModal}
/>
)}
Expand Down
15 changes: 13 additions & 2 deletions src/uberComponents/ResourceListPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { plural, Trans } from '@lingui/macro';
import { Empty, Row, Col, Button } from 'antd';
import { ColumnsType } from 'antd/lib/table';
import { Bundle, Resource } from 'fhir/r4b';
import { Bundle, ParametersParameter, Resource } from 'fhir/r4b';

import { formatError, SearchParams } from '@beda.software/fhir-react';
import { isFailure, isLoading, isSuccess } from '@beda.software/remote-data';
Expand Down Expand Up @@ -76,6 +76,12 @@ interface ResourceListPageProps<R extends Resource> {
* NOTE: Theoretically getHeaderActions can accept selected resources Bundle
*/
getBatchActions?: () => Array<QuestionnaireActionType>;

/**
* Default launch context that will be added to al questionnaires
* TODO now it is used for header actions only
*/
defaultLaunchContext?: ParametersParameter[];
}

export function ResourceListPage<R extends Resource>({
Expand All @@ -88,6 +94,7 @@ export function ResourceListPage<R extends Resource>({
getBatchActions,
searchBarColumns,
tableColumns,
defaultLaunchContext,
}: ResourceListPageProps<R>) {
const { columnsFilterValues, onChangeColumnFilter, onResetFilters } = useSearchBar({
columns: searchBarColumns ?? [],
Expand Down Expand Up @@ -115,7 +122,11 @@ export function ResourceListPage<R extends Resource>({
</Col>
{headerActions.map((action, index) => (
<Col key={index}>
<HeaderQuestionnaireAction action={action} reload={pagerManager.reload} />
<HeaderQuestionnaireAction
action={action}
reload={pagerManager.reload}
defaultLaunchContext={defaultLaunchContext ?? []}
/>
</Col>
))}
</Row>
Expand Down

0 comments on commit 6531ba8

Please sign in to comment.