@openmrs/esm-patient-common-lib 7.0.2-pre.3790 → 7.0.2-pre.3795

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-patient-common-lib",
3
- "version": "7.0.2-pre.3790",
3
+ "version": "7.0.2-pre.3795",
4
4
  "license": "MPL-2.0",
5
5
  "description": "Library for common patient chart components",
6
6
  "browser": "dist/openmrs-esm-patient-common-lib.js",
@@ -38,5 +38,5 @@
38
38
  "react": "18.x",
39
39
  "single-spa": "6.x"
40
40
  },
41
- "gitHead": "232d0055dd69f62c4a686b8f25da652df9488c26"
41
+ "gitHead": "9cea718964ab0991a69914f347128d628ea08c0d"
42
42
  }
@@ -1,14 +1,35 @@
1
+ import { closeWorkspace } from '../workspaces';
2
+
1
3
  /* The possible states a workspace window can be opened in. */
2
4
  export type WorkspaceWindowState = 'maximized' | 'hidden' | 'normal';
3
5
 
6
+ export interface CloseWorkspaceOptions {
7
+ /**
8
+ * Whether to close the workspace ignoring all the changes present in the workspace.
9
+ *
10
+ * If ignoreChanges is true, the user will not be prompted to save changes before closing
11
+ * even if the `testFcn` passed to `promptBeforeClosing` returns `true`.
12
+ */
13
+ ignoreChanges?: boolean;
14
+ /**
15
+ * If you want to take an action after the workspace is closed, you can pass your function as
16
+ * `onWorkspaceClose`. This function will be called only after the workspace is closed, given
17
+ * that the user might be shown a prompt.
18
+ * @returns void
19
+ */
20
+ onWorkspaceClose?: () => void;
21
+ }
22
+
4
23
  /** The default parameters received by all workspaces */
5
24
  export interface DefaultWorkspaceProps {
6
25
  /**
7
- * Call this function to close the workspace. If ignoreChanges is true, the user will not be
8
- * prompted to save changes before closing, even if the `testFcn` passed to `promptBeforeClosing`
9
- * returns `true`.
26
+ * Call this function to close the workspace. This function will prompt the user
27
+ * if there are any unsaved changes to workspace.
28
+ *
29
+ * You can pass `onWorkspaceClose` function to be called when the workspace is finally
30
+ * closed, given the user forcefully closes the workspace.
10
31
  */
11
- closeWorkspace(ignoreChanges?: boolean): void;
32
+ closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
12
33
  /**
13
34
  * Call this with a no-args function that returns true if the user should be prompted before
14
35
  * this workspace is closed; e.g. if there is unsaved data.
@@ -70,18 +70,20 @@ describe('workspace system', () => {
70
70
  expect(store.getState().openWorkspaces.length).toEqual(0);
71
71
  });
72
72
 
73
- it('should show a modal when a workspace is already open and it cannot hide', () => {
73
+ it('should show a modal when a workspace is already open (with changes) and it cannot hide', () => {
74
74
  const store = getWorkspaceStore();
75
75
  registerWorkspace({ name: 'allergies', title: 'Allergies', load: jest.fn() });
76
76
  launchPatientWorkspace('allergies', { foo: true });
77
77
  expect(store.getState().openWorkspaces.length).toEqual(1);
78
+ const allergies = store.getState().openWorkspaces?.[0];
79
+ allergies.promptBeforeClosing(() => true);
78
80
  registerWorkspace({ name: 'conditions', title: 'Conditions', load: jest.fn() });
79
81
  launchPatientWorkspace('conditions', { foo: true });
80
82
  const prompt = store.getState().prompt;
81
83
  expect(prompt).toBeTruthy();
82
- expect(prompt.title).toMatch('You have unsaved changes');
84
+ expect(prompt.title).toMatch('Unsaved Changes');
83
85
  expect(prompt.body).toMatch(
84
- 'There are unsaved changes in Allergies. Please save them before opening another form.',
86
+ 'There are unsaved changes in Allergies. Please save them before opening another workspace.',
85
87
  );
86
88
  expect(prompt.confirmText).toMatch('Open anyway');
87
89
  prompt.onConfirm();
@@ -137,15 +139,17 @@ describe('workspace system', () => {
137
139
  expect(store.getState().openWorkspaces.length).toEqual(2);
138
140
  expect(store.getState().openWorkspaces[0].name).toBe('conditions');
139
141
  expect(store.getState().openWorkspaces[1].name).toBe('allergies');
142
+ const allergies = store.getState().openWorkspaces[1];
143
+ allergies.promptBeforeClosing(() => true);
140
144
  launchPatientWorkspace('vitals');
141
145
  expect(store.getState().openWorkspaces.length).toEqual(2);
142
146
  expect(store.getState().openWorkspaces[0].name).toBe('allergies');
143
147
  expect(store.getState().openWorkspaces[1].name).toBe('conditions');
144
148
  const prompt = store.getState().prompt;
145
149
  expect(prompt).toBeTruthy();
146
- expect(prompt.title).toMatch('You have unsaved changes');
150
+ expect(prompt.title).toMatch('Unsaved Changes');
147
151
  expect(prompt.body).toMatch(
148
- 'There are unsaved changes in Allergies. Please save them before opening another form.',
152
+ 'There are unsaved changes in Allergies. Please save them before opening another workspace.',
149
153
  );
150
154
  expect(prompt.confirmText).toMatch('Open anyway');
151
155
  prompt.onConfirm();
@@ -223,13 +227,17 @@ describe('workspace system', () => {
223
227
  launchPatientWorkspace('conditions');
224
228
  expect(store.getState().openWorkspaces.length).toEqual(3);
225
229
  expect(store.getState().openWorkspaces.map((w) => w.name)).toEqual(['conditions', 'attachments', 'allergies']);
230
+ const conditionsWorkspace = store.getState().openWorkspaces?.[0];
231
+ const allergiesWorkspace = store.getState().openWorkspaces?.[2];
232
+ conditionsWorkspace.promptBeforeClosing(() => true);
233
+ allergiesWorkspace.promptBeforeClosing(() => true);
226
234
  launchPatientWorkspace('vitals');
227
235
  expect(store.getState().openWorkspaces.length).toEqual(3);
228
236
  expect(store.getState().openWorkspaces[0].name).toBe('conditions');
229
237
  const prompt = store.getState().prompt;
230
238
  expect(prompt).toBeTruthy();
231
239
  expect(prompt.body).toMatch(
232
- 'There are unsaved changes in Conditions. Please save them before opening another form.',
240
+ 'There are unsaved changes in Conditions. Please save them before opening another workspace.',
233
241
  );
234
242
  // Closing the conditions workspace because it cannot be hidden
235
243
  prompt.onConfirm();
@@ -239,7 +247,7 @@ describe('workspace system', () => {
239
247
  const prompt2 = store.getState().prompt;
240
248
  expect(prompt2).toBeTruthy();
241
249
  expect(prompt2.body).toMatch(
242
- 'There are unsaved changes in Allergies. Please save them before opening another form.',
250
+ 'There are unsaved changes in Allergies. Please save them before opening another workspace.',
243
251
  );
244
252
  prompt2.onConfirm();
245
253
  expect(store.getState().openWorkspaces.length).toEqual(2);
@@ -280,11 +288,11 @@ describe('workspace system', () => {
280
288
  launchPatientWorkspace('conditions');
281
289
  expect(store.getState().openWorkspaces.length).toBe(3);
282
290
  expect(store.getState().workspaceWindowState).toBe('maximized');
283
- store.getState().openWorkspaces[0].closeWorkspace(false);
291
+ store.getState().openWorkspaces[0].closeWorkspace({ ignoreChanges: true });
284
292
  expect(store.getState().workspaceWindowState).toBe('normal');
285
- store.getState().openWorkspaces[0].closeWorkspace(false);
293
+ store.getState().openWorkspaces[0].closeWorkspace();
286
294
  expect(store.getState().workspaceWindowState).toBe('maximized');
287
- store.getState().openWorkspaces[0].closeWorkspace(false);
295
+ store.getState().openWorkspaces[0].closeWorkspace({ ignoreChanges: true });
288
296
  expect(store.getState().workspaceWindowState).toBe('normal');
289
297
  });
290
298
  });
@@ -306,11 +314,13 @@ describe('workspace system', () => {
306
314
  launchPatientWorkspace('conditions');
307
315
  launchPatientWorkspace('conditions');
308
316
  expect(store.getState().openWorkspaces.length).toEqual(1);
317
+ const conditionsWorkspace = store.getState().openWorkspaces[0];
318
+ conditionsWorkspace.promptBeforeClosing(() => true);
309
319
  // Test opening a workspace of the same type--should require confirmation and then replace
310
320
  launchPatientWorkspace('form-entry', { foo: true });
311
321
  expect(store.getState().openWorkspaces.length).toEqual(1);
312
322
  expect(store.getState().openWorkspaces[0].name).toBe('conditions');
313
- expect(store.getState().prompt.title).toMatch('You have unsaved changes');
323
+ expect(store.getState().prompt.title).toMatch('Unsaved Changes');
314
324
  store.getState().prompt.onConfirm();
315
325
  expect(store.getState().prompt).toBeNull();
316
326
  expect(store.getState().openWorkspaces.length).toEqual(1);
@@ -321,13 +331,15 @@ describe('workspace system', () => {
321
331
  expect(store.getState().openWorkspaces.length).toEqual(2);
322
332
  expect(store.getState().openWorkspaces[0].name).toBe('order-meds');
323
333
  expect(store.getState().openWorkspaces[1].name).toBe('form-entry');
334
+ const formEntryWorkspace = store.getState().openWorkspaces[1];
335
+ formEntryWorkspace.promptBeforeClosing(() => true);
324
336
  // Test going through confirmation flow while order-meds is open
325
337
  // Changing the form workspace shouldn't destroy the order-meds workspace
326
338
  launchPatientWorkspace('conditions');
327
339
  expect(store.getState().openWorkspaces.length).toEqual(2);
328
340
  expect(store.getState().openWorkspaces[0].name).toBe('form-entry');
329
341
  expect(store.getState().openWorkspaces[1].name).toBe('order-meds');
330
- expect(store.getState().prompt.title).toMatch('You have unsaved changes');
342
+ expect(store.getState().prompt.title).toMatch('Unsaved Changes');
331
343
  cancelPrompt(); // should leave same workspaces intact
332
344
  expect(store.getState().openWorkspaces.length).toEqual(2);
333
345
  expect(store.getState().openWorkspaces[0].name).toBe('form-entry');
@@ -338,7 +350,7 @@ describe('workspace system', () => {
338
350
  expect(store.getState().openWorkspaces.length).toEqual(2);
339
351
  expect(store.getState().openWorkspaces[0].name).toBe('conditions');
340
352
  expect(store.getState().openWorkspaces[1].name).toBe('order-meds');
341
- store.getState().openWorkspaces[0].closeWorkspace();
353
+ store.getState().openWorkspaces[0].closeWorkspace({ ignoreChanges: true });
342
354
  expect(store.getState().openWorkspaces.length).toEqual(1);
343
355
  expect(store.getState().openWorkspaces[0].name).toBe('order-meds');
344
356
  });
@@ -355,7 +367,7 @@ describe('workspace system', () => {
355
367
  store.getState().openWorkspaces[0].promptBeforeClosing(() => true);
356
368
  launchPatientWorkspace('hiv');
357
369
  expect(store.getState().openWorkspaces[0].name).toBe('diabetes');
358
- expect(store.getState().prompt.title).toBe('You have unsaved changes');
370
+ expect(store.getState().prompt.title).toBe('Unsaved Changes');
359
371
  store.getState().prompt.onConfirm();
360
372
  expect(store.getState().openWorkspaces[0].name).toBe('hiv');
361
373
  });
@@ -389,10 +401,10 @@ describe('workspace system', () => {
389
401
  registerWorkspace({ name: 'hiv', title: 'HIV', load: jest.fn() });
390
402
  launchPatientWorkspace('hiv');
391
403
  store.getState().openWorkspaces[0].promptBeforeClosing(() => true);
392
- store.getState().openWorkspaces[0].closeWorkspace(false);
404
+ store.getState().openWorkspaces[0].closeWorkspace({ ignoreChanges: false });
393
405
  expect(store.getState().prompt.title).toBe('Unsaved Changes');
394
406
  expect(store.getState().prompt.body).toBe(
395
- 'You have unsaved changes in the side panel. Do you want to discard these changes?',
407
+ 'You have unsaved changes in the opened workspace. Do you want to discard these changes?',
396
408
  );
397
409
  expect(store.getState().prompt.confirmText).toBe('Discard');
398
410
  store.getState().prompt.onConfirm();
@@ -2,7 +2,7 @@ import { type ExtensionRegistration, getGlobalStore, navigate, translateFrom } f
2
2
  // FIXME We should not rely on internals here
3
3
  import { getExtensionRegistration } from '@openmrs/esm-framework/src/internal';
4
4
  import _i18n from 'i18next';
5
- import { type WorkspaceWindowState } from '../types/workspace';
5
+ import { type WorkspaceWindowState, type CloseWorkspaceOptions } from '../types/workspace';
6
6
 
7
7
  export interface Prompt {
8
8
  title: string;
@@ -23,8 +23,7 @@ export interface WorkspaceStoreState {
23
23
 
24
24
  export interface OpenWorkspace extends WorkspaceRegistration {
25
25
  additionalProps: object;
26
- closeWorkspace(promptBeforeClosing?: boolean): void;
27
- closeWorkspace(): void;
26
+ closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): boolean;
28
27
  promptBeforeClosing(testFcn: () => boolean): void;
29
28
  }
30
29
 
@@ -103,40 +102,37 @@ function getTitleFromExtension(ext: ExtensionRegistration) {
103
102
  return ext.name;
104
103
  }
105
104
 
105
+ /**
106
+ *
107
+ * @param name Name of the workspace
108
+ * @param ignoreChanges If set to true, the "unsaved changes" modal will never be shown, even if the `promptBeforeClosing` function returns true. The user will not be prompted before closing.
109
+ * @returns true if the workspace can be closed.
110
+ */
111
+ export function canCloseWorkspaceWithoutPrompting(name: string, ignoreChanges: boolean = false) {
112
+ if (ignoreChanges) {
113
+ return true;
114
+ }
115
+ const promptBeforeFn = getPromptBeforeClosingFcn(name);
116
+ return !promptBeforeFn || !promptBeforeFn();
117
+ }
118
+
106
119
  function promptBeforeLaunchingWorkspace(
107
120
  workspace: OpenWorkspace,
108
121
  newWorkspaceDetails: { name: string; additionalProps?: object },
109
122
  ) {
110
- const store = getWorkspaceStore();
111
123
  const { name, additionalProps } = newWorkspaceDetails;
112
- const promptCheckFcn = getPromptBeforeClosingFcn(workspace.name);
113
124
 
114
125
  const proceed = () => {
115
- workspace.closeWorkspace();
116
- // Calling the launchPatientWorkspace again, since one of the `if` case
117
- // might resolve, but we need to check all the cases before launching the form.
118
- launchPatientWorkspace(name, additionalProps);
126
+ workspace.closeWorkspace({
127
+ ignoreChanges: true,
128
+ // Calling the launchPatientWorkspace again, since one of the `if` case
129
+ // might resolve, but we need to check all the cases before launching the form.
130
+ onWorkspaceClose: () => launchPatientWorkspace(name, additionalProps),
131
+ });
119
132
  };
120
133
 
121
- if (!promptCheckFcn || promptCheckFcn()) {
122
- const currentName = workspace.title ?? workspace.name;
123
- const prompt: Prompt = {
124
- title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChanges', 'You have unsaved changes'),
125
- body: translateFrom(
126
- '@openmrs/esm-patient-chart-app',
127
- 'unsavedChangesInForm',
128
- 'There are unsaved changes in {{formName}}. Please save them before opening another form.',
129
- { formName: currentName },
130
- ),
131
- onConfirm: () => {
132
- store.setState({
133
- prompt: null,
134
- });
135
- proceed();
136
- },
137
- confirmText: translateFrom('@openmrs/esm-patient-chart-app', 'openAnyway', 'Open anyway'),
138
- };
139
- store.setState((state) => ({ ...state, prompt }));
134
+ if (!canCloseWorkspaceWithoutPrompting(workspace.name)) {
135
+ showWorkspacePrompts('closing-workspace-launching-new-workspace', proceed, workspace.title ?? workspace.name);
140
136
  } else {
141
137
  proceed();
142
138
  }
@@ -166,7 +162,7 @@ export function launchPatientWorkspace(name: string, additionalProps?: object) {
166
162
  const workspace = getWorkspaceRegistration(name);
167
163
  const newWorkspace = {
168
164
  ...workspace,
169
- closeWorkspace: (ignoreChanges = true) => closeWorkspace(name, ignoreChanges),
165
+ closeWorkspace: (options: CloseWorkspaceOptions = {}) => closeWorkspace(name, options),
170
166
  promptBeforeClosing: (testFcn) => promptBeforeClosing(name, testFcn),
171
167
  additionalProps,
172
168
  };
@@ -244,38 +240,44 @@ export function cancelPrompt() {
244
240
  store.setState({ ...state, prompt: null });
245
241
  }
246
242
 
247
- export function closeWorkspace(name: string, ignoreChanges: boolean) {
243
+ /**
244
+ * Function to close an opened workspace
245
+ * @param name Workspace registration name
246
+ * @param options Options to close workspace
247
+ * @returns
248
+ */
249
+ export function closeWorkspace(
250
+ name: string,
251
+ options: CloseWorkspaceOptions = {
252
+ ignoreChanges: false,
253
+ onWorkspaceClose: () => {},
254
+ },
255
+ ): boolean {
248
256
  const store = getWorkspaceStore();
249
- const promptCheckFcn = getPromptBeforeClosingFcn(name);
250
257
 
251
258
  const updateStoreWithClosedWorkspace = () => {
252
259
  const state = store.getState();
253
260
  const newOpenWorkspaces = state.openWorkspaces.filter((w) => w.name != name);
254
261
 
262
+ // promptBeforeClosing function should be removed if the workspace is closed.
263
+ promptBeforeClosing(name, null);
255
264
  store.setState({
256
265
  ...state,
257
266
  prompt: null,
258
267
  openWorkspaces: newOpenWorkspaces,
259
268
  workspaceWindowState: getUpdatedWorkspaceWindowState(newOpenWorkspaces?.[0]),
260
269
  });
270
+
271
+ options?.onWorkspaceClose?.();
261
272
  };
262
273
 
263
- if (!ignoreChanges && promptCheckFcn && promptCheckFcn()) {
264
- const prompt: Prompt = {
265
- title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChangesTitleText', 'Unsaved Changes'),
266
- body: translateFrom(
267
- '@openmrs/esm-patient-chart-app',
268
- 'unsavedChangeText',
269
- `You have unsaved changes in the side panel. Do you want to discard these changes?`,
270
- ),
271
- onConfirm: () => {
272
- updateStoreWithClosedWorkspace();
273
- },
274
- confirmText: translateFrom('@openmrs/esm-patient-chart-app', 'discard', 'Discard'),
275
- };
276
- store.setState({ ...store.getState(), prompt });
274
+ if (!canCloseWorkspaceWithoutPrompting(name, options?.ignoreChanges)) {
275
+ const currentName = getWorkspaceRegistration(name).title ?? name;
276
+ showWorkspacePrompts('closing-workspace', updateStoreWithClosedWorkspace, currentName);
277
+ return false;
277
278
  } else {
278
279
  updateStoreWithClosedWorkspace();
280
+ return true;
279
281
  }
280
282
  }
281
283
 
@@ -315,7 +317,7 @@ export function closeAllWorkspaces(onClosingWorkspaces: () => void = () => {}) {
315
317
  const store = getWorkspaceStore();
316
318
 
317
319
  const canCloseAllWorkspaces = store.getState().openWorkspaces.every(({ name }) => {
318
- const canCloseWorkspace = getWhetherWorkspaceCanBeClosed(name);
320
+ const canCloseWorkspace = canCloseWorkspaceWithoutPrompting(name);
319
321
  return canCloseWorkspace;
320
322
  });
321
323
 
@@ -331,31 +333,60 @@ export function closeAllWorkspaces(onClosingWorkspaces: () => void = () => {}) {
331
333
  }
332
334
  }
333
335
 
334
- export function getWhetherWorkspaceCanBeClosed(name: string, ignoreChanges = false) {
335
- const promptCheckFcn = getPromptBeforeClosingFcn(name);
336
- return ignoreChanges || !promptCheckFcn || !promptCheckFcn();
337
- }
338
-
339
336
  type PromptType = 'closing-workspace' | 'closing-all-workspaces' | 'closing-workspace-launching-new-workspace';
340
337
 
341
- export function showWorkspacePrompts(promptType: PromptType, onConfirmation: () => void = () => {}) {
338
+ /**
339
+ * Which type of prompt should be shown to the user.
340
+ * @param promptType 'closing-workspace' | 'closing-all-workspaces' | 'closing-workspace-launching-new-workspace'
341
+ * @param onConfirmation Function to be called after the user confirms to close the workspace
342
+ * @param workspaceTitle Workspace title to be shown in the prompt
343
+ * @returns
344
+ */
345
+
346
+ export function showWorkspacePrompts(
347
+ promptType: PromptType,
348
+ onConfirmation: () => void = () => {},
349
+ workspaceTitle: string = '',
350
+ ) {
342
351
  const store = getWorkspaceStore();
343
352
 
344
353
  switch (promptType) {
354
+ case 'closing-workspace': {
355
+ const prompt: Prompt = {
356
+ title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChangesTitleText', 'Unsaved Changes'),
357
+ body: translateFrom(
358
+ '@openmrs/esm-patient-chart-app',
359
+ 'unsavedChangesInOpenedWorkspace',
360
+ `You have unsaved changes in the opened workspace. Do you want to discard these changes?`,
361
+ ),
362
+ onConfirm: () => {
363
+ onConfirmation?.();
364
+ },
365
+ confirmText: translateFrom('@openmrs/esm-patient-chart-app', 'discard', 'Discard'),
366
+ };
367
+ store.setState({ ...store.getState(), prompt });
368
+ store.setState((prevState) => ({ ...prevState, prompt }));
369
+ return;
370
+ }
371
+
345
372
  case 'closing-all-workspaces': {
346
373
  const workspacesNotClosed = store
347
374
  .getState()
348
- .openWorkspaces.filter(({ name }) => !getWhetherWorkspaceCanBeClosed(name))
375
+ .openWorkspaces.filter(({ name }) => !canCloseWorkspaceWithoutPrompting(name))
349
376
  .map(({ title }, indx) => `${indx + 1}. ${title}`);
350
377
 
351
378
  const prompt: Prompt = {
352
- title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChanges', 'You have unsaved changes'),
379
+ title: translateFrom(
380
+ '@openmrs/esm-patient-chart-app',
381
+ 'closingAllWorkspacesPromptTitle',
382
+ 'You have unsaved changes',
383
+ ),
353
384
  body: translateFrom(
354
385
  '@openmrs/esm-patient-chart-app',
355
- 'unsavedChangesInForms',
356
- `There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}`,
386
+ 'closingAllWorkspacesPromptBody',
387
+ 'There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}',
357
388
  {
358
- workspaceNames: workspacesNotClosed.join(' '),
389
+ workspaceNames: workspacesNotClosed.join(','),
359
390
  },
360
391
  ),
361
392
  onConfirm: () => {
@@ -363,7 +394,7 @@ export function showWorkspacePrompts(promptType: PromptType, onConfirmation: ()
363
394
  },
364
395
  confirmText: translateFrom(
365
396
  '@openmrs/esm-patient-chart-app',
366
- 'closeWorkspaces',
397
+ 'closeAllOpenedWorkspaces',
367
398
  'Discard changes in {{count}} workspaces',
368
399
  { count: workspacesNotClosed.length },
369
400
  ),
@@ -374,6 +405,30 @@ export function showWorkspacePrompts(promptType: PromptType, onConfirmation: ()
374
405
  }));
375
406
  return;
376
407
  }
408
+ case 'closing-workspace-launching-new-workspace': {
409
+ const prompt: Prompt = {
410
+ title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChangesTitleText', 'Unsaved Changes'),
411
+ body: translateFrom(
412
+ '@openmrs/esm-patient-chart-app',
413
+ 'unsavedChangesInWorkspace',
414
+ 'There are unsaved changes in {{workspaceName}}. Please save them before opening another workspace.',
415
+ { workspaceName: workspaceTitle },
416
+ ),
417
+ onConfirm: () => {
418
+ store.setState((prevState) => ({
419
+ ...prevState,
420
+ prompt: null,
421
+ }));
422
+ onConfirmation?.();
423
+ },
424
+ confirmText: translateFrom('@openmrs/esm-patient-chart-app', 'openAnyway', 'Open anyway'),
425
+ };
426
+ store.setState((prevState) => ({
427
+ ...prevState,
428
+ prompt,
429
+ }));
430
+ return;
431
+ }
377
432
  default: {
378
433
  onConfirmation?.();
379
434
  return;