@openmrs/esm-styleguide 5.7.2 → 5.7.3-pre.2113
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/.turbo/turbo-build.log +8 -8
- package/dist/openmrs-esm-styleguide.css.map +1 -1
- package/dist/openmrs-esm-styleguide.js +1 -1
- package/dist/openmrs-esm-styleguide.js.map +1 -1
- package/package.json +9 -8
- package/src/icons/svgs/sticky-note-add.svg +2 -2
- package/src/modals/index.tsx +1 -2
- package/src/workspaces/action-menu-button/action-menu-button.module.scss +3 -4
- package/src/workspaces/container/action-menu.module.scss +1 -1
- package/src/workspaces/container/workspace-container.component.tsx +1 -1
- package/src/workspaces/container/workspace-container.test.tsx +3 -2
- package/src/workspaces/container/workspace-renderer.component.tsx +1 -1
- package/src/workspaces/index.ts +0 -1
- package/src/workspaces/notification/workspace-notification.component.tsx +3 -3
- package/src/workspaces/public.ts +7 -2
- package/src/workspaces/workspaces.test.ts +2 -9
- package/src/workspaces/workspaces.ts +71 -116
- package/src/modals/registry.ts +0 -48
- package/src/workspaces/types.ts +0 -70
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-styleguide",
|
|
3
|
-
"version": "5.7.
|
|
3
|
+
"version": "5.7.3-pre.2113",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "The styleguide for OpenMRS SPA",
|
|
6
6
|
"browser": "dist/openmrs-esm-styleguide.js",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"rxjs": "6.x"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@openmrs/esm-error-handling": "5.7.
|
|
68
|
-
"@openmrs/esm-extensions": "5.7.
|
|
69
|
-
"@openmrs/esm-navigation": "5.7.
|
|
70
|
-
"@openmrs/esm-react-utils": "5.7.
|
|
71
|
-
"@openmrs/esm-state": "5.7.
|
|
72
|
-
"@openmrs/esm-translations": "5.7.
|
|
67
|
+
"@openmrs/esm-error-handling": "5.7.3-pre.2113",
|
|
68
|
+
"@openmrs/esm-extensions": "5.7.3-pre.2113",
|
|
69
|
+
"@openmrs/esm-navigation": "5.7.3-pre.2113",
|
|
70
|
+
"@openmrs/esm-react-utils": "5.7.3-pre.2113",
|
|
71
|
+
"@openmrs/esm-state": "5.7.3-pre.2113",
|
|
72
|
+
"@openmrs/esm-translations": "5.7.3-pre.2113",
|
|
73
73
|
"@types/geopattern": "^1.2.9",
|
|
74
74
|
"autoprefixer": "^9.8.8",
|
|
75
75
|
"css-minimizer-webpack-plugin": "^1.2.0",
|
|
@@ -82,5 +82,6 @@
|
|
|
82
82
|
"rxjs": "^6.5.3",
|
|
83
83
|
"svgo-loader": "^4.0.0",
|
|
84
84
|
"webpack": "^5.88.0"
|
|
85
|
-
}
|
|
85
|
+
},
|
|
86
|
+
"stableVersion": "5.7.2"
|
|
86
87
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg">
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
<path d="M11.5 1H10.5V3H8.5V4H10.5V6H11.5V4H13.5V3H11.5V1Z" />
|
|
3
|
+
<path d="M7.5 1.99982H3.5C3.23502 2.0006 2.98112 2.10621 2.79375 2.29358C2.60638 2.48094 2.50078 2.73485 2.5 2.99982V12.9998C2.50078 13.2648 2.60638 13.5187 2.79375 13.7061C2.98112 13.8934 3.23502 13.999 3.5 13.9998H9.5C9.56572 14.0017 9.63106 13.9892 9.69149 13.9633C9.75192 13.9374 9.80601 13.8987 9.85 13.8498L13.35 10.3498C13.3989 10.3058 13.4376 10.2517 13.4635 10.1913C13.4894 10.1309 13.5018 10.0655 13.5 9.99982V7.00007H12.5V8.99982H9.5C9.23502 9.0006 8.98112 9.10621 8.79375 9.29358C8.60638 9.48094 8.50078 9.73485 8.5 9.99982V12.9998H3.5V2.99982H7.5V1.99982ZM12.3 9.99982L9.5 12.7998V9.99982H12.3Z" />
|
|
4
4
|
</svg>
|
package/src/modals/index.tsx
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/** @module @category UI */
|
|
2
2
|
import { mountRootParcel, type Parcel } from 'single-spa';
|
|
3
3
|
import { createGlobalStore } from '@openmrs/esm-state';
|
|
4
|
-
import { getModalRegistration } from '
|
|
4
|
+
import { getModalRegistration } from '@openmrs/esm-extensions';
|
|
5
5
|
import { reportError } from '@openmrs/esm-error-handling';
|
|
6
|
-
export * from './registry';
|
|
7
6
|
|
|
8
7
|
type ModalInstanceState = 'NEW' | 'MOUNTED' | 'TO_BE_DELETED';
|
|
9
8
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
@use '@carbon/styles/scss/spacing';
|
|
2
2
|
@use '@carbon/styles/scss/type';
|
|
3
|
-
@
|
|
3
|
+
@use '@openmrs/esm-styleguide/src/vars' as *;
|
|
4
4
|
|
|
5
5
|
.container {
|
|
6
6
|
margin-top: spacing.$spacing-02;
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
& > span {
|
|
22
22
|
margin-top: spacing.$spacing-02;
|
|
23
|
-
@include type.type-style(
|
|
23
|
+
@include type.type-style('body-compact-01');
|
|
24
24
|
color: $text-02;
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -78,7 +78,6 @@
|
|
|
78
78
|
|
|
79
79
|
/* Tablet */
|
|
80
80
|
:global(.omrs-breakpoint-lt-desktop) {
|
|
81
|
-
|
|
82
81
|
.container {
|
|
83
82
|
margin-bottom: 0;
|
|
84
83
|
margin-top: 0;
|
|
@@ -102,7 +101,7 @@
|
|
|
102
101
|
|
|
103
102
|
& > span {
|
|
104
103
|
color: $interactive-01;
|
|
105
|
-
@include type.type-style(
|
|
104
|
+
@include type.type-style('heading-compact-01');
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
svg {
|
|
@@ -7,8 +7,8 @@ import { getCoreTranslation, translateFrom } from '@openmrs/esm-translations';
|
|
|
7
7
|
|
|
8
8
|
import { ArrowLeftIcon, ArrowRightIcon, CloseIcon } from '../../icons';
|
|
9
9
|
import { WorkspaceNotification } from '../notification/workspace-notification.component';
|
|
10
|
-
import { type OpenWorkspace, updateWorkspaceWindowState, useWorkspaces } from '../workspaces';
|
|
11
10
|
import ActionMenu from './action-menu.component';
|
|
11
|
+
import { type OpenWorkspace, updateWorkspaceWindowState, useWorkspaces } from '../workspaces';
|
|
12
12
|
import { WorkspaceRenderer } from './workspace-renderer.component';
|
|
13
13
|
import styles from './workspace.module.scss';
|
|
14
14
|
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { screen, render, within, renderHook, act } from '@testing-library/react';
|
|
4
4
|
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import { registerWorkspace } from '@openmrs/esm-extensions';
|
|
5
6
|
import { ComponentContext, isDesktop, useLayoutType } from '@openmrs/esm-react-utils';
|
|
6
|
-
import { type DefaultWorkspaceProps, WorkspaceContainer, launchWorkspace,
|
|
7
|
+
import { type DefaultWorkspaceProps, WorkspaceContainer, launchWorkspace, useWorkspaces } from '..';
|
|
7
8
|
|
|
8
9
|
jest.mock('./workspace-renderer.component.tsx', () => {
|
|
9
10
|
return {
|
|
@@ -16,7 +17,7 @@ jest.mock('./workspace-renderer.component.tsx', () => {
|
|
|
16
17
|
};
|
|
17
18
|
});
|
|
18
19
|
|
|
19
|
-
const mockedIsDesktop = isDesktop as jest.Mock;
|
|
20
|
+
const mockedIsDesktop = isDesktop as unknown as jest.Mock;
|
|
20
21
|
const mockedUseLayoutType = useLayoutType as jest.Mock;
|
|
21
22
|
|
|
22
23
|
window.history.pushState({}, 'Workspace Container', '/workspace-container');
|
|
@@ -3,8 +3,8 @@ import { mountRootParcel, type ParcelConfig } from 'single-spa';
|
|
|
3
3
|
import Parcel from 'single-spa-react/parcel';
|
|
4
4
|
import { InlineLoading } from '@carbon/react';
|
|
5
5
|
import { getCoreTranslation } from '@openmrs/esm-translations';
|
|
6
|
-
import { type OpenWorkspace } from '../workspaces';
|
|
7
6
|
import styles from './workspace.module.scss';
|
|
7
|
+
import { type OpenWorkspace } from '../workspaces';
|
|
8
8
|
|
|
9
9
|
interface WorkspaceRendererProps {
|
|
10
10
|
workspace: OpenWorkspace;
|
package/src/workspaces/index.ts
CHANGED
|
@@ -2,5 +2,4 @@ export * from './action-menu-button/action-menu-button.component';
|
|
|
2
2
|
export * from './container/action-menu.component';
|
|
3
3
|
export * from './container/workspace-container.component';
|
|
4
4
|
export * from './notification/workspace-notification.component';
|
|
5
|
-
export * from './types';
|
|
6
5
|
export * from './workspaces';
|
|
@@ -4,17 +4,17 @@ import { useTranslation } from 'react-i18next';
|
|
|
4
4
|
import { Button, ComposedModal, ModalBody, ModalFooter, ModalHeader } from '@carbon/react';
|
|
5
5
|
import { navigate } from '@openmrs/esm-navigation';
|
|
6
6
|
import { reportError } from '@openmrs/esm-error-handling';
|
|
7
|
+
import { escapeRegExp } from 'lodash-es';
|
|
8
|
+
import { type SingleSpaCustomEventDetail } from 'single-spa';
|
|
7
9
|
import {
|
|
8
|
-
canCloseWorkspaceWithoutPrompting,
|
|
9
10
|
cancelPrompt,
|
|
11
|
+
canCloseWorkspaceWithoutPrompting,
|
|
10
12
|
changeWorkspaceContext,
|
|
11
13
|
closeAllWorkspaces,
|
|
12
14
|
getWorkspaceStore,
|
|
13
15
|
resetWorkspaceStore,
|
|
14
16
|
useWorkspaces,
|
|
15
17
|
} from '../workspaces';
|
|
16
|
-
import { escapeRegExp } from 'lodash-es';
|
|
17
|
-
import { type SingleSpaCustomEventDetail } from 'single-spa';
|
|
18
18
|
import styles from './workspace-notification.module.scss';
|
|
19
19
|
|
|
20
20
|
export interface WorkspaceNotificationProps {
|
package/src/workspaces/public.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export * from './action-menu-button/action-menu-button.component';
|
|
2
2
|
export * from './container/workspace-container.component';
|
|
3
|
-
export { type DefaultWorkspaceProps, type CloseWorkspaceOptions } from './types';
|
|
4
3
|
export { closeWorkspace, launchWorkspace, navigateAndLaunchWorkspace, useWorkspaces } from './workspaces';
|
|
5
|
-
export {
|
|
4
|
+
export {
|
|
5
|
+
type DefaultWorkspaceProps,
|
|
6
|
+
type CloseWorkspaceOptions,
|
|
7
|
+
type OpenWorkspace,
|
|
8
|
+
type WorkspacesInfo,
|
|
9
|
+
type Prompt,
|
|
10
|
+
} from './workspaces';
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
cancelPrompt,
|
|
4
|
-
getWorkspaceStore,
|
|
5
|
-
launchWorkspace,
|
|
6
|
-
registerWorkspace,
|
|
7
|
-
resetWorkspaceStore,
|
|
8
|
-
} from './workspaces';
|
|
9
|
-
import { registerExtension } from '@openmrs/esm-extensions';
|
|
1
|
+
import { type Prompt, cancelPrompt, getWorkspaceStore, launchWorkspace, resetWorkspaceStore } from './workspaces';
|
|
2
|
+
import { registerExtension, registerWorkspace } from '@openmrs/esm-extensions';
|
|
10
3
|
import { clearMockExtensionRegistry } from '@openmrs/esm-framework/mock';
|
|
11
4
|
|
|
12
5
|
describe('workspace system', () => {
|
|
@@ -1,14 +1,80 @@
|
|
|
1
1
|
/** @module @category Workspace */
|
|
2
|
-
import { type ReactNode
|
|
3
|
-
import { type LifeCycles } from 'single-spa';
|
|
2
|
+
import { useMemo, type ReactNode } from 'react';
|
|
4
3
|
import _i18n from 'i18next';
|
|
5
|
-
import { type
|
|
4
|
+
import { getWorkspaceRegistration, type WorkspaceRegistration } from '@openmrs/esm-extensions';
|
|
6
5
|
import { type WorkspaceWindowState } from '@openmrs/esm-globals';
|
|
7
|
-
import { useStore } from '@openmrs/esm-react-utils';
|
|
8
6
|
import { navigate } from '@openmrs/esm-navigation';
|
|
9
7
|
import { getGlobalStore, createGlobalStore } from '@openmrs/esm-state';
|
|
10
8
|
import { getCoreTranslation, translateFrom } from '@openmrs/esm-translations';
|
|
11
|
-
import {
|
|
9
|
+
import { useStore } from '@openmrs/esm-react-utils';
|
|
10
|
+
|
|
11
|
+
export interface CloseWorkspaceOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Whether to close the workspace ignoring all the changes present in the workspace.
|
|
14
|
+
*
|
|
15
|
+
* If ignoreChanges is true, the user will not be prompted to save changes before closing
|
|
16
|
+
* even if the `testFcn` passed to `promptBeforeClosing` returns `true`.
|
|
17
|
+
*/
|
|
18
|
+
ignoreChanges?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* If you want to take an action after the workspace is closed, you can pass your function as
|
|
21
|
+
* `onWorkspaceClose`. This function will be called only after the workspace is closed, given
|
|
22
|
+
* that the user might be shown a prompt.
|
|
23
|
+
* @returns void
|
|
24
|
+
*/
|
|
25
|
+
onWorkspaceClose?: () => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The default parameters received by all workspaces */
|
|
29
|
+
export interface DefaultWorkspaceProps {
|
|
30
|
+
/**
|
|
31
|
+
* Call this function to close the workspace. This function will prompt the user
|
|
32
|
+
* if there are any unsaved changes to workspace.
|
|
33
|
+
*
|
|
34
|
+
* You can pass `onWorkspaceClose` function to be called when the workspace is finally
|
|
35
|
+
* closed, given the user forcefully closes the workspace.
|
|
36
|
+
*/
|
|
37
|
+
closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
|
|
38
|
+
/**
|
|
39
|
+
* Call this with a no-args function that returns true if the user should be prompted before
|
|
40
|
+
* this workspace is closed; e.g. if there is unsaved data.
|
|
41
|
+
*/
|
|
42
|
+
promptBeforeClosing(testFcn: () => boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Call this function to close the workspace after the form is saved. This function
|
|
45
|
+
* will directly close the workspace without any prompt
|
|
46
|
+
*/
|
|
47
|
+
closeWorkspaceWithSavedChanges(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
|
|
48
|
+
/**
|
|
49
|
+
* Use this to set the workspace title if it needs to be set dynamically.
|
|
50
|
+
*
|
|
51
|
+
* Workspace titles generally are set in the workspace declaration in the routes.json file. They can also
|
|
52
|
+
* be set by the workspace launcher by passing `workspaceTitle` in the `additionalProps`
|
|
53
|
+
* parameter of the `launchWorkspace` function. This function is useful when the workspace
|
|
54
|
+
* title needs to be set dynamically.
|
|
55
|
+
*
|
|
56
|
+
* @param title The title to set. If using titleNode, set this to a human-readable string
|
|
57
|
+
* which will identify the workspace in notifications and other places.
|
|
58
|
+
* @param titleNode A React object to put in the workspace header in place of the title. This
|
|
59
|
+
* is useful for displaying custom elements in the header. Note that custom header
|
|
60
|
+
* elements can also be attached to the workspace header extension slots.
|
|
61
|
+
*/
|
|
62
|
+
setTitle(title: string, titleNode?: ReactNode): void;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface WorkspaceWindowSize {
|
|
66
|
+
size: WorkspaceWindowState;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface WorkspaceWindowSizeProviderProps {
|
|
70
|
+
children?: React.ReactNode;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface WorkspaceWindowSizeContext {
|
|
74
|
+
windowSize: WorkspaceWindowSize;
|
|
75
|
+
updateWindowSize?(value: WorkspaceWindowState): any;
|
|
76
|
+
active: boolean;
|
|
77
|
+
}
|
|
12
78
|
|
|
13
79
|
export interface Prompt {
|
|
14
80
|
title: string;
|
|
@@ -27,121 +93,10 @@ export interface WorkspaceStoreState {
|
|
|
27
93
|
workspaceWindowState: WorkspaceWindowState;
|
|
28
94
|
}
|
|
29
95
|
|
|
30
|
-
/** See [[WorkspaceDefinition]] for more information about these properties */
|
|
31
|
-
export interface WorkspaceRegistration {
|
|
32
|
-
name: string;
|
|
33
|
-
title: string;
|
|
34
|
-
titleNode?: ReactNode;
|
|
35
|
-
type: string;
|
|
36
|
-
canHide: boolean;
|
|
37
|
-
canMaximize: boolean;
|
|
38
|
-
width: 'narrow' | 'wider' | 'extra-wide';
|
|
39
|
-
hasOwnSidebar: boolean;
|
|
40
|
-
sidebarFamily: string;
|
|
41
|
-
preferredWindowSize: WorkspaceWindowState;
|
|
42
|
-
load: () => Promise<{ default?: LifeCycles } & LifeCycles>;
|
|
43
|
-
moduleName: string;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
96
|
export interface OpenWorkspace extends WorkspaceRegistration, DefaultWorkspaceProps {
|
|
47
97
|
additionalProps: object;
|
|
48
98
|
}
|
|
49
99
|
|
|
50
|
-
interface WorkspaceRegistrationStore {
|
|
51
|
-
workspaces: Record<string, WorkspaceRegistration>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const workspaceRegistrationStore = createGlobalStore<WorkspaceRegistrationStore>('workspaceRegistrations', {
|
|
55
|
-
workspaces: {},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
/** See [[WorkspaceDefinition]] for more information about these properties */
|
|
59
|
-
export interface RegisterWorkspaceOptions {
|
|
60
|
-
name: string;
|
|
61
|
-
title: string;
|
|
62
|
-
type?: string;
|
|
63
|
-
canHide?: boolean;
|
|
64
|
-
canMaximize?: boolean;
|
|
65
|
-
width?: 'narrow' | 'wider' | 'extra-wide';
|
|
66
|
-
hasOwnSidebar?: boolean;
|
|
67
|
-
sidebarFamily?: string;
|
|
68
|
-
preferredWindowSize?: WorkspaceWindowState;
|
|
69
|
-
load: () => Promise<{ default?: LifeCycles } & LifeCycles>;
|
|
70
|
-
moduleName: string;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Tells the workspace system about a workspace. This is used by the app shell
|
|
75
|
-
* to register workspaces defined in the `routes.json` file.
|
|
76
|
-
* @internal
|
|
77
|
-
*/
|
|
78
|
-
export function registerWorkspace(workspace: RegisterWorkspaceOptions) {
|
|
79
|
-
workspaceRegistrationStore.setState((state) => ({
|
|
80
|
-
workspaces: {
|
|
81
|
-
...state.workspaces,
|
|
82
|
-
[workspace.name]: {
|
|
83
|
-
...workspace,
|
|
84
|
-
preferredWindowSize: workspace.preferredWindowSize ?? 'normal',
|
|
85
|
-
type: workspace.type ?? 'form',
|
|
86
|
-
canHide: workspace.canHide ?? false,
|
|
87
|
-
canMaximize: workspace.canMaximize ?? false,
|
|
88
|
-
width: workspace.width ?? 'narrow',
|
|
89
|
-
hasOwnSidebar: workspace.hasOwnSidebar ?? false,
|
|
90
|
-
sidebarFamily: workspace.sidebarFamily ?? 'default',
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const workspaceExtensionWarningsIssued = new Set();
|
|
97
|
-
/**
|
|
98
|
-
* This exists for compatibility with the old way of registering
|
|
99
|
-
* workspaces (as extensions).
|
|
100
|
-
*
|
|
101
|
-
* @param name of the workspace
|
|
102
|
-
*/
|
|
103
|
-
function getWorkspaceRegistration(name: string): WorkspaceRegistration {
|
|
104
|
-
const registeredWorkspaces = workspaceRegistrationStore.getState().workspaces;
|
|
105
|
-
if (registeredWorkspaces[name]) {
|
|
106
|
-
return registeredWorkspaces[name];
|
|
107
|
-
} else {
|
|
108
|
-
const workspaceExtension = getExtensionRegistration(name);
|
|
109
|
-
if (workspaceExtension) {
|
|
110
|
-
if (!workspaceExtensionWarningsIssued.has(name)) {
|
|
111
|
-
console.warn(
|
|
112
|
-
`The workspace '${name}' is registered as an extension. This is deprecated. Please register it in the "workspaces" section of the routes.json file.`,
|
|
113
|
-
);
|
|
114
|
-
workspaceExtensionWarningsIssued.add(name);
|
|
115
|
-
}
|
|
116
|
-
return {
|
|
117
|
-
name: workspaceExtension.name,
|
|
118
|
-
title: getTitleFromExtension(workspaceExtension),
|
|
119
|
-
moduleName: workspaceExtension.moduleName,
|
|
120
|
-
preferredWindowSize: workspaceExtension.meta?.screenSize ?? 'normal',
|
|
121
|
-
load: workspaceExtension.load,
|
|
122
|
-
type: workspaceExtension.meta?.type ?? 'form',
|
|
123
|
-
canHide: workspaceExtension.meta?.canHide ?? false,
|
|
124
|
-
canMaximize: workspaceExtension.meta?.canMaximize ?? false,
|
|
125
|
-
width: workspaceExtension.meta?.width ?? 'narrow',
|
|
126
|
-
sidebarFamily: 'default',
|
|
127
|
-
hasOwnSidebar: false,
|
|
128
|
-
};
|
|
129
|
-
} else {
|
|
130
|
-
throw new Error(`No workspace named '${name}' has been registered.`);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function getTitleFromExtension(ext: ExtensionRegistration) {
|
|
136
|
-
const title = ext?.meta?.title;
|
|
137
|
-
if (typeof title === 'string') {
|
|
138
|
-
return title;
|
|
139
|
-
} else if (title && typeof title === 'object') {
|
|
140
|
-
return translateFrom(ext.moduleName, title.key, title.default);
|
|
141
|
-
}
|
|
142
|
-
return ext.name;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
100
|
/**
|
|
146
101
|
*
|
|
147
102
|
* @param name Name of the workspace
|
package/src/modals/registry.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { getExtensionRegistration } from '@openmrs/esm-extensions';
|
|
2
|
-
import { createGlobalStore } from '@openmrs/esm-state';
|
|
3
|
-
import type { LifeCycles } from 'single-spa';
|
|
4
|
-
|
|
5
|
-
/** @internal */
|
|
6
|
-
export interface ModalRegistration {
|
|
7
|
-
name: string;
|
|
8
|
-
load(): Promise<{ default?: LifeCycles } & LifeCycles>;
|
|
9
|
-
moduleName: string;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
interface ModalRegistry {
|
|
13
|
-
/** Modals indexed by name */
|
|
14
|
-
modals: Record<string, ModalRegistration>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const modalRegistryStore = createGlobalStore<ModalRegistry>('modalRegistry', {
|
|
18
|
-
modals: {},
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
/** @internal */
|
|
22
|
-
export function registerModal(modalRegistration: ModalRegistration) {
|
|
23
|
-
modalRegistryStore.setState((state) => {
|
|
24
|
-
state.modals[modalRegistration.name] = modalRegistration;
|
|
25
|
-
return state;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** @internal */
|
|
30
|
-
export function getModalRegistration(modalName: string): ModalRegistration | undefined {
|
|
31
|
-
let modalRegistration = modalRegistryStore.getState().modals[modalName];
|
|
32
|
-
if (!modalRegistration) {
|
|
33
|
-
const extensionRegistration = getExtensionRegistration(modalName);
|
|
34
|
-
if (extensionRegistration) {
|
|
35
|
-
modalRegistration = {
|
|
36
|
-
name: modalName,
|
|
37
|
-
load: extensionRegistration.load,
|
|
38
|
-
moduleName: extensionRegistration.moduleName,
|
|
39
|
-
};
|
|
40
|
-
console.warn(
|
|
41
|
-
`Modal ${modalName} was registered as an extension. This is deprecated and will be removed in the future. Please register it in the "modals" section of routes.json instead of the "extensions" section.`,
|
|
42
|
-
);
|
|
43
|
-
// Register it so the warning only appears once
|
|
44
|
-
registerModal(modalRegistration);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return modalRegistration;
|
|
48
|
-
}
|
package/src/workspaces/types.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { type WorkspaceWindowState } from '@openmrs/esm-globals';
|
|
2
|
-
import { type ReactNode } from 'react';
|
|
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
|
-
|
|
21
|
-
/** The default parameters received by all workspaces */
|
|
22
|
-
export interface DefaultWorkspaceProps {
|
|
23
|
-
/**
|
|
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.
|
|
29
|
-
*/
|
|
30
|
-
closeWorkspace(closeWorkspaceOptions?: CloseWorkspaceOptions): void;
|
|
31
|
-
/**
|
|
32
|
-
* Call this with a no-args function that returns true if the user should be prompted before
|
|
33
|
-
* this workspace is closed; e.g. if there is unsaved data.
|
|
34
|
-
*/
|
|
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;
|
|
41
|
-
/**
|
|
42
|
-
* Use this to set the workspace title if it needs to be set dynamically.
|
|
43
|
-
*
|
|
44
|
-
* Workspace titles generally are set in the workspace declaration in the routes.json file. They can also
|
|
45
|
-
* be set by the workspace launcher by passing `workspaceTitle` in the `additionalProps`
|
|
46
|
-
* parameter of the `launchWorkspace` function. This function is useful when the workspace
|
|
47
|
-
* title needs to be set dynamically.
|
|
48
|
-
*
|
|
49
|
-
* @param title The title to set. If using titleNode, set this to a human-readable string
|
|
50
|
-
* which will identify the workspace in notifications and other places.
|
|
51
|
-
* @param titleNode A React object to put in the workspace header in place of the title. This
|
|
52
|
-
* is useful for displaying custom elements in the header. Note that custom header
|
|
53
|
-
* elements can also be attached to the workspace header extension slots.
|
|
54
|
-
*/
|
|
55
|
-
setTitle(title: string, titleNode?: ReactNode): void;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export interface WorkspaceWindowSize {
|
|
59
|
-
size: WorkspaceWindowState;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface WorkspaceWindowSizeProviderProps {
|
|
63
|
-
children?: React.ReactNode;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface WorkspaceWindowSizeContext {
|
|
67
|
-
windowSize: WorkspaceWindowSize;
|
|
68
|
-
updateWindowSize?(value: WorkspaceWindowState): any;
|
|
69
|
-
active: boolean;
|
|
70
|
-
}
|