@openmrs/esm-extensions 6.0.3-pre.2631 → 6.0.3-pre.2634
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-extensions",
|
|
3
|
-
"version": "6.0.3-pre.
|
|
3
|
+
"version": "6.0.3-pre.2634",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Coordinates extensions and extension points in the OpenMRS Frontend",
|
|
6
6
|
"browser": "dist/openmrs-esm-extensions.js",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
"single-spa": "6.x"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@openmrs/esm-api": "6.0.3-pre.
|
|
51
|
-
"@openmrs/esm-config": "6.0.3-pre.
|
|
52
|
-
"@openmrs/esm-expression-evaluator": "6.0.3-pre.
|
|
53
|
-
"@openmrs/esm-feature-flags": "6.0.3-pre.
|
|
54
|
-
"@openmrs/esm-state": "6.0.3-pre.
|
|
55
|
-
"@openmrs/esm-utils": "6.0.3-pre.
|
|
50
|
+
"@openmrs/esm-api": "6.0.3-pre.2634",
|
|
51
|
+
"@openmrs/esm-config": "6.0.3-pre.2634",
|
|
52
|
+
"@openmrs/esm-expression-evaluator": "6.0.3-pre.2634",
|
|
53
|
+
"@openmrs/esm-feature-flags": "6.0.3-pre.2634",
|
|
54
|
+
"@openmrs/esm-state": "6.0.3-pre.2634",
|
|
55
|
+
"@openmrs/esm-utils": "6.0.3-pre.2634",
|
|
56
56
|
"single-spa": "^6.0.1"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
package/src/workspaces.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type LifeCycles } from 'single-spa';
|
|
3
|
-
import { type WorkspaceWindowState } from '@openmrs/esm-globals';
|
|
3
|
+
import { type WorkspaceGroupDefinition, type WorkspaceWindowState } from '@openmrs/esm-globals';
|
|
4
4
|
import { type ExtensionRegistration, getExtensionRegistration } from '.';
|
|
5
5
|
import { createGlobalStore } from '@openmrs/esm-state';
|
|
6
6
|
import { translateFrom } from '@openmrs/esm-translations';
|
|
@@ -17,9 +17,13 @@ export interface WorkspaceRegistration {
|
|
|
17
17
|
preferredWindowSize: WorkspaceWindowState;
|
|
18
18
|
load: () => Promise<{ default?: LifeCycles } & LifeCycles>;
|
|
19
19
|
moduleName: string;
|
|
20
|
-
groups
|
|
20
|
+
groups: Array<string>;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export type WorkspaceGroupRegistration = WorkspaceGroupDefinition & {
|
|
24
|
+
members: Array<string>;
|
|
25
|
+
};
|
|
26
|
+
|
|
23
27
|
interface WorkspaceRegistrationStore {
|
|
24
28
|
workspaces: Record<string, WorkspaceRegistration>;
|
|
25
29
|
}
|
|
@@ -28,6 +32,14 @@ const workspaceRegistrationStore = createGlobalStore<WorkspaceRegistrationStore>
|
|
|
28
32
|
workspaces: {},
|
|
29
33
|
});
|
|
30
34
|
|
|
35
|
+
interface WorkspaceGroupRegistrationStore {
|
|
36
|
+
workspaceGroups: Record<string, { name: string; members: Array<string> }>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const workspaceGroupStore = createGlobalStore<WorkspaceGroupRegistrationStore>('workspaceGroups', {
|
|
40
|
+
workspaceGroups: {},
|
|
41
|
+
});
|
|
42
|
+
|
|
31
43
|
/** See [[WorkspaceDefinition]] for more information about these properties */
|
|
32
44
|
export interface RegisterWorkspaceOptions {
|
|
33
45
|
name: string;
|
|
@@ -64,6 +76,23 @@ export function registerWorkspace(workspace: RegisterWorkspaceOptions) {
|
|
|
64
76
|
}));
|
|
65
77
|
}
|
|
66
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Tells the workspace system about a workspace group. This is used by the app shell
|
|
81
|
+
* to register workspace groups defined in the `routes.json` file.
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export function registerWorkspaceGroup(workspaceGroup: WorkspaceGroupRegistration) {
|
|
85
|
+
workspaceGroupStore.setState((state) => ({
|
|
86
|
+
workspaceGroups: {
|
|
87
|
+
...state.workspaceGroups,
|
|
88
|
+
[workspaceGroup.name]: {
|
|
89
|
+
name: workspaceGroup.name,
|
|
90
|
+
members: workspaceGroup.members,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
|
|
67
96
|
const workspaceExtensionWarningsIssued = new Set();
|
|
68
97
|
/**
|
|
69
98
|
* This exists for compatibility with the old way of registering
|
|
@@ -94,7 +123,7 @@ export function getWorkspaceRegistration(name: string): WorkspaceRegistration {
|
|
|
94
123
|
canHide: workspaceExtension.meta?.canHide ?? false,
|
|
95
124
|
canMaximize: workspaceExtension.meta?.canMaximize ?? false,
|
|
96
125
|
width: workspaceExtension.meta?.width ?? 'narrow',
|
|
97
|
-
groups: workspaceExtension
|
|
126
|
+
groups: workspaceExtension.meta?.groups ?? [],
|
|
98
127
|
};
|
|
99
128
|
} else {
|
|
100
129
|
throw new Error(`No workspace named '${name}' has been registered.`);
|
|
@@ -102,6 +131,21 @@ export function getWorkspaceRegistration(name: string): WorkspaceRegistration {
|
|
|
102
131
|
}
|
|
103
132
|
}
|
|
104
133
|
|
|
134
|
+
/**
|
|
135
|
+
* This provides the workspace group registration and is also compatibile with the
|
|
136
|
+
* old way of registering workspace groups (as extensions), but isn't recommended.
|
|
137
|
+
*
|
|
138
|
+
* @param name of the workspace
|
|
139
|
+
*/
|
|
140
|
+
export function getWorkspaceGroupRegistration(name: string): WorkspaceGroupRegistration {
|
|
141
|
+
const registeredWorkspaces = workspaceGroupStore.getState().workspaceGroups;
|
|
142
|
+
if (registeredWorkspaces[name]) {
|
|
143
|
+
return registeredWorkspaces[name];
|
|
144
|
+
} else {
|
|
145
|
+
throw new Error(`No workspace group named '${name}' has been registered.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
105
149
|
function getTitleFromExtension(ext: ExtensionRegistration) {
|
|
106
150
|
const title = ext?.meta?.title;
|
|
107
151
|
if (typeof title === 'string') {
|
|
@@ -111,3 +155,37 @@ function getTitleFromExtension(ext: ExtensionRegistration) {
|
|
|
111
155
|
}
|
|
112
156
|
return ext.name;
|
|
113
157
|
}
|
|
158
|
+
|
|
159
|
+
function createNewWorkspaceGroupInfo(groupName: string): WorkspaceGroupRegistration {
|
|
160
|
+
return {
|
|
161
|
+
name: groupName,
|
|
162
|
+
members: [],
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export function attachWorkspaceToGroup(workspaceName: string, groupName: string) {
|
|
167
|
+
workspaceGroupStore.setState((state) => {
|
|
168
|
+
const group = state.workspaceGroups[groupName];
|
|
169
|
+
if (group) {
|
|
170
|
+
return {
|
|
171
|
+
workspaceGroups: {
|
|
172
|
+
...state.workspaceGroups,
|
|
173
|
+
[groupName]: {
|
|
174
|
+
...group,
|
|
175
|
+
members: [...group.members, workspaceName],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
} else {
|
|
180
|
+
return {
|
|
181
|
+
workspaceGroups: {
|
|
182
|
+
...state.workspaceGroups,
|
|
183
|
+
[groupName]: {
|
|
184
|
+
...createNewWorkspaceGroupInfo(groupName),
|
|
185
|
+
members: [workspaceName],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|