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

(feat) Comboboxes in the order form should filter out non-matching items #2008

Merged
merged 3 commits into from
Sep 11, 2024
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
2 changes: 2 additions & 0 deletions e2e/specs/drug-orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ test('Record, edit and discontinue a drug order', async ({ page }) => {

await test.step('And I change the route to `Inhalation`', async () => {
await form.getByPlaceholder(/route/i).click();
await form.getByPlaceholder(/route/i).clear();
await form.getByPlaceholder(/route/i).fill('Inhalation');
await form.getByText('Inhalation', { exact: true }).click();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
return orderConfigObject?.orderFrequencies ?? [];
}, [orderConfigObject]);

const filterItems = useCallback((menu) => {
const filterItemsByName = useCallback((menu) => {
return menu?.item?.value?.toLowerCase().includes(menu?.inputValue?.toLowerCase());
}, []);

const filterItemsBySynonymNames = useCallback((menu) => {
if (menu?.inputValue?.length) {
return menu.item?.names?.some((abbr: string) => abbr.toLowerCase().includes(menu.inputValue.toLowerCase()));
}
Expand Down Expand Up @@ -482,6 +486,7 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
getValues={getValues}
size={isTablet ? 'lg' : 'md'}
id="dosingUnits"
shouldFilterItem={filterItemsByName}
items={drugDosingUnits}
placeholder={t('editDosageUnitsPlaceholder', 'Unit')}
titleText={t('editDosageUnitsTitle', 'Dose unit')}
Expand All @@ -496,14 +501,15 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
<InputWrapper>
<ControlledFieldInput
control={control}
name="route"
type="comboBox"
size={isTablet ? 'lg' : 'md'}
id="editRoute"
items={drugRoutes}
itemToString={(item) => item?.value}
name="route"
placeholder={t('editRouteComboBoxTitle', 'Route')}
shouldFilterItem={filterItemsByName}
size={isTablet ? 'lg' : 'md'}
titleText={t('editRouteComboBoxTitle', 'Route')}
itemToString={(item) => item?.value}
type="comboBox"
/>
</InputWrapper>
</Column>
Expand All @@ -516,7 +522,7 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
size={isTablet ? 'lg' : 'md'}
id="editFrequency"
items={orderFrequencies}
shouldFilterItem={filterItems}
shouldFilterItem={filterItemsBySynonymNames}
placeholder={t('editFrequencyComboBoxTitle', 'Frequency')}
titleText={t('editFrequencyComboBoxTitle', 'Frequency')}
itemToString={(item) => item?.value}
Expand Down Expand Up @@ -647,6 +653,7 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
items={durationUnits}
itemToString={(item) => item?.value}
placeholder={t('durationUnitPlaceholder', 'Duration Unit')}
shouldFilterItem={filterItemsByName}
/>
</InputWrapper>
</Column>
Expand Down Expand Up @@ -674,14 +681,15 @@ export function DrugOrderForm({ initialOrderBasketItem, onSave, onCancel, prompt
<InputWrapper>
<ControlledFieldInput
control={control}
name="quantityUnits"
type="comboBox"
size="lg"
id="dispensingUnits"
items={drugDispensingUnits}
itemToString={(item) => item?.value}
name="quantityUnits"
placeholder={t('editDispensingUnit', 'Quantity unit')}
shouldFilterItem={filterItemsByName}
size="lg"
titleText={t('editDispensingUnit', 'Quantity unit')}
itemToString={(item) => item?.value}
type="comboBox"
/>
</InputWrapper>
</Column>
Expand Down