Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) O3-4299: Missing Label in Dropdown Menu of Service Queues #1425

Merged
merged 4 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,50 @@ import { updateSelectedService, useSelectedService, useSelectedQueueLocationUuid
import { useActiveVisits, useAverageWaitTime } from './clinic-metrics.resource';
import { useServiceMetricsCount } from './queue-metrics.resource';
import { useQueueEntries } from '../hooks/useQueueEntries';
import useQueueServices from '../hooks/useQueueService';
import { type Concept } from '../types';
import MetricsCard from './metrics-card.component';
import MetricsHeader from './metrics-header.component';
import useQueueServices from '../hooks/useQueueService';
import styles from './clinic-metrics.scss';

export interface Service {
uuid: string;
display: string;
uuid?: string;
}

type ServiceListItem = Service | Concept;

function ClinicMetrics() {
const { t } = useTranslation();
const layout = useLayoutType();

const currentQueueLocation = useSelectedQueueLocationUuid();
const { services } = useQueueServices();
const currentService = useSelectedService();

const { services } = useQueueServices();
const { serviceCount } = useServiceMetricsCount(currentService?.serviceUuid, currentQueueLocation);

const [initialSelectedItem, setInitialSelectItem] = useState(() => {
return !currentService?.serviceDisplay || !currentService?.serviceUuid;
});

const { totalCount } = useQueueEntries({
service: currentService?.serviceUuid,
location: currentQueueLocation,
isEnded: false,
});

const { activeVisitsCount, isLoading: loading } = useActiveVisits();
const { waitTime } = useAverageWaitTime(currentService?.serviceUuid, '');

const defaultServiceItem: Service = {
display: `${t('all', 'All')}`,
};

const serviceItems: ServiceListItem[] = [defaultServiceItem, ...(services ?? [])];

const handleServiceChange = ({ selectedItem }) => {
updateSelectedService(selectedItem.uuid, selectedItem.display);
if (selectedItem.uuid == undefined) {
if (selectedItem.uuid === undefined) {
setInitialSelectItem(true);
} else {
setInitialSelectItem(false);
Expand All @@ -49,36 +61,37 @@ function ClinicMetrics() {
<MetricsHeader />
<div className={styles.cardContainer} data-testid="clinic-metrics">
<MetricsCard
label={t('patients', 'Patients')}
value={loading ? '--' : activeVisitsCount}
headerLabel={t('checkedInPatients', 'Checked in patients')}
label={t('patients', 'Patients')}
service="scheduled"
value={loading ? '--' : activeVisitsCount}
/>
<MetricsCard
headerLabel=""
label={t('patients', 'Patients')}
value={initialSelectedItem ? totalCount ?? '--' : serviceCount}
headerLabel={`${t('waitingFor', 'Waiting for')}:`}
locationUuid={currentQueueLocation}
service={currentService?.serviceDisplay}
serviceUuid={currentService?.serviceUuid}
locationUuid={currentQueueLocation}>
value={initialSelectedItem ? totalCount ?? '--' : serviceCount}>
<Dropdown
id="inline"
items={[{ display: `${t('all', 'All')}` }, ...(services ?? [])]}
initialSelectedItem={defaultServiceItem}
items={serviceItems}
itemToString={(item) =>
item ? `${item.display} ${item.location?.display ? `- ${item.location.display}` : ''}` : ''
}
label=""
onChange={handleServiceChange}
Copy link
Member

@denniskigen denniskigen Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoding All as the label for the default item in the dropdown is not the right approach. If the goal is to show a default value for the dropdown, we should use the initialSelectedItem prop. This allows us to display a default value in the dropdown.

To achieve, this we can modify the logic as follows:

const defaultServiceItem = {
  display: `${t('all', 'All')}`,
  uuid: '',
};

const serviceItems = [defaultServiceItem, ...(services ?? [])];

And then further down the line, we can use these values to set the initialSelectedItem prop and the items prop:

<Dropdown
  initialSelectedItem={defaultServiceItem}
  items={serviceItems}
  label=""
  // ... other props
/>

Copy link
Member

@denniskigen denniskigen Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nice, optional extra touches would be:

  • Annotating serviceItems with the proper types.
  • Fixing the styling of the dropdown so it's vertical alignment matches that of the label.

Copy link
Contributor Author

@harshthakkr harshthakkr Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fixing the styling of the dropdown so it's vertical alignment matches that of the label.

I am not able to implement the proper vertical alignment here since changing the value of margin-top can cause changes globally, and I couldn't find any other solution.

:global(.cds--dropdown__wrapper--inline) {
    gap: 0;
    margin-top: -(layout.$spacing-04);
  }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest commit @harshthakkr.

size={isDesktop(layout) ? 'sm' : 'lg'}
titleText=""
titleText={`${t('waitingFor', 'Waiting for')}:`}
type="inline"
/>
</MetricsCard>
<MetricsCard
label={t('minutes', 'Minutes')}
value={waitTime ? waitTime.averageWaitTime : '--'}
headerLabel={t('averageWaitTime', 'Average wait time today')}
service="waitTime"
value={waitTime ? waitTime.averageWaitTime : '--'}
/>
</div>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@
.headerLabelContainer {
display: flex;
height: layout.$spacing-07;
align-items: center;

:global(.cds--dropdown__wrapper--inline) {
gap: 0;
margin-top: -(layout.$spacing-04);

label {
@include type.type-style('heading-compact-01');
color: $text-02;
margin-right: layout.$spacing-03;
}
}

:global(.cds--list-box__menu-icon) {
Expand Down
Loading