@uxland/primary-shell 7.3.0 → 7.5.0

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.
Files changed (40) hide show
  1. package/dist/component-s17Jsk26.js +47 -0
  2. package/dist/component-s17Jsk26.js.map +1 -0
  3. package/dist/index-C3997nyY.js +45157 -0
  4. package/dist/index-C3997nyY.js.map +1 -0
  5. package/dist/index.js +18 -45079
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.umd.cjs +111 -94
  8. package/dist/index.umd.cjs.map +1 -1
  9. package/dist/primary/shell/src/UI/bootstrapper.d.ts +1 -1
  10. package/dist/primary/shell/src/UI/internal-views/handle-views.d.ts +1 -1
  11. package/dist/primary/shell/src/api/api.d.ts +4 -0
  12. package/dist/primary/shell/src/api/import-data-manager/component/component.d.ts +15 -0
  13. package/dist/primary/shell/src/api/import-data-manager/component/template.d.ts +2 -0
  14. package/dist/primary/shell/src/api/import-data-manager/import-data-manager-impl.d.ts +27 -0
  15. package/dist/primary/shell/src/api/import-data-manager/import-data-manager-impl.test.d.ts +1 -0
  16. package/dist/primary/shell/src/api/import-data-manager/import-data-manager.d.ts +19 -0
  17. package/dist/primary/shell/src/api/import-data-manager/index.d.ts +2 -0
  18. package/dist/primary/shell/src/api/region-manager/regions.d.ts +1 -0
  19. package/dist/primary/shell/src/api/user-manager/user-manager.d.ts +12 -0
  20. package/dist/primary/shell/src/bootstrapper.d.ts +1 -1
  21. package/dist/primary/shell/src/handle-plugins.d.ts +1 -1
  22. package/dist/primary/shell/src/locales.d.ts +8 -0
  23. package/package.json +1 -1
  24. package/src/UI/bootstrapper.ts +2 -2
  25. package/src/UI/internal-views/handle-views.ts +4 -3
  26. package/src/api/api.ts +8 -0
  27. package/src/api/import-data-manager/component/component.ts +34 -0
  28. package/src/api/import-data-manager/component/styles.css +58 -0
  29. package/src/api/import-data-manager/component/template.ts +24 -0
  30. package/src/api/import-data-manager/import-data-manager-impl.test.ts +282 -0
  31. package/src/api/import-data-manager/import-data-manager-impl.ts +80 -0
  32. package/src/api/import-data-manager/import-data-manager.ts +15 -0
  33. package/src/api/import-data-manager/index.ts +2 -0
  34. package/src/api/region-manager/regions.ts +1 -0
  35. package/src/api/user-manager/user-manager.ts +45 -0
  36. package/src/bootstrapper.ts +2 -2
  37. package/src/handle-plugins.ts +6 -6
  38. package/src/locales.ts +9 -0
  39. package/dist/primary/shell/src/domain/is-user-role-administrative.d.ts +0 -1
  40. package/src/domain/is-user-role-administrative.ts +0 -1
@@ -0,0 +1,80 @@
1
+ import { PrimariaImportDataManager } from './import-data-manager';
2
+ import { PrimariaInteractionService } from '../interaction-service/interaction-service';
3
+
4
+ export class ImportDataManagerImpl implements PrimariaImportDataManager {
5
+ private selectedItems: Record<string, any[]> = {};
6
+ private currentImporterId = '';
7
+ private pluginTexts: Record<string, {raw: string, html: string}> = {};
8
+
9
+ constructor(private interactionService: PrimariaInteractionService) {}
10
+
11
+ async import(importerId: string): Promise<{
12
+ accepted: boolean;
13
+ data: Record<string, any[]>;
14
+ text: {raw: string, html: string};
15
+ }> {
16
+ this.currentImporterId = importerId;
17
+ this.selectedItems = {};
18
+ this.pluginTexts = {};
19
+
20
+ try {
21
+ // Import component dynamically to avoid circular dependency
22
+ const { ImportDataManagerModal } = await import("./component/component");
23
+
24
+ const { confirmed } = await this.interactionService.confirm(
25
+ undefined,
26
+ { component: ImportDataManagerModal as any },
27
+ {
28
+ fullCustomization: true,
29
+ },
30
+ );
31
+
32
+ const concatenatedText = this.getConcatenatedText();
33
+
34
+ const finalResult = {
35
+ accepted: confirmed,
36
+ data: confirmed ? this.selectedItems : {},
37
+ text: confirmed ? concatenatedText : {raw: '', html: ''}
38
+ };
39
+
40
+ this.selectedItems = {};
41
+ this.currentImporterId = '';
42
+ this.pluginTexts = {};
43
+
44
+ return finalResult;
45
+ } catch (error) {
46
+ this.selectedItems = {};
47
+ this.currentImporterId = '';
48
+ this.pluginTexts = {};
49
+ throw error;
50
+ }
51
+ }
52
+
53
+ selectItems(payload: {
54
+ pluginId: string,
55
+ data: any[],
56
+ text: {raw: string, html: string}
57
+ }): void {
58
+ this.selectedItems[payload.pluginId] = payload.data;
59
+ this.pluginTexts[payload.pluginId] = payload.text;
60
+ }
61
+
62
+ getCurrentImporterId(): string {
63
+ return this.currentImporterId;
64
+ }
65
+
66
+ private getConcatenatedText(): {raw: string, html: string} {
67
+ const rawTexts: string[] = [];
68
+ const htmlTexts: string[] = [];
69
+
70
+ for (const text of Object.values(this.pluginTexts)) {
71
+ if (text.raw) rawTexts.push(text.raw);
72
+ if (text.html) htmlTexts.push(text.html);
73
+ }
74
+
75
+ return {
76
+ raw: rawTexts.join('\n\n'),
77
+ html: htmlTexts.join('<br><br>')
78
+ };
79
+ }
80
+ }
@@ -0,0 +1,15 @@
1
+ export interface PrimariaImportDataManager {
2
+ import(importerId: string): Promise<{
3
+ accepted: boolean;
4
+ data: Record<string, any[]>;
5
+ text: {raw: string, html: string};
6
+ }>;
7
+
8
+ selectItems(payload: {
9
+ pluginId: string,
10
+ data: any[],
11
+ text: {raw: string, html: string}
12
+ }): void;
13
+
14
+ getCurrentImporterId(): string;
15
+ }
@@ -0,0 +1,2 @@
1
+ export * from './import-data-manager';
2
+ export * from './import-data-manager-impl';
@@ -7,6 +7,7 @@ export const shellRegions = {
7
7
  quickActions: "quick-actions-region",
8
8
  floating: "floating-region",
9
9
  communicationSidenav: "communication-sidenav-region",
10
+ importData: "import-data-region",
10
11
  };
11
12
 
12
13
  export const clinicalMonitoringRegions = {
@@ -0,0 +1,45 @@
1
+ import { jwtDecode } from "jwt-decode";
2
+ import { TokenManager } from "../token-manager/token-manager";
3
+
4
+ interface JWTPayload {
5
+ access_info?: {
6
+ role_type?: string;
7
+ };
8
+ }
9
+
10
+ export interface UserManager {
11
+ getRole: () => string | undefined;
12
+ isUserRoleAdministrative: () => boolean;
13
+ }
14
+
15
+ export class UserManagerImpl implements UserManager {
16
+ constructor(private tokenManager: TokenManager) {}
17
+
18
+ getRole = (): string | undefined => {
19
+ const token = this.tokenManager.getToken();
20
+ if (!token) {
21
+ return undefined;
22
+ }
23
+
24
+ try {
25
+ const payload = jwtDecode<JWTPayload>(token);
26
+ const role = payload.access_info?.role_type;
27
+ return role;
28
+ } catch (error) {
29
+ console.error("Error decoding JWT token:", error);
30
+ return undefined;
31
+ }
32
+ };
33
+
34
+ isUserRoleAdministrative = (): boolean => {
35
+ const userRole = this.getRole();
36
+ return userRole === "ADM";
37
+ };
38
+ }
39
+
40
+ let userManager: UserManager;
41
+ export const createUserManager = (tokenManager: TokenManager): UserManager => {
42
+ if (userManager) return userManager;
43
+ userManager = new UserManagerImpl(tokenManager);
44
+ return userManager;
45
+ };
@@ -4,9 +4,9 @@ import { useFeatures } from "./features/bootstrapper";
4
4
  import { useLocalization } from "./locales";
5
5
  import { useUI } from "./UI/bootstrapper";
6
6
 
7
- export const initializeShell = (hostAppElement: HTMLElement, userRole?: string) => {
7
+ export const initializeShell = (hostAppElement: HTMLElement) => {
8
8
  useLocalization(shellApi);
9
- useUI(userRole);
9
+ useUI();
10
10
  useFeatures(shellApi);
11
11
  const shell = new PrimariaShell();
12
12
  hostAppElement.appendChild(shell as any);
@@ -13,8 +13,7 @@ import {
13
13
  initialize as adminClinicalMonitoringInitialize,
14
14
  dispose as adminClinicalMonitoringDispose,
15
15
  } from "../../../plugins/admin-clinical-monitoring/src/plugin";
16
- import { PrimariaApi, primariaApiFactory } from "./api/api";
17
- import { isUserRoleAdministrative } from "./domain/is-user-role-administrative";
16
+ import { PrimariaApi, primariaApiFactory, shellApi } from "./api/api";
18
17
 
19
18
  let bootstrappedPlugins = [] as BootstrappedPlugin[];
20
19
 
@@ -51,15 +50,16 @@ const administrativeInternalPlugins: PluginDefinition[] = [
51
50
  },
52
51
  ];
53
52
 
54
- const getPluginsByUserRole = (userRole?: string) => {
55
- if (isUserRoleAdministrative(userRole)) {
53
+ const getPluginsByUserRole = (isUserRoleAdministrative: boolean) => {
54
+ if (isUserRoleAdministrative) {
56
55
  return commonPlugins.concat(administrativeInternalPlugins);
57
56
  }
58
57
  return commonPlugins.concat(doctorInternalPlugins);
59
58
  };
60
59
 
61
- export const bootstrapPlugins = async (plugins: PluginDefinition[], userRole?: string) => {
62
- const internalPlugins = getPluginsByUserRole(userRole);
60
+ export const bootstrapPlugins = async (plugins: PluginDefinition[]) => {
61
+ const isUserRoleAdministrative = shellApi.userManager.isUserRoleAdministrative();
62
+ const internalPlugins = getPluginsByUserRole(isUserRoleAdministrative);
63
63
  const finalPlugins = internalPlugins.concat(plugins || []);
64
64
  bootstrappedPlugins = await pluginBootstrapper(finalPlugins, primariaApiFactory);
65
65
  };
package/src/locales.ts CHANGED
@@ -25,6 +25,8 @@ export const translate = (path: ShellLocales) => {
25
25
 
26
26
  export { shellLocaleManager };
27
27
 
28
+ const defaultLang = "ca";
29
+
28
30
  export const locales = {
29
31
  ca: {
30
32
  [primariaShellId]: {
@@ -61,6 +63,13 @@ export const locales = {
61
63
  pdfVisor: {
62
64
  noPdfSelected: "No hi ha cap PDF seleccionat",
63
65
  },
66
+ importDataManager:{
67
+ title: "Importar dades",
68
+ actions: {
69
+ cancel: "Cancel·lar",
70
+ import: "Importar dades",
71
+ }
72
+ }
64
73
  },
65
74
  },
66
75
  };
@@ -1 +0,0 @@
1
- export declare const isUserRoleAdministrative: (userRole?: string) => userRole is "ADM";
@@ -1 +0,0 @@
1
- export const isUserRoleAdministrative = (userRole?: string) => userRole === "ADM";