Skip to content

Commit 851c2e1

Browse files
committed
(fix) O3-5368 Appointments - make appointment table always show rows of configured status
1 parent c999a77 commit 851c2e1

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

packages/esm-appointments-app/src/appointments/scheduled/appointments-list.component.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@ import React, { useMemo } from 'react';
22
import { filterByServiceType } from '../utils';
33
import { useAppointmentList } from '../../hooks/useAppointmentList';
44
import AppointmentsTable from '../common-components/appointments-table.component';
5+
import { useConfig } from '@openmrs/esm-framework';
6+
import { useTranslation } from 'react-i18next';
7+
import { type AppointmentPanelConfig } from '../../scheduled-appointments-config-schema';
58

69
interface AppointmentsListProps {
710
appointmentServiceTypes?: Array<string>;
811
date: string;
912
excludeCancelledAppointments?: boolean;
10-
status?: string;
11-
title: string;
1213
}
1314

15+
/**
16+
* This component is both rendered as a regular componant and as an extension.
17+
* As an extension, it can be configured to display appointments of certain status.
18+
*/
1419
const AppointmentsList: React.FC<AppointmentsListProps> = ({
1520
appointmentServiceTypes,
1621
date,
1722
excludeCancelledAppointments = false,
18-
status,
19-
title,
2023
}) => {
24+
const { t } = useTranslation();
25+
const { status, title = t('todays', "Today's") } = useConfig<AppointmentPanelConfig>();
2126
const { appointmentList, isLoading } = useAppointmentList(status, date);
2227

2328
const appointmentsFilteredByServiceType = filterByServiceType(appointmentList, appointmentServiceTypes).map(

packages/esm-appointments-app/src/appointments/scheduled/scheduled-appointments.component.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ import {
1111
type ConfigObject,
1212
useLayoutType,
1313
isDesktop,
14+
useAssignedExtensions,
1415
} from '@openmrs/esm-framework';
1516
import { useAppointmentsStore } from '../../store';
1617
import styles from './scheduled-appointments.scss';
18+
import { type AppointmentPanelConfig } from '../../scheduled-appointments-config-schema';
1719

1820
dayjs.extend(isSameOrBefore);
1921

@@ -37,7 +39,7 @@ const ScheduledAppointments: React.FC<ScheduledAppointmentsProps> = ({ appointme
3739

3840
const [currentTab, setCurrentTab] = useState(null);
3941
const [dateType, setDateType] = useState<DateType>('today');
40-
const scheduledAppointmentPanels = useConnectedExtensions(scheduledAppointmentsPanelsSlot);
42+
const scheduledAppointmentPanels = useAssignedExtensions(scheduledAppointmentsPanelsSlot);
4143
const { allowedExtensions, showExtension, hideExtension } = useAllowedExtensions();
4244
const shouldShowPanel = useCallback(
4345
(panel: Omit<ConnectedExtension, 'config'>) => allowedExtensions[panel.name] ?? false,
@@ -78,7 +80,7 @@ const ScheduledAppointments: React.FC<ScheduledAppointmentsProps> = ({ appointme
7880
<ContentSwitcher
7981
className={styles.switcher}
8082
size={responsiveSize}
81-
onChange={({ name }) => setCurrentTab(name)}
83+
onChange={({ name }) => setCurrentTab(name as string)}
8284
selectedIndex={panelsToShow.findIndex((panel) => panel.name == currentTab) ?? 0}
8385
selectionMode="manual">
8486
{panelsToShow.map((panel) => (
@@ -161,12 +163,18 @@ function ExtensionWrapper({
161163
) {
162164
currentConfig.current = extension.config;
163165
currentDateType.current = dateType;
164-
void (shouldDisplayExtensionTab(extension?.config, dateType)
165-
? showExtensionTab(extension.name)
166-
: hideExtensionTab(extension.name));
166+
if (shouldDisplayExtensionTab(extension?.config as AppointmentPanelConfig, dateType)) {
167+
showExtensionTab(extension.name);
168+
} else {
169+
hideExtensionTab(extension.name);
170+
}
167171
}
168172
}, [extension, dateType, showExtensionTab, hideExtensionTab]);
169173

174+
if (extension.config == null) {
175+
return null;
176+
}
177+
170178
return (
171179
<div
172180
key={extension.name}
@@ -184,7 +192,7 @@ function ExtensionWrapper({
184192
);
185193
}
186194

187-
function shouldDisplayExtensionTab(config: ConfigObject | undefined, dateType: DateType): boolean {
195+
function shouldDisplayExtensionTab(config: AppointmentPanelConfig | undefined, dateType: DateType): boolean {
188196
if (!config) {
189197
return false;
190198
}

packages/esm-appointments-app/src/home/home-appointments.component.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const HomeAppointments = () => {
1313
<AppointmentsList
1414
date={toOmrsIsoString(dayjs().startOf('day').toDate())}
1515
excludeCancelledAppointments
16-
title={t('todays', "Today's")}
1716
/>
1817
</div>
1918
);

packages/esm-appointments-app/src/scheduled-appointments-config-schema.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,11 @@ export const earlyAppointmentsPanelConfigSchema = {
167167
_default: false,
168168
},
169169
};
170+
171+
export interface AppointmentPanelConfig {
172+
title: string;
173+
status?: string;
174+
showForPastDate: boolean;
175+
showForToday: boolean;
176+
showForFutureDate: boolean;
177+
}

0 commit comments

Comments
 (0)