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-2768: Display error in case there are no locations #906

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

Conversation

trevor-james-nangosha
Copy link

@trevor-james-nangosha trevor-james-nangosha commented Jan 28, 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 issue makes sure that an error is shown when no locations are returned from the backend on the location-selection screen

Screenshots

This is a small video that shows what happens in the aforementioned case. I would like to know if I am on the right track, or if I could possibly make some changes. @denniskigen

OpenMRS.-.Google.Chrome.2024-02-02.15-27-28.mp4

Related Issue

Issue is here

Other

@ibacher
Copy link
Member

ibacher commented Feb 1, 2024

This looks ok. Instead of manually rendering a toast (which ends up with a slightly weird UX, use the framework's showToast() method. Also, ideally, the loading indicator would disappear. Instead of "No locations were found for this instance", it should probably say "No locations were found for this system" or something along those lines.

@trevor-james-nangosha
Copy link
Author

@ibacher I have applied the changes as requested and also updated the video above to show the current state of things.

@trevor-james-nangosha trevor-james-nangosha marked this pull request as ready for review February 2, 2024 12:35
@trevor-james-nangosha
Copy link
Author

Done with the changes as requested @ibacher

@denniskigen
Copy link
Member

Sorry I'm getting to this late @trevor-james-nangosha @ibacher, but this is a mockup that Ciaran's thrown together for what this error notification could look like:

Screenshot 2024-02-15 at 11 50 18

You could imagine this appearing in place of the search bar in case no locations are configured. Should we just show a subtitle instead of the reload button with something along the lines of Please contact your administrator @ibacher?

@ibacher
Copy link
Member

ibacher commented Feb 15, 2024

Should we just show a subtitle instead of the reload button with something along the lines of Please contact your administrator @ibacher?

Maybe have a subtitle that says "If the issue persists please contact your administrator" and leave the refresh button?

@denniskigen
Copy link
Member

denniskigen commented Feb 15, 2024

Would clicking the Reload button just invoke window.location.reload() or would it do something else?

@denniskigen denniskigen changed the title (fix)o3-2768 Display error in case there are no locations (fix) O3-2768: Display error in case there are no locations Feb 15, 2024
@ibacher
Copy link
Member

ibacher commented Feb 19, 2024

Would clicking the Reload button just invoke window.location.reload() or would it do something else?

Presumably we could just call the mutator for SWR rather than doing a full page reload? This isn't a "component is broken" error, just a "data is missing error".

@trevor-james-nangosha To answer you're question from Slack, the image is just a sketch to show the inline notification. Leave the rest of the elements on the page.

@jayasanka-sack
Copy link
Member

Isn't the fallback for no locations is to Login without a location? As I can remember that's how the location picker was written.

title: t('error', 'Error'),
kind: 'error',
description: 'No locations were found for this system. Please contact your administrator',
});
changeLocation();
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to call this function, right?

Choose a reason for hiding this comment

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

Yea, did not see that. Will remove it!! Thanks.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@jayasanka-sack @vasharma05 What's up with this, should we remove this function call?

@ibacher
Copy link
Member

ibacher commented Feb 20, 2024

Isn't the fallback for no locations is to Login without a location?

I think that was what was originally implemented just to get something in. Most of the code in various places assumes that there's a session location and, while the backend technically supports logins without locations, the RefApp hasn't since O2.

Looking at this from a slightly different angle: we can either stop the user up-front with no locations or we can write tests for every place that accesses the session location to ensure they continue to function if there is no location available.

@mseaton
Copy link
Member

mseaton commented Feb 23, 2024

Looking at this from a slightly different angle: we can either stop the user up-front with no locations or we can write tests for every place that accesses the session location to ensure they continue to function if there is no location available

I do think this may be worth a follow-up discussion to confirm that we definitely want to make session location required in esm-core and the location picker, rather than just configured to be required within the refapp implementation of O3.

@trevor-james-nangosha
Copy link
Author

Screenshot showing behavior.
Screenshot (22)

@suubi-joshua
Copy link
Contributor

Screenshot showing behavior. Screenshot (22)

Great job @trevor-james-nangosha but I think I think if the locations don't load the confirm button should not show neither should the checker for remember my location.

@@ -16,6 +16,7 @@ import { useLoginLocations } from '../login.resource';
import styles from './location-picker.scss';
import { useDefaultLocation } from './location-picker.resource';
import type { ConfigSchema } from '../config-schema';
import { Snackbar } from '@openmrs/esm-styleguide/src/snackbars/snackbar.component';
Copy link
Member

Choose a reason for hiding this comment

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

import { showSnackbar } from "@openmrs/esm-framework"


const referrer = state?.referrer;
const returnToUrl = new URLSearchParams(location?.search).get('returnToUrl');

const sessionDefined = locationUuid ? setSessionLocation(locationUuid, new AbortController()) : Promise.resolve();
const sessionDefined = locationUuid ? setSessionLocation(locationUuid, new AbortController()) : Promise.reject();
Copy link
Member

Choose a reason for hiding this comment

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

Since we have the check above for undefined/null locationUuid, why add this unnecessary promise here?

Comment on lines 192 to 205
<Snackbar
snackbar={{
id: 1,
actionButtonLabel: t('reload', 'Reload'),
onActionButtonClick: () => mutate(),
kind: 'error',
title: t('locationsFailedToLoad', 'Locations failed to load'),
subtitle: t(
'locationIssueContactAdministrator',
'If the issue persists please contact your administrator',
),
}}
closeSnackbar={() => {}}
/>
Copy link
Member

Choose a reason for hiding this comment

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

Snackbar is a notification, it's not a component to be shown in place of search.
Please read here for more info

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 use an ActionableSnackbar, using the props actionButtonLabel and onActionButtonClick in the showSnackbar. Learn more about showSnackbar here:

export function showSnackbar(snackbar: SnackbarDescriptor) {

Comment on lines 110 to 119
if (!locations?.length) {
changeLocation();
}
Copy link
Member

Choose a reason for hiding this comment

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

      if (!error && !locations?.length) {
        changeLocation();
      }

Copy link
Member

Choose a reason for hiding this comment

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

@ibacher, do we have any implementation at all where there are no locations?
Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

It's not impossible, but I would say that that's a configuration error. Every functioning OMRS system should have at least one location.

@vasharma05
Copy link
Member

vasharma05 commented Mar 22, 2024

Updated error screen:

image

@vasharma05
Copy link
Member

Re-requesting review from @ibacher @samuelmale @denniskigen.
Thanks!

@@ -20,6 +20,7 @@ export const coreTranslations = {
change: 'Change',
close: 'Close',
confirm: 'Confirm',
contactAdministratorIfIssuePersists: 'If the problem persists contact your system administrator.',
Copy link
Collaborator

@brandones brandones Apr 19, 2024

Choose a reason for hiding this comment

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

Suggested change
contactAdministratorIfIssuePersists: 'If the problem persists contact your system administrator.',
contactAdministratorIfIssuePersists: 'Contact your system administrator if the problem persists.',

@brandones
Copy link
Collaborator

Based on the designs it looks like we can do away with the top "Welcome" block.

image

@ibacher
Copy link
Member

ibacher commented Apr 19, 2024

Based on the designs it looks like we can do away with the top "Welcome" block.

I thought the design there was just a sketch of the notification, not a full screen preview. I kind of prefer it with the "Welcome" block because it makes it look more like what it is (an unexpected error in one part of the system) rather than just a basically blank page.

@brandones
Copy link
Collaborator

That makes sense, thanks @ibacher . I think you're right.

Copy link
Collaborator

@brandones brandones left a comment

Choose a reason for hiding this comment

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

I have only minor feedback; feel free to ship this when you feel happy with it @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
9 participants