-
Notifications
You must be signed in to change notification settings - Fork 248
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-2760: Present workspaces should leverage the promptBeforeClosing
function
#1613
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense if the closeWorkspace()
function returned a Promise<void>
rather than void
? Then instead of needing all this logic to embed the onWorkspaceClose()
callback, callers that need to do something after the workspace closes can just do:
closeWorkspace().then(/* do something */);
@vasharma05 order is cleared upon prompting. order-removed-even-before-user-discards.mp4 |
Thank you @usamaidrsk , I'll fix it! |
…rkspaces and keeping the closeWorkspace default behaviour intact
@vasharma05 Please re-request review when ready. I've got my eye on this. |
* t('unsavedChangesInForms', 'There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}') | ||
* t('closeWorkspaces', 'Discard changes in {{count}} workspaces', {count}) | ||
|
||
* t('unsavedChangesInOpenedWorkspace', 'You have unsaved changes in the opened workspace. Do you want to discard these changes?') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* t('unsavedChangesInOpenedWorkspace', 'You have unsaved changes in the opened workspace. Do you want to discard these changes?') | |
* t('unsavedChangesInOpenedWorkspace', 'You have unsaved changes in the currently opened workspace. Do you want to discard these changes?') |
* t('closingAllWorkspacesPromptTitle','You have unsaved changes') | ||
* t('closingAllWorkspacesPromptBody', 'There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}') | ||
* t('closeAllOpenedWorkspaces', 'Discard changes in {{count}} workspaces', {count}) | ||
* t('unsavedChangesInWorkspace', 'There are unsaved changes in {{workspaceName}}. Please save them before opening another workspace.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'm not sure that relying on workspace names for this particular translation is the most ideal approach because they're so arbitrary. That said, I don't have a better alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we had this in the previous versions as well, I say we move ahead with this
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Outdated
Show resolved
Hide resolved
"closeWorkspaces_other": "Discard changes in {{count}} workspaces", | ||
"closeAllOpenedWorkspaces_one": "Discard changes in {{count}} workspaces", | ||
"closeAllOpenedWorkspaces_other": "Discard changes in {{count}} workspaces", | ||
"closingAllWorkspacesPromptBody": "There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem right to repeat the phrase 'following workspaces' twice. Also, wouldn't it be better to list out the open workspaces as list items?
"closingAllWorkspacesPromptBody": "There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}", | |
"closingAllWorkspacesPromptBody": "There are unsaved changes in several workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}", |
packages/esm-patient-conditions-app/src/conditions/conditions-form.component.tsx
Outdated
Show resolved
Hide resolved
Co-authored-by: Dennis Kigen <[email protected]>
I had a discussion with Ciaran today in the O3 UI/UX Design hours, and he said that the Hence I will be reverting on the So sorry everyone for hanging this PR so long. Thank you for bearing with me and I'll finalize the PR for final review. |
Good call talking to Ciaran about it! Thanks for doing such a thorough job. |
Do let us know when you're ready so we can do a fresh pass of reviews, @vasharma05! This is very consequential work, thanks for taking it on! |
Hi @denniskigen! |
@@ -154,7 +166,7 @@ function AllergyForm({ closeWorkspace, patientUuid }: DefaultWorkspaceProps) { | |||
(response: FetchResponse) => { | |||
if (response.status === 201) { | |||
mutate(); | |||
closeWorkspace(); | |||
closeWorkspace({ ignoreChanges: true }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I see. Now that ignoreChanges
is false by default, we have to pass this argument on saving & exiting, which is a little awkward. Nevertheless I still think this is the right approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I guess the thing that is weird is actually that isDirty
is still true after the form is submitted. Logically, it seems like it shouldn't be.
* @returns | ||
*/ | ||
|
||
export function showWorkspacePrompts( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this as a pattern; I think it's inappropriate unless the same prompts are being launched from many different places in the code. It is better to have the content of the prompt housed in the context that it is relevant to. But that's just sort of a note for posterity; let's get this PR in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I agree with @denniskigen 's suggestions about copy but this is a big PR that's been around for a while already. Requesting his forgiveness and that we fix the copy after merging this.
Thanks so much for all your work on this @vasharma05 !
@vasharma05, the program enrollment E2E test has been failing since this PR. Can we sort it out pronto? New PRs are feeling the heat. Let's stick to the branch protection rules and avoid merging when checks are failing. |
Sure @jayasanka-sack ! |
Thanks, Vineet! ❤️ |
Coming back to this like the Proverbial grammar Sith lord. Can we fix the copy @brandones @vasharma05? |
I'll do this after we move workspaces into core. I have an idea: sometimes workspace titles are a little funny. But we can make workspace names whatever we want; there's no reason they need to be lowercased-and-hyphenated. Why don't we make workspace names exactly what should appear in notifications about that workspace? e.g. the allergy form, which has title |
I think the only issue with that is it needs to be translatable, since, presumably, we don’t want to need a separate allergy workspace per language, but I like the idea. |
Requirements
Summary
This PR updates the existing workspaces implementation to use the
promptBeforeClosing
functions in the workspaces.This PR makes the following changes in the codebase:
to registering them via
registerWorkspace`.promptBeforeClosing
function.All the workspace forms (except the Lab order form) use React Hook Form, which returns a state
isDirty
, which tells whether the user made any change to the form or not. ThepromptBeforeClosing
keeps an eye on the form stateisDirty
and decides whether to show the user a prompt when closing form without saving form changes.CloseWorkspace
Workspace's
closeWorkspace
now takes an object of the following keys as an argument:P.S. The onWorkspaceClose function can be used in the following manner:
GetWhetherWorkspaceCanBeClosed
A new function
getWhetherWorkspaceCanBeClosed
is introduced which tells whether a workspace can be directly closed or the user will be shown a prompt before closing the function.Screenshots
None
Related Issue
https://issues.openmrs.org/browse/O3-2760
Other
Also solves O3-2714.