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) O3-2262 & O3-2263: Previously logged in locations should show at the top of the locations' list #954

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

vasharma05
Copy link
Member

@vasharma05 vasharma05 commented Mar 12, 2024

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

This PR now saves the last 10 logged in locations of the users in the userProperties under the key previousLoggedInLocations as a string joined by ,. The previous logged in locations are then shown at the top of the list before the rest of the locations.

The order of the locations in the list is:

  1. Default location
  2. Previously logged in locations
  3. Rest of the locations
/* To get a list of previous logged in locations' UUIDs */
const previousLoggedInLocations: Array<string> = user?.userProperties?.previousLoggedInLocations?.split(',') ?? []

/* To save the location UUIDs */
const userProperties = {
	previousLoggedInLocations: previousLoggedInLocations.join(',')
}

Screenshots

Screen.Recording.2024-03-21.at.11.48.50.mov

Related Issue

https://openmrs.atlassian.net/browse/O3-2262
https://openmrs.atlassian.net/browse/O3-2263

Other

Built over #851

Copy link
Contributor

github-actions bot commented Mar 12, 2024

Size Change: -413 kB (-10%) 👏

Total Size: 3.73 MB

Filename Size Change
packages/apps/esm-login-app/dist/363.js 0 B -30.5 kB (removed) 🏆
packages/shell/esm-app-shell/dist/openmrs.12d76e3dead3b7ff.js 0 B -382 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
packages/apps/esm-devtools-app/dist/344.js 27.3 kB 0 B
packages/apps/esm-devtools-app/dist/630.js 2.69 kB 0 B
packages/apps/esm-devtools-app/dist/667.js 6.96 kB 0 B
packages/apps/esm-devtools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-devtools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-devtools-app/dist/875.js 9.86 kB 0 B
packages/apps/esm-devtools-app/dist/884.js 15.2 kB 0 B
packages/apps/esm-devtools-app/dist/889.js 206 kB 0 B
packages/apps/esm-devtools-app/dist/988.js 328 B 0 B
packages/apps/esm-devtools-app/dist/main.js 3.14 kB 0 B
packages/apps/esm-devtools-app/dist/openmrs-esm-devtools-app.js 3.19 kB 0 B
packages/apps/esm-implementer-tools-app/dist/15.js 62.2 kB 0 B
packages/apps/esm-implementer-tools-app/dist/271.js 716 B 0 B
packages/apps/esm-implementer-tools-app/dist/319.js 637 B 0 B
packages/apps/esm-implementer-tools-app/dist/426.js 24.8 kB 0 B
packages/apps/esm-implementer-tools-app/dist/460.js 735 B 0 B
packages/apps/esm-implementer-tools-app/dist/482.js 15.2 kB 0 B
packages/apps/esm-implementer-tools-app/dist/528.js 133 kB 0 B
packages/apps/esm-implementer-tools-app/dist/56.js 3.07 kB 0 B
packages/apps/esm-implementer-tools-app/dist/560.js 13.9 kB 0 B
packages/apps/esm-implementer-tools-app/dist/574.js 560 B 0 B
packages/apps/esm-implementer-tools-app/dist/587.js 2.92 kB 0 B
packages/apps/esm-implementer-tools-app/dist/620.js 126 kB 0 B
packages/apps/esm-implementer-tools-app/dist/625.js 562 B 0 B
packages/apps/esm-implementer-tools-app/dist/644.js 717 B 0 B
packages/apps/esm-implementer-tools-app/dist/657.js 7.01 kB 0 B
packages/apps/esm-implementer-tools-app/dist/71.js 6.97 kB 0 B
packages/apps/esm-implementer-tools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-implementer-tools-app/dist/757.js 560 B 0 B
packages/apps/esm-implementer-tools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-implementer-tools-app/dist/791.js 284 B 0 B
packages/apps/esm-implementer-tools-app/dist/807.js 559 B 0 B
packages/apps/esm-implementer-tools-app/dist/833.js 681 B 0 B
packages/apps/esm-implementer-tools-app/dist/86.js 6.71 kB 0 B
packages/apps/esm-implementer-tools-app/dist/889.js 206 kB 0 B
packages/apps/esm-implementer-tools-app/dist/main.js 79 kB 0 B
packages/apps/esm-implementer-tools-app/dist/openmrs-esm-implementer-tools-app.js 3.31 kB 0 B
packages/apps/esm-login-app/dist/111.js 1.22 kB 0 B
packages/apps/esm-login-app/dist/126.js 2.5 kB 0 B
packages/apps/esm-login-app/dist/173.js 1.22 kB 0 B
packages/apps/esm-login-app/dist/224.js 0 B -256 B (removed) 🏆
packages/apps/esm-login-app/dist/236.js 272 B 0 B
packages/apps/esm-login-app/dist/240.js 364 B 0 B
packages/apps/esm-login-app/dist/271.js 718 B 0 B
packages/apps/esm-login-app/dist/272.js 264 B 0 B
packages/apps/esm-login-app/dist/319.js 679 B 0 B
packages/apps/esm-login-app/dist/336.js 234 B 0 B
packages/apps/esm-login-app/dist/460.js 737 B 0 B
packages/apps/esm-login-app/dist/539.js 298 B 0 B
packages/apps/esm-login-app/dist/56.js 3.06 kB 0 B
packages/apps/esm-login-app/dist/574.js 554 B -23 B (-4%)
packages/apps/esm-login-app/dist/625.js 579 B 0 B
packages/apps/esm-login-app/dist/627.js 0 B -257 B (removed) 🏆
packages/apps/esm-login-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-login-app/dist/644.js 718 B 0 B
packages/apps/esm-login-app/dist/667.js 6.96 kB 0 B
packages/apps/esm-login-app/dist/673.js 284 B 0 B
packages/apps/esm-login-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-login-app/dist/757.js 660 B 0 B
packages/apps/esm-login-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-login-app/dist/807.js 897 B 0 B
packages/apps/esm-login-app/dist/833.js 684 B 0 B
packages/apps/esm-login-app/dist/836.js 22.5 kB 0 B
packages/apps/esm-login-app/dist/861.js 30.8 kB 0 B
packages/apps/esm-login-app/dist/884.js 15.2 kB 0 B
packages/apps/esm-login-app/dist/889.js 206 kB 0 B
packages/apps/esm-login-app/dist/main.js 57.3 kB +237 B (0%)
packages/apps/esm-login-app/dist/openmrs-esm-login-app.js 3.33 kB -38 B (-1%)
packages/apps/esm-offline-tools-app/dist/271.js 1.18 kB 0 B
packages/apps/esm-offline-tools-app/dist/319.js 1.13 kB 0 B
packages/apps/esm-offline-tools-app/dist/460.js 1.29 kB 0 B
packages/apps/esm-offline-tools-app/dist/56.js 3.07 kB 0 B
packages/apps/esm-offline-tools-app/dist/574.js 1.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/59.js 56.5 kB 0 B
packages/apps/esm-offline-tools-app/dist/625.js 1.04 kB 0 B
packages/apps/esm-offline-tools-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-offline-tools-app/dist/644.js 1.18 kB 0 B
packages/apps/esm-offline-tools-app/dist/667.js 6.96 kB 0 B
packages/apps/esm-offline-tools-app/dist/735.js 2.63 kB 0 B
packages/apps/esm-offline-tools-app/dist/757.js 1.2 kB 0 B
packages/apps/esm-offline-tools-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-offline-tools-app/dist/807.js 1.11 kB 0 B
packages/apps/esm-offline-tools-app/dist/833.js 1.21 kB 0 B
packages/apps/esm-offline-tools-app/dist/884.js 15.2 kB 0 B
packages/apps/esm-offline-tools-app/dist/889.js 206 kB 0 B
packages/apps/esm-offline-tools-app/dist/922.js 90.9 kB 0 B
packages/apps/esm-offline-tools-app/dist/main.js 147 kB 0 B
packages/apps/esm-offline-tools-app/dist/openmrs-esm-offline-tools-app.js 3.29 kB 0 B
packages/apps/esm-primary-navigation-app/dist/271.js 267 B 0 B
packages/apps/esm-primary-navigation-app/dist/319.js 237 B 0 B
packages/apps/esm-primary-navigation-app/dist/460.js 264 B 0 B
packages/apps/esm-primary-navigation-app/dist/553.js 23.3 kB 0 B
packages/apps/esm-primary-navigation-app/dist/574.js 230 B 0 B
packages/apps/esm-primary-navigation-app/dist/625.js 232 B 0 B
packages/apps/esm-primary-navigation-app/dist/63.js 16.5 kB 0 B
packages/apps/esm-primary-navigation-app/dist/644.js 267 B 0 B
packages/apps/esm-primary-navigation-app/dist/667.js 6.97 kB 0 B
packages/apps/esm-primary-navigation-app/dist/735.js 2.64 kB 0 B
packages/apps/esm-primary-navigation-app/dist/757.js 238 B 0 B
packages/apps/esm-primary-navigation-app/dist/762.js 7.61 kB 0 B
packages/apps/esm-primary-navigation-app/dist/788.js 42.9 kB 0 B
packages/apps/esm-primary-navigation-app/dist/807.js 290 B 0 B
packages/apps/esm-primary-navigation-app/dist/833.js 257 B 0 B
packages/apps/esm-primary-navigation-app/dist/884.js 15.2 kB 0 B
packages/apps/esm-primary-navigation-app/dist/889.js 206 kB 0 B
packages/apps/esm-primary-navigation-app/dist/958.js 22.7 kB 0 B
packages/apps/esm-primary-navigation-app/dist/main.js 47.6 kB 0 B
packages/apps/esm-primary-navigation-app/dist/openmrs-esm-primary-navigation-app.js 3.23 kB 0 B
packages/framework/esm-api/dist/openmrs-esm-api.js 16.2 kB 0 B
packages/framework/esm-config/dist/openmrs-esm-module-config.js 8.02 kB 0 B
packages/framework/esm-dynamic-loading/dist/openmrs-esm-dynamic-loading.js 2.75 kB 0 B
packages/framework/esm-error-handling/dist/openmrs-esm-error-handling.js 889 B 0 B
packages/framework/esm-extensions/dist/openmrs-esm-extensions.js 8.1 kB 0 B
packages/framework/esm-feature-flags/dist/openmrs-esm-feature-flags.js 1.67 kB 0 B
packages/framework/esm-framework/dist/126.openmrs-esm-framework.js 2.47 kB 0 B
packages/framework/esm-framework/dist/278.openmrs-esm-framework.js 14.5 kB 0 B
packages/framework/esm-framework/dist/530.openmrs-esm-framework.js 2.92 kB 0 B
packages/framework/esm-framework/dist/619.openmrs-esm-framework.js 6.49 kB 0 B
packages/framework/esm-framework/dist/645.openmrs-esm-framework.js 9.31 kB 0 B
packages/framework/esm-framework/dist/680.openmrs-esm-framework.js 6.13 kB 0 B
packages/framework/esm-framework/dist/735.openmrs-esm-framework.js 2.66 kB 0 B
packages/framework/esm-framework/dist/788.openmrs-esm-framework.js 42.9 kB 0 B
packages/framework/esm-framework/dist/openmrs-esm-framework.js 474 kB 0 B
packages/framework/esm-globals/dist/openmrs-esm-globals.js 770 B 0 B
packages/framework/esm-navigation/dist/openmrs-esm-navigation.js 9.35 kB 0 B
packages/framework/esm-offline/dist/openmrs-esm-offline.js 34.4 kB 0 B
packages/framework/esm-react-utils/dist/openmrs-esm-react-utils.js 15.2 kB 0 B
packages/framework/esm-routes/dist/openmrs-esm-utils.js 1.46 kB 0 B
packages/framework/esm-state/dist/openmrs-esm-state.js 888 B 0 B
packages/framework/esm-styleguide/dist/openmrs-esm-styleguide.js 103 kB 0 B
packages/framework/esm-translations/dist/openmrs-esm-core-translations.js 1.59 kB 0 B
packages/framework/esm-utils/dist/openmrs-esm-utils.js 11.1 kB 0 B
packages/shell/esm-app-shell/dist/11c63b65f96a8718.js 499 B 0 B
packages/shell/esm-app-shell/dist/1e0131662341578e.js 645 B 0 B
packages/shell/esm-app-shell/dist/2916d0aa7a9d5dc8.js 544 B 0 B
packages/shell/esm-app-shell/dist/2e49bd21ea50fd0d.js 1.58 kB 0 B
packages/shell/esm-app-shell/dist/4a3e954c45d63305.js 645 B 0 B
packages/shell/esm-app-shell/dist/4a756bad65fec00c.js 6.87 kB 0 B
packages/shell/esm-app-shell/dist/56c2295bc732ae32.js 722 B 0 B
packages/shell/esm-app-shell/dist/651172ae1548469c.js 499 B 0 B
packages/shell/esm-app-shell/dist/98343ad4bb547c48.js 499 B 0 B
packages/shell/esm-app-shell/dist/b5151d35f680b40a.js 3.82 kB 0 B
packages/shell/esm-app-shell/dist/ba933133ad512cac.js 499 B 0 B
packages/shell/esm-app-shell/dist/fa89289c9d9645c9.js 519 B 0 B
packages/shell/esm-app-shell/dist/openmrs.643eec3a36ca728b.js 382 kB 0 B
packages/shell/esm-app-shell/dist/service-worker.js 45.9 kB -1 B (0%)
packages/tooling/openmrs/dist/cli.js 2.88 kB 0 B
packages/tooling/openmrs/dist/commands/assemble.js 2.82 kB 0 B
packages/tooling/openmrs/dist/commands/build.js 1.34 kB 0 B
packages/tooling/openmrs/dist/commands/debug.js 545 B 0 B
packages/tooling/openmrs/dist/commands/develop.js 2.59 kB 0 B
packages/tooling/openmrs/dist/commands/index.js 438 B 0 B
packages/tooling/openmrs/dist/commands/start.js 851 B 0 B
packages/tooling/openmrs/dist/index.js 517 B 0 B
packages/tooling/openmrs/dist/runner.js 637 B 0 B
packages/tooling/openmrs/dist/utils/config.js 728 B 0 B
packages/tooling/openmrs/dist/utils/debugger.js 576 B 0 B
packages/tooling/openmrs/dist/utils/dependencies.js 648 B 0 B
packages/tooling/openmrs/dist/utils/helpers.js 395 B 0 B
packages/tooling/openmrs/dist/utils/importmap.js 3.07 kB 0 B
packages/tooling/openmrs/dist/utils/index.js 444 B 0 B
packages/tooling/openmrs/dist/utils/logger.js 368 B 0 B
packages/tooling/openmrs/dist/utils/npmConfig.js 830 B 0 B
packages/tooling/openmrs/dist/utils/untar.js 722 B 0 B
packages/tooling/openmrs/dist/utils/variables.js 192 B 0 B
packages/tooling/openmrs/dist/utils/webpack.js 278 B 0 B
packages/tooling/webpack-config/dist/index.js 3.61 kB 0 B

compressed-size-action

@vasharma05 vasharma05 changed the title (feat) O3-2262 & O3-2263: Record previously logged in locations of the users and show them at the top of the locations' list (feat) O3-2262 & O3-2263: Previously logged in locations should show at the top of the locations' list Mar 21, 2024
Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

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

Some initial comments. Nice work!

packages/apps/esm-login-app/src/login.resource.ts Outdated Show resolved Hide resolved
},
[savePreference, defaultLocation, updateUserPropsWithDefaultLocation, t, isUpdateFlow],
);
export function getUpdatedLoggedInLocations(previousLoggedInLocations: string, locationUuid: string): string {
Copy link
Member

Choose a reason for hiding this comment

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

This function needs a better name, e.g., getDefaultLoginLocations(). Similarly, I think locationUuid could use a better name, e.g., defaultLocationUuid.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @ibacher!
Actually this function stores all the logged in locations joined with ,

Copy link
Member

Choose a reason for hiding this comment

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

I get what the function does. My point was that the name here is both quite long and not very descriptive. getDefaultLoginLocations() is based on my suggestion below to renamed getUserPropertiesWithDefaultAndLogInLocation() to getDefaultLocationUserProperties().

Copy link
Member

Choose a reason for hiding this comment

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

Also, shouldn't this function ensure the invariant that no more than 10 locations are stored in the updatedLoggedInLocations() (less a concern in newer versions of the backend where user properties can be longer, but there's always a maximum length and truncation will almost certainly lead to invalid UUIDs in the list).

return results;
}

export function useLocations(useLoginLocationTag: boolean, count: number = 0, searchQuery: string = '') {
Copy link
Member

Choose a reason for hiding this comment

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

Since this only pertains to login locations. I'm also unclear on why we need this in the framework itself and not as part of the login app, which is where I think it belongs (there are other uses to locations; these should not be default restricted to login locations and they should not have the same logic that we're using here to surface locations; in other cases where we need locations, it makes sense to surface the location the user is logged into, but not the previous locations they have logged into).

Suggested change
export function useLocations(useLoginLocationTag: boolean, count: number = 0, searchQuery: string = '') {
export function useLoginLocations(useLoginLocationTag: boolean, count: number = 0, searchQuery: string = '') {

Copy link
Member Author

Choose a reason for hiding this comment

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

it makes sense to surface the location the user is logged into, but not the previous locations they have logged into

I actually thought that this case you mentioned above would have to handled in other places, say location dropdown somewhere else in UI, to use both default(logged in) and previous logged in locations to show at the top, hence using the same hook everywhere else rather than creating this again and again.

Should I move this from framework to login app again?

Also, we can pass the useLoginLocationTag as true/false, hence I believe useLocations is a better name for handling both the cases. Please confirm on this as well.
Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

So a couple of things here:

  1. Locations have an entire tagging system, which are intended for a sort of "folksonomy" of locations. That is, it might make sense (for other applications) to tag all pharmacy locations as "Pharmacy" and then, say, in the dispensing app, load those "Pharmacy" locations as the list of valid locations a user can dispense from. The upshot of this, I think, is that a framework-wide useLocations() hook would take an arbitrary string for tags rather than a boolean to indicate whether to use a single tag or not.
  2. I'm not convinced that previous logged in locations are the right thing to display for anything other than previous logged-in locations. For example, if I am logged into Clinic 1 which has the sub-locations Room A, Room B, and Room C, it might make more sense for a form (like say the start visit form) to present me first with Room A, Room B, and Room C, since those are the sub-locations of the place I am currently working.

Both of these kind of speak against this being a useful enough function to include in the framework, especially with the name useLocations().

Copy link
Member

Choose a reason for hiding this comment

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

What I'm getting at isn't that we shouldn't have a useLocations() hook in the framework. It's that that hook should have different properties from the hook that is specific to login locations. It would be possible to implement a useLoginLocations() hook in terms of a generic useLocations() hook, but implementing a generic useLocations() hook cannot be easily done from a hook that implements logic that mostly makes sense in the context of login locations.

packages/tooling/openmrs/src/cli.ts Outdated Show resolved Hide resolved
playwright.config.ts Outdated Show resolved Hide resolved
@brandones
Copy link
Collaborator

Where are we at with this @vasharma05 ?

@vasharma05
Copy link
Member Author

Hi @brandones !
Awaiting @ibacher 's review, pushed prev review changes.
Thanks!

@ibacher
Copy link
Member

ibacher commented Apr 19, 2024

@vasharma05 Rename useLocations() to useLoginLocations() and I'm happy.

@ibacher ibacher dismissed their stale review April 19, 2024 18:55

Mostly done

@brandones
Copy link
Collaborator

@vasharma05 Thanks for making the requested changes. Can you resolve the conflicts and we'll get this in?

@ibacher ibacher force-pushed the main branch 2 times, most recently from 8f994a6 to 9cee659 Compare July 22, 2024 18:54
@brandones
Copy link
Collaborator

Ping @vasharma05 , it's so close, just have to resolve the conflicts...

@brandones
Copy link
Collaborator

Ping @vasharma05

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.

3 participants