@openmrs/esm-patient-common-lib 6.1.1-pre.3577 → 6.1.1-pre.3580
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 +2 -2
- package/src/workspaces/workspaces.ts +69 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-patient-common-lib",
|
|
3
|
-
"version": "6.1.1-pre.
|
|
3
|
+
"version": "6.1.1-pre.3580",
|
|
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": "5.x"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "50d85ce8660de6b5cb3f7bfda2f362ac5f395d7a"
|
|
42
42
|
}
|
|
@@ -279,12 +279,6 @@ export function closeWorkspace(name: string, ignoreChanges: boolean) {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
|
|
282
|
-
export function closeAllWorkspaces() {
|
|
283
|
-
const store = getWorkspaceStore();
|
|
284
|
-
const state = store.getState();
|
|
285
|
-
store.setState({ ...state, openWorkspaces: [] });
|
|
286
|
-
}
|
|
287
|
-
|
|
288
282
|
/**
|
|
289
283
|
* The set of workspaces is specific to a particular patient. This function
|
|
290
284
|
* should be used when setting up workspaces for a new patient. If the current
|
|
@@ -317,6 +311,75 @@ export function updateWorkspaceWindowState(value: WorkspaceWindowState) {
|
|
|
317
311
|
function getUpdatedWorkspaceWindowState(workspaceAtTop: OpenWorkspace) {
|
|
318
312
|
return workspaceAtTop?.preferredWindowSize ?? 'normal';
|
|
319
313
|
}
|
|
314
|
+
export function closeAllWorkspaces(onClosingWorkspaces: () => void = () => {}) {
|
|
315
|
+
const store = getWorkspaceStore();
|
|
316
|
+
|
|
317
|
+
const canCloseAllWorkspaces = store.getState().openWorkspaces.every(({ name }) => {
|
|
318
|
+
const canCloseWorkspace = getWhetherWorkspaceCanBeClosed(name);
|
|
319
|
+
return canCloseWorkspace;
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
const updateWorkspaceStore = () => {
|
|
323
|
+
resetWorkspaceStore();
|
|
324
|
+
onClosingWorkspaces?.();
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
if (!canCloseAllWorkspaces) {
|
|
328
|
+
showWorkspacePrompts('closing-all-workspaces', updateWorkspaceStore);
|
|
329
|
+
} else {
|
|
330
|
+
updateWorkspaceStore();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function getWhetherWorkspaceCanBeClosed(name: string, ignoreChanges = false) {
|
|
335
|
+
const promptCheckFcn = getPromptBeforeClosingFcn(name);
|
|
336
|
+
return ignoreChanges || !promptCheckFcn || !promptCheckFcn();
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
type PromptType = 'closing-workspace' | 'closing-all-workspaces' | 'closing-workspace-launching-new-workspace';
|
|
340
|
+
|
|
341
|
+
export function showWorkspacePrompts(promptType: PromptType, onConfirmation: () => void = () => {}) {
|
|
342
|
+
const store = getWorkspaceStore();
|
|
343
|
+
|
|
344
|
+
switch (promptType) {
|
|
345
|
+
case 'closing-all-workspaces': {
|
|
346
|
+
const workspacesNotClosed = store
|
|
347
|
+
.getState()
|
|
348
|
+
.openWorkspaces.filter(({ name }) => !getWhetherWorkspaceCanBeClosed(name))
|
|
349
|
+
.map(({ title }, indx) => `${indx + 1}. ${title}`);
|
|
350
|
+
|
|
351
|
+
const prompt: Prompt = {
|
|
352
|
+
title: translateFrom('@openmrs/esm-patient-chart-app', 'unsavedChanges', 'You have unsaved changes'),
|
|
353
|
+
body: translateFrom(
|
|
354
|
+
'@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}}`,
|
|
357
|
+
{
|
|
358
|
+
workspaceNames: workspacesNotClosed.join(' '),
|
|
359
|
+
},
|
|
360
|
+
),
|
|
361
|
+
onConfirm: () => {
|
|
362
|
+
onConfirmation?.();
|
|
363
|
+
},
|
|
364
|
+
confirmText: translateFrom(
|
|
365
|
+
'@openmrs/esm-patient-chart-app',
|
|
366
|
+
'closeWorkspaces',
|
|
367
|
+
'Discard changes in {{count}} workspaces',
|
|
368
|
+
{ count: workspacesNotClosed.length },
|
|
369
|
+
),
|
|
370
|
+
};
|
|
371
|
+
store.setState((prevState) => ({
|
|
372
|
+
...prevState,
|
|
373
|
+
prompt,
|
|
374
|
+
}));
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
default: {
|
|
378
|
+
onConfirmation?.();
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
320
383
|
|
|
321
384
|
/**
|
|
322
385
|
* @internal
|