@openmrs/esm-framework 3.4.1-pre.146 → 3.4.1-pre.149
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 +10 -10
- package/dist/openmrs-esm-framework.js +1 -1
- package/dist/openmrs-esm-framework.js.map +1 -1
- package/docs/API.md +39 -34
- package/docs/interfaces/AssignedExtension.md +7 -7
- package/docs/interfaces/ComponentDefinition.md +5 -4
- package/docs/interfaces/ConfigObject.md +11 -0
- package/docs/interfaces/ConnectedExtension.md +4 -4
- package/docs/interfaces/DisplayConditionsConfigObject.md +19 -0
- package/docs/interfaces/ExtensionDefinition.md +11 -10
- package/docs/interfaces/ExtensionRegistration.md +11 -0
- package/docs/interfaces/ExtensionSlotConfig.md +4 -4
- package/docs/interfaces/ExtensionSlotConfigObject.md +3 -3
- package/docs/interfaces/ExtensionSlotState.md +2 -2
- package/docs/interfaces/ExtensionStore.md +1 -1
- package/docs/interfaces/PageDefinition.md +7 -6
- package/docs/interfaces/UserHasAccessProps.md +1 -1
- package/mock.tsx +2 -1
- package/package.json +13 -13
- package/src/integration-tests/extension-config.test.tsx +173 -4
|
@@ -82,15 +82,16 @@ The order in which to load the page. This determines DOM order.
|
|
|
82
82
|
|
|
83
83
|
#### Defined in
|
|
84
84
|
|
|
85
|
-
[packages/framework/esm-globals/src/types.ts:
|
|
85
|
+
[packages/framework/esm-globals/src/types.ts:146](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-globals/src/types.ts#L146)
|
|
86
86
|
|
|
87
87
|
___
|
|
88
88
|
|
|
89
89
|
### privilege
|
|
90
90
|
|
|
91
|
-
• `Optional` **privilege**: `string`
|
|
91
|
+
• `Optional` **privilege**: `string` \| `string`[]
|
|
92
92
|
|
|
93
|
-
Defines the access privilege required for this component, if any.
|
|
93
|
+
Defines the access privilege(s) required for this component, if any.
|
|
94
|
+
If more than one privilege is provided, the user must have all specified permissions.
|
|
94
95
|
|
|
95
96
|
#### Inherited from
|
|
96
97
|
|
|
@@ -98,7 +99,7 @@ Defines the access privilege required for this component, if any.
|
|
|
98
99
|
|
|
99
100
|
#### Defined in
|
|
100
101
|
|
|
101
|
-
[packages/framework/esm-globals/src/types.ts:
|
|
102
|
+
[packages/framework/esm-globals/src/types.ts:116](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-globals/src/types.ts#L116)
|
|
102
103
|
|
|
103
104
|
___
|
|
104
105
|
|
|
@@ -114,7 +115,7 @@ Defines resources that are loaded when the component should mount.
|
|
|
114
115
|
|
|
115
116
|
#### Defined in
|
|
116
117
|
|
|
117
|
-
[packages/framework/esm-globals/src/types.ts:
|
|
118
|
+
[packages/framework/esm-globals/src/types.ts:120](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-globals/src/types.ts#L120)
|
|
118
119
|
|
|
119
120
|
___
|
|
120
121
|
|
|
@@ -126,7 +127,7 @@ The route of the page.
|
|
|
126
127
|
|
|
127
128
|
#### Defined in
|
|
128
129
|
|
|
129
|
-
[packages/framework/esm-globals/src/types.ts:
|
|
130
|
+
[packages/framework/esm-globals/src/types.ts:142](https://github.com/openmrs/openmrs-esm-core/blob/master/packages/framework/esm-globals/src/types.ts#L142)
|
|
130
131
|
|
|
131
132
|
## Methods
|
|
132
133
|
|
package/mock.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import type {} from "@openmrs/esm-globals";
|
|
|
3
3
|
import createStore, { Store } from "unistore";
|
|
4
4
|
import { never, of } from "rxjs";
|
|
5
5
|
import { interpolateUrl } from "@openmrs/esm-config";
|
|
6
|
+
import { SessionStore } from "@openmrs/esm-api";
|
|
6
7
|
export {
|
|
7
8
|
parseDate,
|
|
8
9
|
formatDate,
|
|
@@ -51,7 +52,7 @@ export function getCurrentUser() {
|
|
|
51
52
|
return of({ authenticated: false });
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
export const mockSessionStore = createGlobalStore("mock-session-store", {
|
|
55
|
+
export const mockSessionStore = createGlobalStore<SessionStore>("mock-session-store", {
|
|
55
56
|
loaded: false,
|
|
56
57
|
session: null,
|
|
57
58
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openmrs/esm-framework",
|
|
3
|
-
"version": "3.4.1-pre.
|
|
3
|
+
"version": "3.4.1-pre.149",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"browser": "dist/openmrs-esm-framework.js",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -35,18 +35,18 @@
|
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@openmrs/esm-api": "^3.4.1-pre.
|
|
39
|
-
"@openmrs/esm-breadcrumbs": "^3.4.1-pre.
|
|
40
|
-
"@openmrs/esm-config": "^3.4.1-pre.
|
|
41
|
-
"@openmrs/esm-error-handling": "^3.4.1-pre.
|
|
42
|
-
"@openmrs/esm-extensions": "^3.4.1-pre.
|
|
43
|
-
"@openmrs/esm-globals": "^3.4.1-pre.
|
|
44
|
-
"@openmrs/esm-offline": "^3.4.1-pre.
|
|
45
|
-
"@openmrs/esm-react-utils": "^3.4.1-pre.
|
|
46
|
-
"@openmrs/esm-state": "^3.4.1-pre.
|
|
47
|
-
"@openmrs/esm-styleguide": "^3.4.1-pre.
|
|
48
|
-
"@openmrs/esm-utils": "^3.4.1-pre.
|
|
38
|
+
"@openmrs/esm-api": "^3.4.1-pre.149",
|
|
39
|
+
"@openmrs/esm-breadcrumbs": "^3.4.1-pre.149",
|
|
40
|
+
"@openmrs/esm-config": "^3.4.1-pre.149",
|
|
41
|
+
"@openmrs/esm-error-handling": "^3.4.1-pre.149",
|
|
42
|
+
"@openmrs/esm-extensions": "^3.4.1-pre.149",
|
|
43
|
+
"@openmrs/esm-globals": "^3.4.1-pre.149",
|
|
44
|
+
"@openmrs/esm-offline": "^3.4.1-pre.149",
|
|
45
|
+
"@openmrs/esm-react-utils": "^3.4.1-pre.149",
|
|
46
|
+
"@openmrs/esm-state": "^3.4.1-pre.149",
|
|
47
|
+
"@openmrs/esm-styleguide": "^3.4.1-pre.149",
|
|
48
|
+
"@openmrs/esm-utils": "^3.4.1-pre.149",
|
|
49
49
|
"dayjs": "^1.10.7"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "b6c06cecaa56b82534d0478fc565c6a4968991fd"
|
|
52
52
|
}
|
|
@@ -3,8 +3,6 @@ import {
|
|
|
3
3
|
attach,
|
|
4
4
|
registerExtension,
|
|
5
5
|
updateInternalExtensionStore,
|
|
6
|
-
getExtensionInternalStore,
|
|
7
|
-
getExtensionStore,
|
|
8
6
|
} from "../../../esm-extensions";
|
|
9
7
|
import {
|
|
10
8
|
ExtensionSlot,
|
|
@@ -22,7 +20,17 @@ import {
|
|
|
22
20
|
getExtensionSlotsConfigStore,
|
|
23
21
|
} from "../../../esm-config/src";
|
|
24
22
|
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
25
|
-
import {
|
|
23
|
+
import { Person } from "@openmrs/esm-api";
|
|
24
|
+
import { mockSessionStore } from "../../mock";
|
|
25
|
+
|
|
26
|
+
jest.mock("@openmrs/esm-api", () => {
|
|
27
|
+
const original = jest.requireActual("@openmrs/esm-api");
|
|
28
|
+
return {
|
|
29
|
+
...original,
|
|
30
|
+
getSessionStore: () => mockSessionStore,
|
|
31
|
+
refetchCurrentUser: jest.fn(),
|
|
32
|
+
};
|
|
33
|
+
});
|
|
26
34
|
|
|
27
35
|
describe("Interaction between configuration and extension systems", () => {
|
|
28
36
|
beforeEach(() => {
|
|
@@ -244,12 +252,172 @@ describe("Interaction between configuration and extension systems", () => {
|
|
|
244
252
|
});
|
|
245
253
|
expect(screen.getByText(/clothes/)).toHaveTextContent(/tiger/);
|
|
246
254
|
});
|
|
255
|
+
|
|
256
|
+
test("should not show extension when user lacks configured privilege", async () => {
|
|
257
|
+
mockSessionStore.setState({
|
|
258
|
+
loaded: true,
|
|
259
|
+
session: {
|
|
260
|
+
authenticated: true,
|
|
261
|
+
sessionId: "1",
|
|
262
|
+
user: {
|
|
263
|
+
uuid: "1",
|
|
264
|
+
display: "Non-Admin",
|
|
265
|
+
username: "nonadmin",
|
|
266
|
+
systemId: "nonadmin",
|
|
267
|
+
userProperties: {},
|
|
268
|
+
person: {} as Person,
|
|
269
|
+
privileges: [],
|
|
270
|
+
roles: [],
|
|
271
|
+
retired: false,
|
|
272
|
+
locale: "en",
|
|
273
|
+
allowedLocales: ["en"],
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
registerSimpleExtension("Schmoo", "esm-bedrock", true);
|
|
279
|
+
registerSimpleExtension("Wilma", "esm-flintstones", true);
|
|
280
|
+
attach("A slot", "Schmoo");
|
|
281
|
+
attach("A slot", "Wilma");
|
|
282
|
+
defineConfigSchema("esm-bedrock", {});
|
|
283
|
+
defineConfigSchema("esm-flintstones", {});
|
|
284
|
+
provide({
|
|
285
|
+
"esm-bedrock": {
|
|
286
|
+
"Display conditions": {
|
|
287
|
+
privileges: ["Yabadabadoo!"],
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
});
|
|
291
|
+
provide({
|
|
292
|
+
"esm-flintstones": {},
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
function RootComponent() {
|
|
296
|
+
return (
|
|
297
|
+
<div>
|
|
298
|
+
<ExtensionSlot data-testid="slot" extensionSlotName="A slot" />
|
|
299
|
+
</div>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
const App = openmrsComponentDecorator({
|
|
303
|
+
moduleName: "esm-bedrock",
|
|
304
|
+
featureName: "Bedrock",
|
|
305
|
+
disableTranslations: true,
|
|
306
|
+
})(RootComponent);
|
|
307
|
+
|
|
308
|
+
render(<App />);
|
|
309
|
+
await waitFor(() => expect(screen.getByTestId(/slot/)).toBeInTheDocument());
|
|
310
|
+
expect(screen.getByText(/\bWilma\b/)).toBeVisible();
|
|
311
|
+
expect(screen.queryAllByText(/\bSchmoo\b/)).toHaveLength(0);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
test("should show extension when user has configured privilege", async () => {
|
|
315
|
+
mockSessionStore.setState({
|
|
316
|
+
loaded: true,
|
|
317
|
+
session: {
|
|
318
|
+
authenticated: true,
|
|
319
|
+
sessionId: "1",
|
|
320
|
+
user: {
|
|
321
|
+
uuid: "1",
|
|
322
|
+
display: "Non-Admin",
|
|
323
|
+
username: "nonadmin",
|
|
324
|
+
systemId: "nonadmin",
|
|
325
|
+
userProperties: {},
|
|
326
|
+
person: {} as Person,
|
|
327
|
+
privileges: [{ uuid: "1", display: "Yabadabadoo!" }],
|
|
328
|
+
roles: [],
|
|
329
|
+
retired: false,
|
|
330
|
+
locale: "en",
|
|
331
|
+
allowedLocales: ["en"],
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
registerSimpleExtension("Schmoo", "esm-bedrock", true);
|
|
337
|
+
attach("A slot", "Schmoo");
|
|
338
|
+
defineConfigSchema("esm-bedrock", {});
|
|
339
|
+
provide({
|
|
340
|
+
"esm-bedrock": {
|
|
341
|
+
"Display conditions": {
|
|
342
|
+
privileges: ["Yabadabadoo!"],
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
function RootComponent() {
|
|
348
|
+
return (
|
|
349
|
+
<div>
|
|
350
|
+
<ExtensionSlot data-testid="slot" extensionSlotName="A slot" />
|
|
351
|
+
</div>
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
const App = openmrsComponentDecorator({
|
|
355
|
+
moduleName: "esm-bedrock",
|
|
356
|
+
featureName: "Bedrock",
|
|
357
|
+
disableTranslations: true,
|
|
358
|
+
})(RootComponent);
|
|
359
|
+
|
|
360
|
+
render(<App />);
|
|
361
|
+
await waitFor(() => expect(screen.getByTestId(/slot/)).toBeInTheDocument());
|
|
362
|
+
expect(screen.getByText(/\bSchmoo\b/)).toBeVisible();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("should only show extensions users have default privilege for", async () => {
|
|
366
|
+
mockSessionStore.setState({
|
|
367
|
+
loaded: true,
|
|
368
|
+
session: {
|
|
369
|
+
authenticated: true,
|
|
370
|
+
sessionId: "1",
|
|
371
|
+
user: {
|
|
372
|
+
uuid: "1",
|
|
373
|
+
display: "Non-Admin",
|
|
374
|
+
username: "nonadmin",
|
|
375
|
+
systemId: "nonadmin",
|
|
376
|
+
userProperties: {},
|
|
377
|
+
person: {} as Person,
|
|
378
|
+
privileges: [{ uuid: "1", display: "YOWTCH!" }],
|
|
379
|
+
roles: [],
|
|
380
|
+
retired: false,
|
|
381
|
+
locale: "en",
|
|
382
|
+
allowedLocales: ["en"],
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
registerSimpleExtension("Schmoo", "esm-bedrock", true, "Yabadabadoo!");
|
|
388
|
+
registerSimpleExtension("Wilma", "esm-flintstones", true, "YOWTCH!");
|
|
389
|
+
attach("A slot", "Schmoo");
|
|
390
|
+
attach("A slot", "Wilma");
|
|
391
|
+
defineConfigSchema("esm-bedrock", {});
|
|
392
|
+
defineConfigSchema("esm-flintstones", {});
|
|
393
|
+
provide({ "esm-bedrock": {} });
|
|
394
|
+
provide({ "esm-flintstones": {} });
|
|
395
|
+
|
|
396
|
+
function RootComponent() {
|
|
397
|
+
return (
|
|
398
|
+
<div>
|
|
399
|
+
<ExtensionSlot data-testid="slot" extensionSlotName="A slot" />
|
|
400
|
+
</div>
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
const App = openmrsComponentDecorator({
|
|
404
|
+
moduleName: "esm-bedrock",
|
|
405
|
+
featureName: "Bedrock",
|
|
406
|
+
disableTranslations: true,
|
|
407
|
+
})(RootComponent);
|
|
408
|
+
|
|
409
|
+
render(<App />);
|
|
410
|
+
await waitFor(() => expect(screen.getByTestId(/slot/)).toBeInTheDocument());
|
|
411
|
+
expect(screen.getByText(/\bWilma\b/)).toBeVisible();
|
|
412
|
+
expect(screen.queryAllByText(/\bSchmoo\b/)).toHaveLength(0);
|
|
413
|
+
});
|
|
247
414
|
});
|
|
248
415
|
|
|
249
416
|
function registerSimpleExtension(
|
|
250
417
|
name: string,
|
|
251
418
|
moduleName: string,
|
|
252
|
-
takesConfig: boolean = false
|
|
419
|
+
takesConfig: boolean = false,
|
|
420
|
+
privileges?: string | string[]
|
|
253
421
|
) {
|
|
254
422
|
const SimpleComponent = () => <div>{name}</div>;
|
|
255
423
|
const ConfigurableComponent = () => {
|
|
@@ -272,5 +440,6 @@ function registerSimpleExtension(
|
|
|
272
440
|
}
|
|
273
441
|
),
|
|
274
442
|
meta: {},
|
|
443
|
+
privileges,
|
|
275
444
|
});
|
|
276
445
|
}
|