Currently, the workspace system allows for multiple workspaces to be opened simultaneously (with one active and the rest minimized.) Minimized workspaces are useful in that it allows for unsaved changes to forms in the workspace while the user navigates to other workspaces or to different pages (say, different tabs within the patient chart) to look at data. The workspace system has 2 ways to prevent unsaved changes in opened workspaces from getting lost:
-
The workspace system has a concept of a workspace group; all opened workspaces must belong to the same active workspace group. If there is an attempt to open another workspace of a different workspace group, then the user is presented with a warning modal to discard any unsaved changes to the currently opened workspaces. There are 2 ways to define workspace group(s) for a given workspace:
a. When defining a workspace in
routes.json
file, we can optionally specify the workspace group(s) that it belongs to.b. Conversely, we can also declare a workspace group in a
routes.json
file and list of workspaces that are members of the workspace group. -
The workspace system has a concept of a
contextKey
. From here: “The context key is a string that appears in the URL, which defines the pages on which workspaces are valid. If the URL changes in a way such that it no longer contains the context key, then all workspaces will be closed”. The contextKey is passed in to the<WorkspaceContainer>
component. When the user attempts to naviagtes to a URL that no longer matches the context keys, they will also get a warning modal to discard unsaved changes.
Thus, we get “unsaved changes” prompt when we attempt to either naviate to a different URL or try to open workspace from another workspace group. However, I think there are navigations that are not necessarily URL changes that should also prompt for unsaved changes. Here’s my use case:
- For RDE, the vitals / visit notes / forms / order basket workspaces have a concept of the “Visit context”. For example, when creating a visit note, we set the visit context to the visit we want to add the visit note to. (For point of care, we set the visit context to the current active visit; for RDE, we select a past visit instead.) We are also starting to add ability to edit existing encounters. In particular, the visits table or the encounters table in the patient chart allows you to view / edit existing encounters across different visits, without navigating to differen tpages. When editing an existing encounter, the visit context should automatically switch to the visit associated with the encounter. However, we should only allow that to happen when there is no pending changes in existing opened workspaces.
Current, when we launch a workspace to have it opened in a specified workspace group, we do this:
launchWorkspaceGroup('ward-patient', {
workspaceToLaunch: {
name: 'ward-patient-workspace',
},
});
I propose that we solve the issue with the unsaved changes prompts when switching visit contexts by having a context key pass in to `launchWorkspaceGroup, something like this:
launchWorkspaceGroup('patient-chart-forms', {
workspaceToLaunch: {
name: 'visit-note-workspace',
},
contextKey: <visitUuid>,
URLKey: `patient/${patientUuid}`
});
Then, the workspace system shows the unsaved changes prompt if we attempt to do launchWorkspaceGroup
either:
- naviagte to a URL that does not match the
URLKey
- call
launchWorkspaceGroup
with a different group name, or - call
launchWorkspaceGroup
with the same group name, with differentcontextKey
.
Let me know what you think. Thanks!