@uxland/primary-shell 8.3.3 → 8.3.5
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/README.md +18 -1
- package/dist/{component-BYXgNvke.js → component-Dv2Cw4dX.js} +2 -2
- package/dist/{component-BYXgNvke.js.map → component-Dv2Cw4dX.js.map} +1 -1
- package/dist/{index-CDpyZ5Yt.js → index-CCC4rQo1.js} +2629 -2628
- package/dist/{index-CDpyZ5Yt.js.map → index-CCC4rQo1.js.map} +1 -1
- package/dist/index.js +21 -22
- package/dist/index.js.map +1 -1
- package/dist/{plugin-CMgpCPh9.js → plugin-D3sg1ev9.js} +5 -6
- package/dist/{plugin-CMgpCPh9.js.map → plugin-D3sg1ev9.js.map} +1 -1
- package/package.json +7 -15
- package/src/UI/bootstrapper.ts +0 -14
- package/src/UI/components/bootstrapper.ts +0 -25
- package/src/UI/components/clinical-pathways-action-menu/clinical-pathways-action-menu.ts +0 -13
- package/src/UI/components/communication-action-menu/communication-action-menu.ts +0 -13
- package/src/UI/components/error-view/component.ts +0 -17
- package/src/UI/components/error-view/styles.css +0 -27
- package/src/UI/components/error-view/template.ts +0 -12
- package/src/UI/components/nav-divider/nav-divider.ts +0 -41
- package/src/UI/components/nav-divider/styles.css +0 -21
- package/src/UI/components/nav-divider/template.ts +0 -8
- package/src/UI/components/petitioner-action-menu/petitioner-action-menu.ts +0 -13
- package/src/UI/components/primaria-accordion/primaria-accordion.ts +0 -45
- package/src/UI/components/primaria-shell/constants.ts +0 -4
- package/src/UI/components/primaria-shell/primaria-shell.ts +0 -105
- package/src/UI/components/primaria-shell/shell-header/header-divider/header-divider.ts +0 -13
- package/src/UI/components/primaria-shell/shell-header/header-divider/styles.css +0 -5
- package/src/UI/components/primaria-shell/shell-header/header-divider/template.ts +0 -8
- package/src/UI/components/primaria-shell/shell-header/shell-header.ts +0 -71
- package/src/UI/components/primaria-shell/shell-header/styles.css +0 -45
- package/src/UI/components/primaria-shell/shell-header/template.ts +0 -37
- package/src/UI/components/primaria-shell/styles.css +0 -185
- package/src/UI/components/primaria-shell/template.ts +0 -72
- package/src/UI/components/sidenav-action-menu/sidenav-action-menu.ts +0 -62
- package/src/UI/components/sidenav-action-menu/styles.css +0 -25
- package/src/UI/components/sidenav-action-menu/template.ts +0 -24
- package/src/UI/fonts/fonts.css +0 -48
- package/src/UI/fonts/open-sans-v40-latin-300.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-500.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-600.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-700.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-800.woff2 +0 -0
- package/src/UI/fonts/open-sans-v40-latin-regular.woff2 +0 -0
- package/src/UI/images/Gencat_Logotip.svg +0 -70
- package/src/UI/images/Salut_Logotip.svg +0 -8
- package/src/UI/index.ts +0 -1
- package/src/UI/internal-views/administrative-nav-menu.ts +0 -302
- package/src/UI/internal-views/common-nav-menu.ts +0 -94
- package/src/UI/internal-views/doctor-nav-menu.ts +0 -297
- package/src/UI/internal-views/doctor-quick-action-menu.ts +0 -16
- package/src/UI/internal-views/handle-views.ts +0 -24
- package/src/UI/shared-components/bootstrapper.ts +0 -18
- package/src/UI/shared-components/index.ts +0 -1
- package/src/UI/shared-components/primaria-character-limit-badge/primaria-character-limit-badge.ts +0 -27
- package/src/UI/shared-components/primaria-character-limit-badge/styles.css +0 -8
- package/src/UI/shared-components/primaria-content-switcher/primaria-content-switcher.ts +0 -78
- package/src/UI/shared-components/primaria-nav-item/primaria-nav-item.ts +0 -71
- package/src/UI/shared-components/primaria-nav-item/styles.css +0 -25
- package/src/UI/shared-components/primaria-nav-item/template.ts +0 -27
- package/src/UI/shared-components/primaria-nav-tree-menu/primaria-nav-tree-menu.ts +0 -41
- package/src/UI/shared-components/primaria-nav-tree-menu/styles.css +0 -11
- package/src/UI/shared-components/primaria-nav-tree-menu/template.ts +0 -46
- package/src/UI/shared-components/primaria-region/index.ts +0 -1
- package/src/UI/shared-components/primaria-region/primaria-region.ts +0 -199
- package/src/UI/shared-components/primaria-text-editor/primaria-rich-text-editor.ts +0 -261
- package/src/UI/shared-components/primaria-text-editor/styles.css +0 -966
- package/src/UI/shared-components/primaria-text-editor/template.ts +0 -8
- package/src/UI/shared-components/primaria-text-editor/utils.ts +0 -39
- package/src/UI/shared-components/quick-action-item/quick-action-item.ts +0 -21
- package/src/UI/shared-components/quick-action-item/template.ts +0 -8
- package/src/UI/shared-components/typings.ts +0 -19
- package/src/api/activity-monitor/activity-monitor.test.ts +0 -67
- package/src/api/activity-monitor/activity-monitor.ts +0 -26
- package/src/api/api.test.ts +0 -37
- package/src/api/api.ts +0 -119
- package/src/api/broker/broker-events.ts +0 -39
- package/src/api/broker/broker-requests.ts +0 -20
- package/src/api/broker/factory.test.ts +0 -378
- package/src/api/broker/factory.ts +0 -151
- package/src/api/broker/primaria-broker.ts +0 -20
- package/src/api/context-manager/context-manager.test.ts +0 -86
- package/src/api/context-manager/context-manager.ts +0 -42
- package/src/api/ecap-event-manager/ecap-event-manager.test.ts +0 -100
- package/src/api/ecap-event-manager/ecap-event-manager.ts +0 -58
- package/src/api/ecap-event-manager/typings.ts +0 -6
- package/src/api/exit-guard-manager/exit-guard-manager.test.ts +0 -75
- package/src/api/exit-guard-manager/exit-guard-manager.ts +0 -31
- package/src/api/global-state/global-state.test.ts +0 -45
- package/src/api/global-state/global-state.ts +0 -38
- package/src/api/http-client/http-client.test.ts +0 -196
- package/src/api/http-client/http-client.ts +0 -97
- package/src/api/import-data-manager/component/component.ts +0 -29
- package/src/api/import-data-manager/component/styles.css +0 -79
- package/src/api/import-data-manager/component/template.ts +0 -49
- package/src/api/import-data-manager/import-data-manager-impl.test.ts +0 -364
- package/src/api/import-data-manager/import-data-manager-impl.ts +0 -121
- package/src/api/import-data-manager/import-data-manager.ts +0 -42
- package/src/api/import-data-manager/index.ts +0 -2
- package/src/api/interaction-service/confirmation-message.tsx +0 -5
- package/src/api/interaction-service/index.ts +0 -1
- package/src/api/interaction-service/interaction-service-impl.tsx +0 -260
- package/src/api/interaction-service/interaction-service.ts +0 -52
- package/src/api/interaction-service/modal-styles.css +0 -97
- package/src/api/localization/localization.test.ts +0 -61
- package/src/api/localization/localization.ts +0 -58
- package/src/api/notification-service/notification-service-impl.test.ts +0 -84
- package/src/api/notification-service/notification-service.ts +0 -6
- package/src/api/notification-service/notification.service-impl.ts +0 -67
- package/src/api/pdf-viewer-manager/constants.ts +0 -1
- package/src/api/pdf-viewer-manager/events.ts +0 -5
- package/src/api/pdf-viewer-manager/handle-views.ts +0 -32
- package/src/api/pdf-viewer-manager/pdf-viewer-manager.test.ts +0 -126
- package/src/api/pdf-viewer-manager/pdf-viewer-manager.ts +0 -96
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/pdf-selector.ts +0 -39
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/styles.css +0 -45
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-selector/template.ts +0 -32
- package/src/api/pdf-viewer-manager/pdf-visor/pdf-visor.ts +0 -122
- package/src/api/pdf-viewer-manager/pdf-visor/styles.css +0 -29
- package/src/api/pdf-viewer-manager/pdf-visor/utils.ts +0 -16
- package/src/api/quick-action-busy-manager/quick-action-busy-manager.test.ts +0 -61
- package/src/api/quick-action-busy-manager/quick-action-busy-manager.ts +0 -45
- package/src/api/region-manager/region-manager.test.ts +0 -239
- package/src/api/region-manager/region-manager.ts +0 -263
- package/src/api/region-manager/regions.ts +0 -30
- package/src/api/region-manager/remove-view-idempotency.test.ts +0 -98
- package/src/api/session-refresh-timer/session-refresh-timer.test.ts +0 -102
- package/src/api/session-refresh-timer/session-refresh-timer.ts +0 -75
- package/src/api/token-manager/token-manager.test.ts +0 -146
- package/src/api/token-manager/token-manager.ts +0 -70
- package/src/api/user-manager/user-manager.ts +0 -79
- package/src/bootstrapper.ts +0 -41
- package/src/constants.ts +0 -1
- package/src/disposer.ts +0 -19
- package/src/features/bootstrapper.ts +0 -21
- package/src/features/exit/bootstrapper.ts +0 -17
- package/src/features/exit/handler.test.ts +0 -187
- package/src/features/exit/handler.ts +0 -58
- package/src/features/exit/request.ts +0 -10
- package/src/features/get-patient-cip/action.ts +0 -5
- package/src/features/get-user-info/backend-adapter.ts +0 -48
- package/src/features/get-user-info/bootstrapper.ts +0 -20
- package/src/features/get-user-info/handler.test.ts +0 -66
- package/src/features/get-user-info/handler.ts +0 -23
- package/src/features/get-user-info/model.ts +0 -10
- package/src/features/get-user-info/pds-token.ts +0 -28
- package/src/features/get-user-info/request.ts +0 -4
- package/src/features/get-visi-id/action.ts +0 -11
- package/src/features/navigate-to-ecap/navigate-to-ecap.ts +0 -21
- package/src/features/utils.ts +0 -27
- package/src/handle-plugins.ts +0 -82
- package/src/index.ts +0 -101
- package/src/infrastructure/ioc/container.ts +0 -14
- package/src/infrastructure/ioc/types.ts +0 -5
- package/src/locales.ts +0 -70
- package/src/types/custom.d.ts +0 -30
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { PrimariaApi, shellInternals } from "../../api/api";
|
|
3
|
-
import { disposeShell, raiseCloseEvent, raiseCustomCloseEvent } from "../../disposer";
|
|
4
|
-
import { disposePlugins } from "../../handle-plugins";
|
|
5
|
-
import { ExitShellHandler } from "./handler";
|
|
6
|
-
import { ExitShell } from "./request";
|
|
7
|
-
|
|
8
|
-
vi.mock("../../api/api", () => ({
|
|
9
|
-
shellInternals: {
|
|
10
|
-
removeAllViews: vi.fn(),
|
|
11
|
-
},
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
vi.mock("../../handle-plugins", () => ({
|
|
15
|
-
disposePlugins: vi.fn(),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
vi.mock("../../disposer", () => ({
|
|
19
|
-
disposeShell: vi.fn(),
|
|
20
|
-
raiseCloseEvent: vi.fn(),
|
|
21
|
-
raiseCustomCloseEvent: vi.fn(),
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
const createMockApi = (): PrimariaApi =>
|
|
25
|
-
({
|
|
26
|
-
exitGuardManager: {
|
|
27
|
-
canExit: vi.fn().mockResolvedValue(true),
|
|
28
|
-
},
|
|
29
|
-
notificationService: {
|
|
30
|
-
error: vi.fn(),
|
|
31
|
-
},
|
|
32
|
-
}) as any;
|
|
33
|
-
|
|
34
|
-
describe("ExitShellHandler", () => {
|
|
35
|
-
let handler: ExitShellHandler;
|
|
36
|
-
let mockApi: PrimariaApi;
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
mockApi = createMockApi();
|
|
40
|
-
handler = new ExitShellHandler(mockApi);
|
|
41
|
-
vi.clearAllMocks();
|
|
42
|
-
vi.mocked(shellInternals.removeAllViews).mockReset().mockResolvedValue(undefined);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("disposes and raises custom close event when canExit resolves true and message has ecapEvent", async () => {
|
|
46
|
-
const message = { ecapEvent: {} } as ExitShell;
|
|
47
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(true);
|
|
48
|
-
(disposePlugins as any).mockResolvedValue(undefined);
|
|
49
|
-
|
|
50
|
-
await handler.handle(message);
|
|
51
|
-
|
|
52
|
-
expect(mockApi.exitGuardManager.canExit).toHaveBeenCalled();
|
|
53
|
-
expect(disposePlugins).toHaveBeenCalled();
|
|
54
|
-
expect(disposeShell).toHaveBeenCalled();
|
|
55
|
-
expect(raiseCustomCloseEvent).toHaveBeenCalledWith(message);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("raises default close event when no ecapEvent is present", async () => {
|
|
59
|
-
const message = {} as ExitShell;
|
|
60
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(true);
|
|
61
|
-
(disposePlugins as any).mockResolvedValue(undefined);
|
|
62
|
-
|
|
63
|
-
await handler.handle(message);
|
|
64
|
-
|
|
65
|
-
expect(disposePlugins).toHaveBeenCalled();
|
|
66
|
-
expect(disposeShell).toHaveBeenCalled();
|
|
67
|
-
expect(raiseCloseEvent).toHaveBeenCalled();
|
|
68
|
-
expect(raiseCustomCloseEvent).not.toHaveBeenCalled();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("aborts the exit when any guard returns false", async () => {
|
|
72
|
-
const message = { ecapEvent: {} } as ExitShell;
|
|
73
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(false);
|
|
74
|
-
|
|
75
|
-
await handler.handle(message);
|
|
76
|
-
|
|
77
|
-
expect(mockApi.exitGuardManager.canExit).toHaveBeenCalled();
|
|
78
|
-
expect(disposePlugins).not.toHaveBeenCalled();
|
|
79
|
-
expect(disposeShell).not.toHaveBeenCalled();
|
|
80
|
-
expect(raiseCustomCloseEvent).not.toHaveBeenCalled();
|
|
81
|
-
expect(raiseCloseEvent).not.toHaveBeenCalled();
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("notifies and raises custom close event when dispose throws and ecapEvent is present", async () => {
|
|
85
|
-
const message = { ecapEvent: {} } as ExitShell;
|
|
86
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(true);
|
|
87
|
-
(disposePlugins as any).mockRejectedValue(new Error("boom"));
|
|
88
|
-
|
|
89
|
-
await handler.handle(message);
|
|
90
|
-
|
|
91
|
-
expect(mockApi.notificationService.error).toHaveBeenCalledWith("errors.exit");
|
|
92
|
-
expect(raiseCustomCloseEvent).toHaveBeenCalledWith(message);
|
|
93
|
-
expect(raiseCloseEvent).not.toHaveBeenCalled();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("notifies and raises default close event when dispose throws and no ecapEvent", async () => {
|
|
97
|
-
const message = {} as ExitShell;
|
|
98
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(true);
|
|
99
|
-
(disposePlugins as any).mockRejectedValue(new Error("boom"));
|
|
100
|
-
|
|
101
|
-
await handler.handle(message);
|
|
102
|
-
|
|
103
|
-
expect(mockApi.notificationService.error).toHaveBeenCalledWith("errors.exit");
|
|
104
|
-
expect(raiseCloseEvent).toHaveBeenCalled();
|
|
105
|
-
expect(raiseCustomCloseEvent).not.toHaveBeenCalled();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("proceeds if disposePlugins exceeds the 10s timeout", async () => {
|
|
109
|
-
const message = { ecapEvent: {} } as ExitShell;
|
|
110
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(true);
|
|
111
|
-
(disposePlugins as any).mockImplementation(() => new Promise((resolve) => setTimeout(resolve, 11000)));
|
|
112
|
-
|
|
113
|
-
await handler.handle(message);
|
|
114
|
-
|
|
115
|
-
expect(disposePlugins).toHaveBeenCalled();
|
|
116
|
-
expect(disposeShell).toHaveBeenCalled();
|
|
117
|
-
expect(raiseCustomCloseEvent).toHaveBeenCalledWith(message);
|
|
118
|
-
}, 15000);
|
|
119
|
-
|
|
120
|
-
it("raises raiseCloseEvent when no exitEvent is passed", async () => {
|
|
121
|
-
(mockApi.exitGuardManager.canExit as any).mockResolvedValue(true);
|
|
122
|
-
(disposePlugins as any).mockResolvedValue(undefined);
|
|
123
|
-
|
|
124
|
-
await handler.handle(undefined as any);
|
|
125
|
-
|
|
126
|
-
expect(disposeShell).toHaveBeenCalled();
|
|
127
|
-
expect(raiseCloseEvent).toHaveBeenCalled();
|
|
128
|
-
expect(raiseCustomCloseEvent).not.toHaveBeenCalled();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
describe("ordre de tancament: vistes abans que plugins", () => {
|
|
132
|
-
/**
|
|
133
|
-
* Els cleanups dels `useEffect` s'executen en desmuntar-se el component i poden enviar
|
|
134
|
-
* comandes pel broker (p. ex. `ClearTransportDetail` a petitioner). Si el `dispose` dels
|
|
135
|
-
* plugins corre primer, el handler ja no hi es i el `send` rebutja. Cada plugin d'aquest
|
|
136
|
-
* repositori ja ho ordena be, pero els de tercers no els controlem: aquest ordre els cobreix.
|
|
137
|
-
*/
|
|
138
|
-
it("desmunta totes les vistes abans de disposar els plugins", async () => {
|
|
139
|
-
const order: string[] = [];
|
|
140
|
-
vi.mocked(shellInternals.removeAllViews).mockImplementation(async () => {
|
|
141
|
-
order.push("removeAllViews");
|
|
142
|
-
});
|
|
143
|
-
(disposePlugins as any).mockImplementation(async () => {
|
|
144
|
-
order.push("disposePlugins");
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
await handler.handle({} as ExitShell);
|
|
148
|
-
|
|
149
|
-
expect(order).toEqual(["removeAllViews", "disposePlugins"]);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("no comenca a disposar fins que el desmuntatge ha acabat", async () => {
|
|
153
|
-
let finishUnmount: () => void = () => {};
|
|
154
|
-
vi.mocked(shellInternals.removeAllViews).mockImplementation(
|
|
155
|
-
() =>
|
|
156
|
-
new Promise<void>((resolve) => {
|
|
157
|
-
finishUnmount = resolve;
|
|
158
|
-
}),
|
|
159
|
-
);
|
|
160
|
-
(disposePlugins as any).mockResolvedValue(undefined);
|
|
161
|
-
|
|
162
|
-
const handled = handler.handle({} as ExitShell);
|
|
163
|
-
await Promise.resolve();
|
|
164
|
-
await Promise.resolve();
|
|
165
|
-
expect(disposePlugins).not.toHaveBeenCalled();
|
|
166
|
-
|
|
167
|
-
finishUnmount();
|
|
168
|
-
await handled;
|
|
169
|
-
|
|
170
|
-
expect(disposePlugins).toHaveBeenCalled();
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("el limit de temps del tancament segueix cobrint tot el proces", async () => {
|
|
174
|
-
vi.useFakeTimers();
|
|
175
|
-
vi.mocked(shellInternals.removeAllViews).mockImplementation(() => new Promise<void>(() => {}));
|
|
176
|
-
|
|
177
|
-
const handled = handler.handle({} as ExitShell);
|
|
178
|
-
await vi.advanceTimersByTimeAsync(10000);
|
|
179
|
-
await handled;
|
|
180
|
-
|
|
181
|
-
// Encara que el desmuntatge no acabi mai, el tancament continua.
|
|
182
|
-
expect(disposeShell).toHaveBeenCalled();
|
|
183
|
-
expect(raiseCloseEvent).toHaveBeenCalled();
|
|
184
|
-
vi.useRealTimers();
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { inject } from "inversify";
|
|
2
|
-
import { PrimariaApi, shellInternals } from "../../api/api";
|
|
3
|
-
import { disposeShell, raiseCloseEvent, raiseCustomCloseEvent } from "../../disposer";
|
|
4
|
-
import { disposePlugins } from "../../handle-plugins";
|
|
5
|
-
import { TYPES } from "../../infrastructure/ioc/types";
|
|
6
|
-
import { translate } from "../../locales";
|
|
7
|
-
import { ExitShell } from "./request";
|
|
8
|
-
|
|
9
|
-
export class ExitShellHandler {
|
|
10
|
-
constructor(@inject(TYPES.primaryApi) private api: PrimariaApi) {}
|
|
11
|
-
async handle(exitEvent: ExitShell): Promise<void> {
|
|
12
|
-
const evt = exitEvent && exitEvent.ecapEvent !== undefined ? exitEvent : undefined;
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
const canExit = await this.api.exitGuardManager.canExit();
|
|
16
|
-
if (!canExit) return;
|
|
17
|
-
|
|
18
|
-
// Per si un plugin tarda molt en fer dispose, màxim deixarem 5 segons, per no interrompre el tancar infinitament
|
|
19
|
-
await Promise.race([
|
|
20
|
-
this.unmountViewsAndDisposePlugins(), // S'intenta executar un dispose normal
|
|
21
|
-
this.timeout(10000), // Si passen 10s, es segueix amb l'execució
|
|
22
|
-
]);
|
|
23
|
-
await disposeShell();
|
|
24
|
-
this.emitClose(evt);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
this.api.notificationService.error(translate("errors.exit"));
|
|
27
|
-
this.emitClose(evt);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Desmunta les vistes de tots els plugins abans de fer-los el `dispose`.
|
|
33
|
-
*
|
|
34
|
-
* Els cleanups dels `useEffect` s'executen en desmuntar-se el component i poden enviar comandes
|
|
35
|
-
* pel broker (p. ex. `ClearTransportDetail` a petitioner). Si el `dispose` s'executa primer, el
|
|
36
|
-
* handler ja no hi és i el `send` rebutja. Cada plugin d'aquest repositori ja desmunta les seves
|
|
37
|
-
* vistes primer, però els de tercers no els controlem: fer-ho aquí els cobreix tots.
|
|
38
|
-
*
|
|
39
|
-
* Va dins del mateix `Promise.race` que el `dispose`, així que el límit de temps del tancament
|
|
40
|
-
* no canvia.
|
|
41
|
-
*/
|
|
42
|
-
private async unmountViewsAndDisposePlugins(): Promise<void> {
|
|
43
|
-
await shellInternals.removeAllViews();
|
|
44
|
-
await disposePlugins();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
private timeout(ms: number) {
|
|
48
|
-
return new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private emitClose(exitEvent?: ExitShell): void {
|
|
52
|
-
if (exitEvent) {
|
|
53
|
-
raiseCustomCloseEvent(exitEvent);
|
|
54
|
-
} else {
|
|
55
|
-
raiseCloseEvent();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { inject, injectable } from "inversify";
|
|
2
|
-
import { jwtDecode } from "jwt-decode";
|
|
3
|
-
import { shellApi } from "../../api/api";
|
|
4
|
-
import { TYPES } from "../../infrastructure/ioc/types";
|
|
5
|
-
import { IUserInfo } from "./model";
|
|
6
|
-
import { PdsAccessInfo, PdsToken } from "./pds-token";
|
|
7
|
-
|
|
8
|
-
/** Ordre de preferència dels identificadors del professional dins del token. */
|
|
9
|
-
const USER_ID_TYPES = ["DNI", "NIE", "PASS"];
|
|
10
|
-
|
|
11
|
-
export abstract class UserInfoBackendAdapter {
|
|
12
|
-
abstract getUserInfo(): Promise<IUserInfo>;
|
|
13
|
-
}
|
|
14
|
-
@injectable()
|
|
15
|
-
export class GetUserInfoBackendAdapter implements UserInfoBackendAdapter {
|
|
16
|
-
constructor(@inject(TYPES.primaryApi) private api: typeof shellApi) {}
|
|
17
|
-
getUserInfo(): Promise<IUserInfo> {
|
|
18
|
-
const decodedToken = jwtDecode<PdsToken>(this.api.tokenManager.getToken());
|
|
19
|
-
const accessInfo = decodedToken.access_info;
|
|
20
|
-
|
|
21
|
-
// `IUserInfo` declara `string` a tots els camps, però el token no en garanteix cap. Abans
|
|
22
|
-
// el token era `any` i els absents arribaven com a `undefined` amb tipus `string`; ara es
|
|
23
|
-
// normalitzen a cadena buida perquè el tipus digui la veritat.
|
|
24
|
-
const userInfo: IUserInfo = {
|
|
25
|
-
userId: this.getUserId(accessInfo) ?? "",
|
|
26
|
-
firstName: accessInfo?.trace_user_given_name ?? "",
|
|
27
|
-
familyName: accessInfo?.trace_user_family_name ?? "",
|
|
28
|
-
lastName: accessInfo?.trace_user_last_name ?? "",
|
|
29
|
-
registrationNumber: this.findIdentifier(accessInfo, "NUMCOL") ?? "",
|
|
30
|
-
workCenter: accessInfo?.center_code ?? "",
|
|
31
|
-
role: accessInfo?.role_type ?? "",
|
|
32
|
-
speciality: accessInfo?.professional_category ?? "",
|
|
33
|
-
};
|
|
34
|
-
return Promise.resolve(userInfo);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private findIdentifier(accessInfo: PdsAccessInfo | undefined, type: string) {
|
|
38
|
-
return accessInfo?.identifier?.find((identifier) => identifier.type === type)?.value;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getUserId(accessInfo: PdsAccessInfo | undefined) {
|
|
42
|
-
for (const type of USER_ID_TYPES) {
|
|
43
|
-
const value = this.findIdentifier(accessInfo, type);
|
|
44
|
-
if (value) return value;
|
|
45
|
-
}
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { PrimariaApi, shellApi } from "../../api/api";
|
|
2
|
-
import { BrokerDisposableHandler } from "../../api/broker/primaria-broker";
|
|
3
|
-
import { container, registerDep, unregisterDep } from "../../infrastructure/ioc/container";
|
|
4
|
-
import { registerRequest } from "../utils";
|
|
5
|
-
import { GetUserInfoBackendAdapter } from "./backend-adapter";
|
|
6
|
-
import { GetUserInfoHandler } from "./handler";
|
|
7
|
-
import { GetUserInfo } from "./request";
|
|
8
|
-
|
|
9
|
-
let request: BrokerDisposableHandler;
|
|
10
|
-
|
|
11
|
-
export const useGetUserInfo = (api: PrimariaApi) => {
|
|
12
|
-
disposeGetUserInfo();
|
|
13
|
-
request = registerRequest(api, container)(GetUserInfo, GetUserInfoHandler);
|
|
14
|
-
registerDep(GetUserInfoBackendAdapter);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const disposeGetUserInfo = () => {
|
|
18
|
-
request?.dispose();
|
|
19
|
-
unregisterDep(GetUserInfoBackendAdapter);
|
|
20
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
2
|
-
import { GetUserInfoHandler } from "./handler";
|
|
3
|
-
import { GetUserInfo } from "./request";
|
|
4
|
-
import { IUserInfo } from "./model";
|
|
5
|
-
import { UserInfoBackendAdapter } from "./backend-adapter";
|
|
6
|
-
import { PrimariaApi } from "../../api/api";
|
|
7
|
-
|
|
8
|
-
const createMockApi = (): PrimariaApi =>
|
|
9
|
-
({
|
|
10
|
-
globalStateManager: {
|
|
11
|
-
setData: vi.fn(),
|
|
12
|
-
},
|
|
13
|
-
notificationService: {
|
|
14
|
-
error: vi.fn(),
|
|
15
|
-
},
|
|
16
|
-
}) as any;
|
|
17
|
-
|
|
18
|
-
const createMockBackendAdapter = (): UserInfoBackendAdapter =>
|
|
19
|
-
({
|
|
20
|
-
getUserInfo: vi.fn(),
|
|
21
|
-
}) as any;
|
|
22
|
-
|
|
23
|
-
describe("GetUserInfoHandler", () => {
|
|
24
|
-
let handler: GetUserInfoHandler;
|
|
25
|
-
let api: PrimariaApi;
|
|
26
|
-
let backendAdapter: UserInfoBackendAdapter;
|
|
27
|
-
|
|
28
|
-
const message = {} as GetUserInfo;
|
|
29
|
-
const mockUserInfo: IUserInfo = {
|
|
30
|
-
userId: "12345678Z",
|
|
31
|
-
firstName: "John",
|
|
32
|
-
familyName: "Doe",
|
|
33
|
-
lastName: "Smith",
|
|
34
|
-
registrationNumber: "081234",
|
|
35
|
-
workCenter: "CAP",
|
|
36
|
-
role: "assist",
|
|
37
|
-
speciality: "MF",
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
api = createMockApi();
|
|
42
|
-
backendAdapter = createMockBackendAdapter();
|
|
43
|
-
handler = new GetUserInfoHandler(api, backendAdapter);
|
|
44
|
-
vi.clearAllMocks();
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("should fetch user info and store it in global state", async () => {
|
|
48
|
-
(backendAdapter.getUserInfo as any).mockResolvedValue(mockUserInfo);
|
|
49
|
-
|
|
50
|
-
const result = await handler.handle(message);
|
|
51
|
-
|
|
52
|
-
expect(backendAdapter.getUserInfo).toHaveBeenCalled();
|
|
53
|
-
expect(api.globalStateManager.setData).toHaveBeenCalledWith("userInfo", mockUserInfo);
|
|
54
|
-
expect(result).toEqual(mockUserInfo);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should handle error and call notificationService", async () => {
|
|
58
|
-
const error = new Error("Failed to fetch user info");
|
|
59
|
-
(backendAdapter.getUserInfo as any).mockRejectedValue(error);
|
|
60
|
-
|
|
61
|
-
const result = await handler.handle(message);
|
|
62
|
-
|
|
63
|
-
expect(api.notificationService.error).toHaveBeenCalledWith("Failed to fetch user info");
|
|
64
|
-
expect(result).toBeUndefined();
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { TYPES } from "../../infrastructure/ioc/types";
|
|
2
|
-
import { inject } from "inversify";
|
|
3
|
-
import { GetUserInfo } from "./request";
|
|
4
|
-
import { IUserInfo } from "./model";
|
|
5
|
-
import { UserInfoBackendAdapter } from "./backend-adapter";
|
|
6
|
-
import { GetUserInfoBackendAdapter } from "./backend-adapter";
|
|
7
|
-
import { PrimariaApi } from "../../api/api";
|
|
8
|
-
|
|
9
|
-
export class GetUserInfoHandler {
|
|
10
|
-
constructor(
|
|
11
|
-
@inject(TYPES.primaryApi) private api: PrimariaApi,
|
|
12
|
-
@inject(GetUserInfoBackendAdapter) private backendAdapter: UserInfoBackendAdapter,
|
|
13
|
-
) {}
|
|
14
|
-
async handle(message: GetUserInfo): Promise<IUserInfo | undefined> {
|
|
15
|
-
try {
|
|
16
|
-
const userInfo = await this.backendAdapter.getUserInfo();
|
|
17
|
-
this.api.globalStateManager.setData("userInfo", userInfo);
|
|
18
|
-
return userInfo;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
this.api.notificationService.error(error.message);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Els camps del token del PDS que aquest adaptador llegeix.
|
|
3
|
-
*
|
|
4
|
-
* Es declara aquí, i no s'importa `PDSToken` de `@pds/core`, per dues raons: el shell no depèn
|
|
5
|
-
* d'aquell package, i el seu `AccessInfo` no inclou `trace_user_last_name`, que sí que es fa
|
|
6
|
-
* servir. Si algun dia s'unifiquen els dos contractes, aquest fitxer hauria de desaparèixer.
|
|
7
|
-
*
|
|
8
|
-
* Tot és opcional perquè el token no en garanteix cap: fins ara el tipus era `any` i
|
|
9
|
-
* `IUserInfo` prometia `string` a tot arreu, cosa que no era certa en runtime.
|
|
10
|
-
*/
|
|
11
|
-
export interface PdsAccessInfo {
|
|
12
|
-
trace_user_given_name?: string;
|
|
13
|
-
trace_user_family_name?: string;
|
|
14
|
-
trace_user_last_name?: string;
|
|
15
|
-
center_code?: string;
|
|
16
|
-
role_type?: string;
|
|
17
|
-
professional_category?: string;
|
|
18
|
-
identifier?: PdsIdentifier[];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface PdsIdentifier {
|
|
22
|
-
type: string;
|
|
23
|
-
value: string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface PdsToken {
|
|
27
|
-
access_info?: PdsAccessInfo;
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { PrimariaApi } from "../../api/api";
|
|
2
|
-
|
|
3
|
-
export const getVisiId = async (api: PrimariaApi): Promise<string | undefined> => {
|
|
4
|
-
const context = api.contextManager.getContext();
|
|
5
|
-
if (context.visi_id) return context.visi_id as string;
|
|
6
|
-
try {
|
|
7
|
-
return (await api.broker.send("get_visi_id")) as string;
|
|
8
|
-
} catch {
|
|
9
|
-
return undefined;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { shellApi } from "../../api/api";
|
|
2
|
-
import { getPatientCip } from "../get-patient-cip/action";
|
|
3
|
-
|
|
4
|
-
export const navigateToEcap = async (
|
|
5
|
-
eventName: string,
|
|
6
|
-
closeAction = "NO_TANCAR",
|
|
7
|
-
additionalParams: Record<string, string> = {},
|
|
8
|
-
includeCip = true,
|
|
9
|
-
) => {
|
|
10
|
-
const params = { ...additionalParams };
|
|
11
|
-
|
|
12
|
-
try {
|
|
13
|
-
if (includeCip) {
|
|
14
|
-
const CIP = await getPatientCip(shellApi);
|
|
15
|
-
params.CIP = CIP;
|
|
16
|
-
shellApi.ecapEventManager.publish(eventName, closeAction, params);
|
|
17
|
-
}
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error(error);
|
|
20
|
-
}
|
|
21
|
-
};
|
package/src/features/utils.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Container, injectable } from "inversify";
|
|
2
|
-
import type { interfaces } from "inversify";
|
|
3
|
-
import { IRequest, IRequestClass } from "..";
|
|
4
|
-
import { PrimariaApi } from "../api/api";
|
|
5
|
-
|
|
6
|
-
// Helper intern del shell: registra una request al broker i binda el seu handler
|
|
7
|
-
// al container d'Inversify. És el bessó del `registerRequest` de
|
|
8
|
-
// `@primaria/plugins-core` (brokerExtensions), però es manté aquí a propòsit:
|
|
9
|
-
// el shell només importa contractes de `plugins-core` (constants i tipus del
|
|
10
|
-
// broker), i `plugins-core` depèn del shell per l'API. Fer servir el seu helper aquí
|
|
11
|
-
// apuntalaria aquest cicle, i exposar aquest a l'API pública del shell la
|
|
12
|
-
// bloataria innecessàriament.
|
|
13
|
-
export const registerRequest =
|
|
14
|
-
(api: PrimariaApi, container: Container) => (command: IRequestClass<any>, handler: interfaces.Newable<any>) => {
|
|
15
|
-
container.bind(handler).to(handler).inTransientScope();
|
|
16
|
-
injectable()(handler);
|
|
17
|
-
const disposable = api.broker.registerRequest(command, (cmd: IRequest<any>) => {
|
|
18
|
-
const handlerInstance = container.get(handler);
|
|
19
|
-
return handlerInstance.handle(cmd);
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
dispose: () => {
|
|
23
|
-
container.isBound(handler) && container.unbind(handler);
|
|
24
|
-
disposable.dispose();
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
};
|
package/src/handle-plugins.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { BootstrappedPlugin, PluginDefinition, Plugin as PluginType } from "@uxland/harmonix";
|
|
2
|
-
import { bootstrapPlugins as pluginBootstrapper } from "@uxland/harmonix";
|
|
3
|
-
import { PrimariaApi, primariaApiFactory } from "./api/api";
|
|
4
|
-
export type { PluginDefinition, PluginInfo } from "@uxland/harmonix";
|
|
5
|
-
|
|
6
|
-
let bootstrappedPlugins = [] as BootstrappedPlugin<PrimariaApi>[];
|
|
7
|
-
|
|
8
|
-
export interface PrimariaPlugin extends Plugin {
|
|
9
|
-
startup: (api: PrimariaApi, startupParams: any) => Promise<void>;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface PrimariaStartupPlugin {
|
|
13
|
-
pluginId: string;
|
|
14
|
-
params: any;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface PrimariaBootstrappedPlugin extends BootstrappedPlugin<PrimariaApi> {
|
|
18
|
-
importedPlugin: PrimariaPlugin;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const CORE_FIRST_ID = "activity-history";
|
|
22
|
-
|
|
23
|
-
// activity-history must finish initializing before any other plugin: it
|
|
24
|
-
// registers the broker requests the rest depend on. In production it is loaded
|
|
25
|
-
// from the plugin store (versioned/uploadable) like any other plugin; this
|
|
26
|
-
// bundled copy is the fallback used when the caller does not provide it — e.g.
|
|
27
|
-
// third-party sandboxes that install primary-shell without a plugin store.
|
|
28
|
-
//
|
|
29
|
-
// The import stays inside the importer on purpose: importing it statically would
|
|
30
|
-
// evaluate the plugin's modules on shell load and register its custom elements,
|
|
31
|
-
// so the copy coming from the store would fail to define them again.
|
|
32
|
-
const bundledActivityHistory: PluginDefinition = {
|
|
33
|
-
pluginId: CORE_FIRST_ID,
|
|
34
|
-
importer: () => import("../../../plugins/activity-history/src/plugin"),
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
let pluginsBootstrapped = false;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Carrega i inicialitza els plugins. L'exporta el paquet perquè el host l'ha de cridar, i per
|
|
41
|
-
* això també el pot importar un plugin: només funciona una vegada, i no torna a funcionar fins
|
|
42
|
-
* que `disposePlugins` els ha desmuntat. Així un plugin no pot carregar-ne d'altres amb la
|
|
43
|
-
* identitat que vulgui.
|
|
44
|
-
*/
|
|
45
|
-
export const bootstrapPlugins = async (plugins: PluginDefinition[], startup?: PrimariaStartupPlugin) => {
|
|
46
|
-
if (pluginsBootstrapped) throw new Error("Plugins already bootstrapped");
|
|
47
|
-
pluginsBootstrapped = true;
|
|
48
|
-
const incoming = plugins ?? [];
|
|
49
|
-
const provided = incoming.filter((plugin) => plugin.pluginId === CORE_FIRST_ID);
|
|
50
|
-
const rest = incoming.filter((plugin) => plugin.pluginId !== CORE_FIRST_ID);
|
|
51
|
-
|
|
52
|
-
// Prefer the store/sandbox-provided activity-history; fall back to the bundled
|
|
53
|
-
// copy. Either way it is bootstrapped — and fully initialized — before the
|
|
54
|
-
// rest, which run in parallel as before.
|
|
55
|
-
const corePlugins = provided.length ? provided : [bundledActivityHistory];
|
|
56
|
-
|
|
57
|
-
const coreBootstrapped = (await pluginBootstrapper(corePlugins, primariaApiFactory)) as BootstrappedPlugin<PrimariaApi>[];
|
|
58
|
-
const restBootstrapped = rest.length
|
|
59
|
-
? ((await pluginBootstrapper(rest, primariaApiFactory)) as BootstrappedPlugin<PrimariaApi>[])
|
|
60
|
-
: [];
|
|
61
|
-
|
|
62
|
-
bootstrappedPlugins = [...coreBootstrapped, ...restBootstrapped];
|
|
63
|
-
handleStartupPlugin(bootstrappedPlugins as PrimariaBootstrappedPlugin[], startup);
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const handleStartupPlugin = (plugins: PrimariaBootstrappedPlugin[], startupPlugin?: PrimariaStartupPlugin) => {
|
|
67
|
-
if (plugins && plugins.length > 0 && startupPlugin?.pluginId) {
|
|
68
|
-
const plugin = plugins.find(
|
|
69
|
-
(plugin: PrimariaBootstrappedPlugin) => plugin?.apiInstance.pluginInfo.pluginId === startupPlugin.pluginId,
|
|
70
|
-
);
|
|
71
|
-
if (plugin?.importedPlugin?.startup) plugin?.importedPlugin?.startup?.(plugin.apiInstance, startupPlugin.params);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const disposePlugins = async () => {
|
|
76
|
-
const disposed = await Promise.all(bootstrappedPlugins.map((plugin: PrimariaBootstrappedPlugin) => plugin?.dispose()));
|
|
77
|
-
bootstrappedPlugins = [];
|
|
78
|
-
pluginsBootstrapped = false;
|
|
79
|
-
return disposed;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export type Plugin = PluginType<PrimariaApi>;
|