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

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.3814",
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": "824f92345387bcc46b07f64dc68ebd654de09211"
42
42
  }
@@ -1,19 +1,43 @@
1
1
  /* The possible states a workspace window can be opened in. */
2
2
  export type WorkspaceWindowState = 'maximized' | 'hidden' | 'normal';
3
3
 
4
+ export interface CloseWorkspaceOptions {
5
+ /**
6
+ * Whether to close the workspace ignoring all the changes present in the workspace.
7
+ *
8
+ * If ignoreChanges is true, the user will not be prompted to save changes before closing
9
+ * even if the `testFcn` passed to `promptBeforeClosing` returns `true`.
10
+ */
11
+ ignoreChanges?: boolean;
12
+ /**
13
+ * If you want to take an action after the workspace is closed, you can pass your function as
14
+ * `onWorkspaceClose`. This function will be called only after the workspace is closed, given
15
+ * that the user might be shown a prompt.
16
+ * @returns void
17
+ */
18
+ onWorkspaceClose?: () => void;
19
+ }
20
+
4
21
  /** The default parameters received by all workspaces */
5
22
  export interface DefaultWorkspaceProps {
6
23
  /**
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`.
24
+ * Call this function to close the workspace. This function will prompt the user
25
+ * if there are any unsaved changes to workspace.
26
+ *
27
+ * You can pass `onWorkspaceClose` function to be called when the workspace is finally
28
+ * closed, given the user forcefully closes the workspace.
10
29
  */
11
- closeWorkspace(ignoreChanges?: boolean): void;
30
+ closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
12
31
  /**
13
32
  * Call this with a no-args function that returns true if the user should be prompted before
14
33
  * this workspace is closed; e.g. if there is unsaved data.
15
34
  */
16
35
  promptBeforeClosing(testFcn: () => boolean): void;
36
+ /**
37
+ * Call this function to close the workspace after the form is saved. This function
38
+ * will directly close the workspace without any prompt
39
+ */
40
+ closeWorkspaceWithSavedChanges(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
17
41
  patientUuid: string;
18
42
  handlePostResponse?(): void;
19
43
  }
@@ -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,8 @@ 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;
27
+ closeWorkspaceWithSavedChanges(closeWorkspaceOptions?: CloseWorkspaceOptions): boolean;
28
28
  promptBeforeClosing(testFcn: () => boolean): void;
29
29
  }
30
30
 
@@ -103,40 +103,37 @@ function getTitleFromExtension(ext: ExtensionRegistration) {
103
103
  return ext.name;
104
104
  }
105
105
 
106
+ /**
107
+ *
108
+ * @param name Name of the workspace
109
+ * @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.
110
+ * @returns true if the workspace can be closed.
111
+ */
112
+ export function canCloseWorkspaceWithoutPrompting(name: string, ignoreChanges: boolean = false) {
113
+ if (ignoreChanges) {
114
+ return true;
115
+ }
116
+ const promptBeforeFn = getPromptBeforeClosingFcn(name);
117
+ return !promptBeforeFn || !promptBeforeFn();
118
+ }
119
+
106
120
  function promptBeforeLaunchingWorkspace(
107
121
  workspace: OpenWorkspace,
108
122
  newWorkspaceDetails: { name: string; additionalProps?: object },
109
123
  ) {
110
- const store = getWorkspaceStore();
111
124
  const { name, additionalProps } = newWorkspaceDetails;
112
- const promptCheckFcn = getPromptBeforeClosingFcn(workspace.name);
113
125
 
114
126
  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);
127
+ workspace.closeWorkspace({
128
+ ignoreChanges: true,
129
+ // Calling the launchPatientWorkspace again, since one of the `if` case
130
+ // might resolve, but we need to check all the cases before launching the form.
131
+ onWorkspaceClose: () => launchPatientWorkspace(name, additionalProps),
132
+ });
119
133
  };
120
134
 
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 }));
135
+ if (!canCloseWorkspaceWithoutPrompting(workspace.name)) {
136
+ showWorkspacePrompts('closing-workspace-launching-new-workspace', proceed, workspace.title ?? workspace.name);
140
137
  } else {
141
138
  proceed();
142
139
  }
@@ -166,7 +163,9 @@ export function launchPatientWorkspace(name: string, additionalProps?: object) {
166
163
  const workspace = getWorkspaceRegistration(name);
167
164
  const newWorkspace = {
168
165
  ...workspace,
169
- closeWorkspace: (ignoreChanges = true) => closeWorkspace(name, ignoreChanges),
166
+ closeWorkspace: (options: CloseWorkspaceOptions = {}) => closeWorkspace(name, options),
167
+ closeWorkspaceWithSavedChanges: (options: CloseWorkspaceOptions) =>
168
+ closeWorkspace(name, { ignoreChanges: true, ...options }),
170
169
  promptBeforeClosing: (testFcn) => promptBeforeClosing(name, testFcn),
171
170
  additionalProps,
172
171
  };
@@ -244,38 +243,44 @@ export function cancelPrompt() {
244
243
  store.setState({ ...state, prompt: null });
245
244
  }
246
245
 
247
- export function closeWorkspace(name: string, ignoreChanges: boolean) {
246
+ /**
247
+ * Function to close an opened workspace
248
+ * @param name Workspace registration name
249
+ * @param options Options to close workspace
250
+ * @returns
251
+ */
252
+ export function closeWorkspace(
253
+ name: string,
254
+ options: CloseWorkspaceOptions = {
255
+ ignoreChanges: false,
256
+ onWorkspaceClose: () => {},
257
+ },
258
+ ): boolean {
248
259
  const store = getWorkspaceStore();
249
- const promptCheckFcn = getPromptBeforeClosingFcn(name);
250
260
 
251
261
  const updateStoreWithClosedWorkspace = () => {
252
262
  const state = store.getState();
253
263
  const newOpenWorkspaces = state.openWorkspaces.filter((w) => w.name != name);
254
264
 
265
+ // promptBeforeClosing function should be removed if the workspace is closed.
266
+ promptBeforeClosing(name, null);
255
267
  store.setState({
256
268
  ...state,
257
269
  prompt: null,
258
270
  openWorkspaces: newOpenWorkspaces,
259
271
  workspaceWindowState: getUpdatedWorkspaceWindowState(newOpenWorkspaces?.[0]),
260
272
  });
273
+
274
+ options?.onWorkspaceClose?.();
261
275
  };
262
276
 
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 });
277
+ if (!canCloseWorkspaceWithoutPrompting(name, options?.ignoreChanges)) {
278
+ const currentName = getWorkspaceRegistration(name).title ?? name;
279
+ showWorkspacePrompts('closing-workspace', updateStoreWithClosedWorkspace, currentName);
280
+ return false;
277
281
  } else {
278
282
  updateStoreWithClosedWorkspace();
283
+ return true;
279
284
  }
280
285
  }
281
286
 
@@ -315,7 +320,7 @@ export function closeAllWorkspaces(onClosingWorkspaces: () => void = () => {}) {
315
320
  const store = getWorkspaceStore();
316
321
 
317
322
  const canCloseAllWorkspaces = store.getState().openWorkspaces.every(({ name }) => {
318
- const canCloseWorkspace = getWhetherWorkspaceCanBeClosed(name);
323
+ const canCloseWorkspace = canCloseWorkspaceWithoutPrompting(name);
319
324
  return canCloseWorkspace;
320
325
  });
321
326
 
@@ -331,31 +336,60 @@ export function closeAllWorkspaces(onClosingWorkspaces: () => void = () => {}) {
331
336
  }
332
337
  }
333
338
 
334
- export function getWhetherWorkspaceCanBeClosed(name: string, ignoreChanges = false) {
335
- const promptCheckFcn = getPromptBeforeClosingFcn(name);
336
- return ignoreChanges || !promptCheckFcn || !promptCheckFcn();
337
- }
338
-
339
339
  type PromptType = 'closing-workspace' | 'closing-all-workspaces' | 'closing-workspace-launching-new-workspace';
340
340
 
341
- export function showWorkspacePrompts(promptType: PromptType, onConfirmation: () => void = () => {}) {
341
+ /**
342
+ * Which type of prompt should be shown to the user.
343
+ * @param promptType 'closing-workspace' | 'closing-all-workspaces' | 'closing-workspace-launching-new-workspace'
344
+ * @param onConfirmation Function to be called after the user confirms to close the workspace
345
+ * @param workspaceTitle Workspace title to be shown in the prompt
346
+ * @returns
347
+ */
348
+
349
+ export function showWorkspacePrompts(
350
+ promptType: PromptType,
351
+ onConfirmation: () => void = () => {},
352
+ workspaceTitle: string = '',
353
+ ) {
342
354
  const store = getWorkspaceStore();
343
355
 
344
356
  switch (promptType) {
357
+ case 'closing-workspace': {
358
+ const prompt: Prompt = {
359
+ title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChangesTitleText', 'Unsaved Changes'),
360
+ body: translateFrom(
361
+ '@openmrs/esm-patient-chart-app',
362
+ 'unsavedChangesInOpenedWorkspace',
363
+ `You have unsaved changes in the opened workspace. Do you want to discard these changes?`,
364
+ ),
365
+ onConfirm: () => {
366
+ onConfirmation?.();
367
+ },
368
+ confirmText: translateFrom('@openmrs/esm-patient-chart-app', 'discard', 'Discard'),
369
+ };
370
+ store.setState({ ...store.getState(), prompt });
371
+ store.setState((prevState) => ({ ...prevState, prompt }));
372
+ return;
373
+ }
374
+
345
375
  case 'closing-all-workspaces': {
346
376
  const workspacesNotClosed = store
347
377
  .getState()
348
- .openWorkspaces.filter(({ name }) => !getWhetherWorkspaceCanBeClosed(name))
378
+ .openWorkspaces.filter(({ name }) => !canCloseWorkspaceWithoutPrompting(name))
349
379
  .map(({ title }, indx) => `${indx + 1}. ${title}`);
350
380
 
351
381
  const prompt: Prompt = {
352
- title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChanges', 'You have unsaved changes'),
382
+ title: translateFrom(
383
+ '@openmrs/esm-patient-chart-app',
384
+ 'closingAllWorkspacesPromptTitle',
385
+ 'You have unsaved changes',
386
+ ),
353
387
  body: translateFrom(
354
388
  '@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}}`,
389
+ 'closingAllWorkspacesPromptBody',
390
+ 'There are unsaved changes in the following workspaces. Do you want to discard changes in the following workspaces? {{workspaceNames}}',
357
391
  {
358
- workspaceNames: workspacesNotClosed.join(' '),
392
+ workspaceNames: workspacesNotClosed.join(','),
359
393
  },
360
394
  ),
361
395
  onConfirm: () => {
@@ -363,7 +397,7 @@ export function showWorkspacePrompts(promptType: PromptType, onConfirmation: ()
363
397
  },
364
398
  confirmText: translateFrom(
365
399
  '@openmrs/esm-patient-chart-app',
366
- 'closeWorkspaces',
400
+ 'closeAllOpenedWorkspaces',
367
401
  'Discard changes in {{count}} workspaces',
368
402
  { count: workspacesNotClosed.length },
369
403
  ),
@@ -374,6 +408,30 @@ export function showWorkspacePrompts(promptType: PromptType, onConfirmation: ()
374
408
  }));
375
409
  return;
376
410
  }
411
+ case 'closing-workspace-launching-new-workspace': {
412
+ const prompt: Prompt = {
413
+ title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChangesTitleText', 'Unsaved Changes'),
414
+ body: translateFrom(
415
+ '@openmrs/esm-patient-chart-app',
416
+ 'unsavedChangesInWorkspace',
417
+ 'There are unsaved changes in {{workspaceName}}. Please save them before opening another workspace.',
418
+ { workspaceName: workspaceTitle },
419
+ ),
420
+ onConfirm: () => {
421
+ store.setState((prevState) => ({
422
+ ...prevState,
423
+ prompt: null,
424
+ }));
425
+ onConfirmation?.();
426
+ },
427
+ confirmText: translateFrom('@openmrs/esm-patient-chart-app', 'openAnyway', 'Open anyway'),
428
+ };
429
+ store.setState((prevState) => ({
430
+ ...prevState,
431
+ prompt,
432
+ }));
433
+ return;
434
+ }
377
435
  default: {
378
436
  onConfirmation?.();
379
437
  return;