@openmrs/esm-react-utils 3.4.1-pre.139 → 3.4.1-pre.151
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-react-utils",
|
|
3
|
-
"version": "3.4.1-pre.
|
|
3
|
+
"version": "3.4.1-pre.151",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "React utilities for OpenMRS.",
|
|
6
6
|
"browser": "dist/openmrs-esm-react-utils.js",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"react-i18next": "11.x"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@openmrs/esm-api": "^3.4.1-pre.
|
|
59
|
-
"@openmrs/esm-config": "^3.4.1-pre.
|
|
60
|
-
"@openmrs/esm-error-handling": "^3.4.1-pre.
|
|
61
|
-
"@openmrs/esm-extensions": "^3.4.1-pre.
|
|
62
|
-
"@openmrs/esm-globals": "^3.4.1-pre.
|
|
58
|
+
"@openmrs/esm-api": "^3.4.1-pre.151",
|
|
59
|
+
"@openmrs/esm-config": "^3.4.1-pre.151",
|
|
60
|
+
"@openmrs/esm-error-handling": "^3.4.1-pre.151",
|
|
61
|
+
"@openmrs/esm-extensions": "^3.4.1-pre.151",
|
|
62
|
+
"@openmrs/esm-globals": "^3.4.1-pre.151",
|
|
63
63
|
"dayjs": "^1.10.8",
|
|
64
64
|
"i18next": "^19.6.0",
|
|
65
65
|
"react": "^16.13.1",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"rxjs": "^6.5.3",
|
|
69
69
|
"unistore": "^3.5.2"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "f8709e7ec5c11e10682ef7e2f1463c4d343c22e5"
|
|
72
72
|
}
|
package/src/ExtensionSlot.tsx
CHANGED
|
@@ -40,12 +40,25 @@ function isShallowEqual(prevDeps: any, nextDeps: any) {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export interface ExtensionSlotBaseProps {
|
|
43
|
+
name: string;
|
|
44
|
+
/** @deprecated Use `name` */
|
|
45
|
+
extensionSlotName?: string;
|
|
46
|
+
select?: (extensions: Array<ConnectedExtension>) => Array<ConnectedExtension>;
|
|
47
|
+
state?: Record<string, any>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface OldExtensionSlotBaseProps {
|
|
51
|
+
name?: string;
|
|
52
|
+
/** @deprecated Use `name` */
|
|
43
53
|
extensionSlotName: string;
|
|
44
54
|
select?: (extensions: Array<ConnectedExtension>) => Array<ConnectedExtension>;
|
|
45
55
|
state?: Record<string, any>;
|
|
46
56
|
}
|
|
47
57
|
|
|
48
|
-
export type ExtensionSlotProps =
|
|
58
|
+
export type ExtensionSlotProps = (
|
|
59
|
+
| OldExtensionSlotBaseProps
|
|
60
|
+
| ExtensionSlotBaseProps
|
|
61
|
+
) &
|
|
49
62
|
React.HTMLAttributes<HTMLDivElement>;
|
|
50
63
|
|
|
51
64
|
function defaultSelect(extensions: Array<ConnectedExtension>) {
|
|
@@ -53,6 +66,7 @@ function defaultSelect(extensions: Array<ConnectedExtension>) {
|
|
|
53
66
|
}
|
|
54
67
|
|
|
55
68
|
export const ExtensionSlot: React.FC<ExtensionSlotProps> = ({
|
|
69
|
+
name: goodName,
|
|
56
70
|
extensionSlotName,
|
|
57
71
|
select = defaultSelect,
|
|
58
72
|
children,
|
|
@@ -60,9 +74,9 @@ export const ExtensionSlot: React.FC<ExtensionSlotProps> = ({
|
|
|
60
74
|
style,
|
|
61
75
|
...divProps
|
|
62
76
|
}: ExtensionSlotProps) => {
|
|
77
|
+
const name = (goodName ?? extensionSlotName) as string;
|
|
63
78
|
const slotRef = useRef(null);
|
|
64
|
-
const { extensions, extensionSlotModuleName } =
|
|
65
|
-
useExtensionSlot(extensionSlotName);
|
|
79
|
+
const { extensions, extensionSlotModuleName } = useExtensionSlot(name);
|
|
66
80
|
const stateRef = useRef(state);
|
|
67
81
|
|
|
68
82
|
if (!isShallowEqual(stateRef.current, state)) {
|
|
@@ -71,7 +85,7 @@ export const ExtensionSlot: React.FC<ExtensionSlotProps> = ({
|
|
|
71
85
|
|
|
72
86
|
const content = useMemo(
|
|
73
87
|
() =>
|
|
74
|
-
|
|
88
|
+
name &&
|
|
75
89
|
select(extensions).map((extension) => (
|
|
76
90
|
<ComponentContext.Provider
|
|
77
91
|
key={extension.id}
|
|
@@ -79,7 +93,7 @@ export const ExtensionSlot: React.FC<ExtensionSlotProps> = ({
|
|
|
79
93
|
moduleName: extensionSlotModuleName, // moduleName is not used by the receiving Extension
|
|
80
94
|
extension: {
|
|
81
95
|
extensionId: extension.id,
|
|
82
|
-
extensionSlotName,
|
|
96
|
+
extensionSlotName: name,
|
|
83
97
|
extensionSlotModuleName,
|
|
84
98
|
},
|
|
85
99
|
}}
|
|
@@ -87,13 +101,13 @@ export const ExtensionSlot: React.FC<ExtensionSlotProps> = ({
|
|
|
87
101
|
{children ?? <Extension state={stateRef.current} />}
|
|
88
102
|
</ComponentContext.Provider>
|
|
89
103
|
)),
|
|
90
|
-
[select, extensions,
|
|
104
|
+
[select, extensions, name, stateRef.current]
|
|
91
105
|
);
|
|
92
106
|
|
|
93
107
|
return (
|
|
94
108
|
<div
|
|
95
109
|
ref={slotRef}
|
|
96
|
-
data-extension-slot-name={
|
|
110
|
+
data-extension-slot-name={name}
|
|
97
111
|
data-extension-slot-module-name={extensionSlotModuleName}
|
|
98
112
|
style={{ ...style, position: "relative" }}
|
|
99
113
|
{...divProps}
|
package/src/UserHasAccess.tsx
CHANGED
package/src/useConfig.test.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { render, cleanup, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import { render, cleanup, screen, waitFor, act } from "@testing-library/react";
|
|
3
3
|
import {
|
|
4
4
|
defineConfigSchema,
|
|
5
5
|
temporaryConfigStore,
|
|
@@ -26,7 +26,6 @@ function clearConfig() {
|
|
|
26
26
|
|
|
27
27
|
describe(`useConfig in root context`, () => {
|
|
28
28
|
afterEach(clearConfig);
|
|
29
|
-
afterEach(cleanup);
|
|
30
29
|
|
|
31
30
|
it(`can return config as a react hook`, async () => {
|
|
32
31
|
defineConfigSchema("foo-module", {
|
|
@@ -103,9 +102,11 @@ describe(`useConfig in root context`, () => {
|
|
|
103
102
|
expect(screen.findByText("The first thing")).toBeTruthy()
|
|
104
103
|
);
|
|
105
104
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
act(() =>
|
|
106
|
+
temporaryConfigStore.setState({
|
|
107
|
+
config: { "foo-module": { thing: "A new thing" } },
|
|
108
|
+
})
|
|
109
|
+
);
|
|
109
110
|
|
|
110
111
|
await waitFor(() => expect(screen.findByText("A new thing")).toBeTruthy());
|
|
111
112
|
});
|
|
@@ -273,7 +274,7 @@ describe(`useConfig in an extension`, () => {
|
|
|
273
274
|
);
|
|
274
275
|
|
|
275
276
|
const newConfig = { "ext-module": { thing: "A new thing" } };
|
|
276
|
-
temporaryConfigStore.setState({ config: newConfig });
|
|
277
|
+
act(() => temporaryConfigStore.setState({ config: newConfig }));
|
|
277
278
|
|
|
278
279
|
await waitFor(() => expect(screen.findByText("A new thing")).toBeTruthy());
|
|
279
280
|
|
|
@@ -290,7 +291,7 @@ describe(`useConfig in an extension`, () => {
|
|
|
290
291
|
},
|
|
291
292
|
},
|
|
292
293
|
};
|
|
293
|
-
temporaryConfigStore.setState({ config: newConfig2 });
|
|
294
|
+
act(() => temporaryConfigStore.setState({ config: newConfig2 }));
|
|
294
295
|
|
|
295
296
|
await waitFor(() =>
|
|
296
297
|
expect(screen.findByText("Yet another thing")).toBeTruthy()
|