Skip to content

Conversation

@Bawanthathilan
Copy link

@Bawanthathilan Bawanthathilan commented May 24, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. Ensure your PR title includes a conventional commit label (such as feat, fix, or chore, among others). See existing PR titles for inspiration.

For changes to apps

If applicable

  • My work includes tests or is validated by existing tests.
  • I have updated the esm-framework mock to reflect any API changes I have made.

Summary

The previous implementation of the location component was not reusable and had UX limitations. To address these issues, the component was refactored into a reusable LocationSelector and moved to the esm-core styleguide for broader use across projects.

Screenshots

Screen.Recording.2025-10-06.at.8.32.23.AM.mov

Related Issue

https://openmrs.atlassian.net/browse/O3-4740

Other

@Bawanthathilan Bawanthathilan changed the title create location selector component O3-4740: Refactor Location Selector Component for Reusability and Move to esm-core Styleguide May 24, 2025
Copy link
Member

@jayasanka-sack jayasanka-sack left a comment

Choose a reason for hiding this comment

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

Thanks for getting this started, @Bawanthathilan! I know it’s still a WIP, but I’ve left a few comments for you. Appreciate your work on this so far!

defaultLocationUuid?: string;
locationTag?: string;
locationsPerRequest?: number;
onChange: (locationUuid?: string) => void;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onChange: (locationUuid?: string) => void;
onChange: (locationUuid: string) => void;

locationUuid shouldn't be null

@Bawanthathilan Bawanthathilan marked this pull request as ready for review October 2, 2025 10:21
@Bawanthathilan
Copy link
Author

Bawanthathilan commented Oct 3, 2025

Hi @jayasanka-sack @ibacher can you review this PR

@jayasanka-sack
Copy link
Member

Thanks a lot for getting this done @Bawanthathilan! would you mind adding some screenshots and/or a video recording when you get a chance?

}, [fetchedLocations]);

const effectiveLocations = useMemo<Location[]>(() => {
const base = fetchedLocations.length > 0 ? fetchedLocations : tempLocations;
Copy link
Member

Choose a reason for hiding this comment

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

When the user searches for a non-existing location, fetchedLocations will be empty, and the component will fall back to tempLocations. However, in this case the expected behavior is to show an empty list. Can you confirm if that’s what currently happens?

Copy link
Member

Choose a reason for hiding this comment

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

Also, could we rename the variable base to something more descriptive of what it actually holds? That would make the code easier to follow.

Copy link
Member

Choose a reason for hiding this comment

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

Were you able to find a way to resolve this one?

Comment on lines +68 to +69
initialSelectedItem={items.find((i) => i.id === defaultLocationUuid)}
selectedItem={items.find((i) => i.id === selectedLocationUuid)}
Copy link
Member

Choose a reason for hiding this comment

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

when selectedItem is provided, the ComboBox behaves as a controlled component, so initialSelectedItem is ignored after the first render. To keep things clearer and avoid confusion it might be better to remove initialSelectedItem here and rely only on selectedItem. What do you think?

import React, { useState, useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { ComboBox } from '@carbon/react';
import { useLocationByUuid, useLocations } from '../location-picker/location-picker.resource';
Copy link
Member

Choose a reason for hiding this comment

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

Data fetching hooks should be moved to esm-react-utils and not left in the styleguide.

import { useTranslation } from 'react-i18next';
import { ComboBox } from '@carbon/react';
import { useLocationByUuid, useLocations } from '../location-picker/location-picker.resource';
import { useDebounce } from '@openmrs/esm-react-utils';
Copy link
Member

Choose a reason for hiding this comment

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

This should be above local imports.

<ComboBox
aria-label={label}
id="location"
invalidText={t('Required')}
Copy link
Member

Choose a reason for hiding this comment

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

We can't translated text like this in the styleguide. Please use the getCoreTranslation() function from esm-translations.

@ibacher
Copy link
Member

ibacher commented Oct 6, 2025

From the test failures, it doesn't look like this PR correctly re-creates the existing location selector. That needs to be fixed.

@Bawanthathilan
Copy link
Author

From the test failures, it doesn't look like this PR correctly re-creates the existing location selector. That needs to be fixed.

Thanks for reviewing @ibacher @jayasanka-sack ill fixed those changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants