@uxland/primary-shell 7.49.2 → 7.50.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.
@@ -2,6 +2,11 @@ import { HarmonixRegionManager, HarmonixViewDefinition, IRegionManager } from '@
2
2
  import { PluginInfo } from '../../handle-plugins';
3
3
  import { PrimariaBroker } from '../broker/primaria-broker';
4
4
  import { activityHistoryRegions, administrativeManagementRegions, clinicalMonitoringRegions, shellRegions } from './regions';
5
+ /** Una vista de la region main, amb el plugin que l'ha registrada. */
6
+ export interface RegisteredMainView {
7
+ pluginId: string;
8
+ viewId: string;
9
+ }
5
10
  export interface PrimariaRegionManager extends HarmonixRegionManager {
6
11
  regions: {
7
12
  shell: typeof shellRegions;
@@ -15,6 +20,7 @@ export interface PrimariaRegionManager extends HarmonixRegionManager {
15
20
  activateMainView(viewId: string): Promise<void>;
16
21
  activatePluginView(regionName: string, pluginId: string, viewId: string): Promise<void>;
17
22
  getCurrentMainViewActive(): string | undefined;
23
+ getRegisteredMainViews(): RegisteredMainView[];
18
24
  _removeAllViews(): Promise<void>;
19
25
  _destroy(): Promise<void>;
20
26
  }
@@ -1,6 +1,7 @@
1
1
  export * from './bootstrapper';
2
2
  export * from './disposer';
3
3
  export * from './api/region-manager/regions';
4
+ export type { RegisteredMainView } from './api/region-manager/region-manager';
4
5
  export * from './handle-plugins';
5
6
  export type { PrimariaApi } from './api/api';
6
7
  export { PrimariaRegionHost, shellApi } from './api/api';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/primary-shell",
3
- "version": "7.49.2",
3
+ "version": "7.50.0",
4
4
  "description": "Primaria Shell",
5
5
  "author": "UXLand <dev@uxland.es>",
6
6
  "homepage": "https://github.com/uxland/harmonix/tree/app#readme",
@@ -125,6 +125,59 @@ describe("RegionManagerProxy", () => {
125
125
  expect(result).toBe("view1");
126
126
  });
127
127
 
128
+ describe("getRegisteredMainViews", () => {
129
+ // `id: undefined` vol dir una definicio que no en declara, no una amb l'id a undefined.
130
+ const registeredView = (key: string, id?: string) => ({
131
+ key,
132
+ view: id === undefined ? { factory: mockView.factory } : { ...mockView, id },
133
+ });
134
+
135
+ it("desglossa la clau del registry en pluginId i viewId", () => {
136
+ regionManager.getRegisteredViews.mockReturnValue([
137
+ registeredView("appointments::main", "main"),
138
+ registeredView("activity-history::timeline", "timeline"),
139
+ ]);
140
+
141
+ expect(proxy.getRegisteredMainViews()).toEqual([
142
+ { pluginId: "appointments", viewId: "main" },
143
+ { pluginId: "activity-history", viewId: "timeline" },
144
+ ]);
145
+ expect(regionManager.getRegisteredViews).toHaveBeenCalledWith(proxy.regions.shell.main);
146
+ });
147
+
148
+ /**
149
+ * El registry s'omple en registrar la vista; `getRegion(main).currentViews` només té
150
+ * les vistes afegides a un host ja muntat, i `getRegion` retorna `undefined` mentre la
151
+ * regio no hi es. Per aixo el metode no ha de dependre de la regio.
152
+ */
153
+ it("no depen que la regio main estigui muntada", () => {
154
+ regionManager.getRegion.mockReturnValue(undefined);
155
+ regionManager.getRegisteredViews.mockReturnValue([registeredView("appointments::main", "main")]);
156
+
157
+ expect(proxy.getRegisteredMainViews()).toEqual([{ pluginId: "appointments", viewId: "main" }]);
158
+ });
159
+
160
+ it("retorna una llista buida quan no hi ha res registrat", () => {
161
+ regionManager.getRegisteredViews.mockReturnValue([]);
162
+
163
+ expect(proxy.getRegisteredMainViews()).toEqual([]);
164
+ });
165
+
166
+ // Les vistes dels plugins de tercers (econsulta, allergies...) es poden registrar
167
+ // directament contra el regionManager, sense el prefix que hi posa aquest proxy.
168
+ it("deixa el pluginId buit si la clau no porta prefix de plugin", () => {
169
+ regionManager.getRegisteredViews.mockReturnValue([registeredView("legacy-view", "legacy-view")]);
170
+
171
+ expect(proxy.getRegisteredMainViews()).toEqual([{ pluginId: "", viewId: "legacy-view" }]);
172
+ });
173
+
174
+ it("cau a la clau quan la definicio no declara id", () => {
175
+ regionManager.getRegisteredViews.mockReturnValue([registeredView("appointments::main", undefined)]);
176
+
177
+ expect(proxy.getRegisteredMainViews()).toEqual([{ pluginId: "appointments", viewId: "main" }]);
178
+ });
179
+ });
180
+
128
181
  it("_destroy should call regionManager.destroy", () => {
129
182
  proxy._destroy();
130
183
  expect(regionManager.destroy).toHaveBeenCalled();
@@ -5,6 +5,12 @@ import { BROKER_EVENTS } from "../broker/broker-events";
5
5
  import { PrimariaBroker } from "../broker/primaria-broker";
6
6
  import { activityHistoryRegions, administrativeManagementRegions, clinicalMonitoringRegions, shellRegions } from "./regions";
7
7
 
8
+ /** Una vista de la region main, amb el plugin que l'ha registrada. */
9
+ export interface RegisteredMainView {
10
+ pluginId: string;
11
+ viewId: string;
12
+ }
13
+
8
14
  export interface PrimariaRegionManager extends HarmonixRegionManager {
9
15
  regions: {
10
16
  shell: typeof shellRegions;
@@ -18,6 +24,7 @@ export interface PrimariaRegionManager extends HarmonixRegionManager {
18
24
  activateMainView(viewId: string): Promise<void>;
19
25
  activatePluginView(regionName: string, pluginId: string, viewId: string): Promise<void>;
20
26
  getCurrentMainViewActive(): string | undefined;
27
+ getRegisteredMainViews(): RegisteredMainView[];
21
28
  _removeAllViews(): Promise<void>;
22
29
  _destroy(): Promise<void>;
23
30
  }
@@ -168,6 +175,32 @@ class RegionManagerProxy implements PrimariaRegionManager {
168
175
  return mainView?.id;
169
176
  }
170
177
 
178
+ /**
179
+ * Totes les vistes registrades a la region main, amb el plugin que les ha registrat.
180
+ *
181
+ * Va pel registry del regionManager i no per `getRegion(main).currentViews`, i és a
182
+ * propòsit: el registry s'omple en registrar la vista, mentre que `currentViews` només
183
+ * té les que s'han afegit a un host de regió ja muntat —i `getRegion` retorna
184
+ * `undefined` si la regió encara no hi és—, així que cridar-ho des de l'`initialize()`
185
+ * d'un plugin donaria una llista incompleta o petaria.
186
+ *
187
+ * Les claus del registry són `pluginId::viewId`. El `viewId` es llegeix de la
188
+ * definició, que és qui en manda; de la clau només se'n treu el prefix del plugin, que
189
+ * pot no ser-hi si la vista l'ha registrada un plugin de tercers directament contra el
190
+ * regionManager, sense passar per aquest proxy.
191
+ */
192
+ getRegisteredMainViews(): RegisteredMainView[] {
193
+ return this.regionManager.getRegisteredViews(this.regions.shell.main).map(({ key, view }) => {
194
+ const separatorIndex = key.indexOf("::");
195
+ const hasPluginPrefix = separatorIndex !== -1;
196
+
197
+ return {
198
+ pluginId: hasPluginPrefix ? key.slice(0, separatorIndex) : "",
199
+ viewId: (view as HarmonixViewDefinition).id ?? (hasPluginPrefix ? key.slice(separatorIndex + 2) : key),
200
+ };
201
+ });
202
+ }
203
+
171
204
  /**
172
205
  * Activates a view if it is marked as default and the region currently has no active views.
173
206
  *
package/src/index.ts CHANGED
@@ -5,12 +5,15 @@ import fontsCSS from "./UI/fonts/fonts.css?inline";
5
5
  // Inject CSS automatically
6
6
  if (typeof document !== "undefined") {
7
7
  const style = document.createElement("style");
8
- style.textContent = fontsCSS + "\n" + dssCSS;
8
+ style.textContent = `${fontsCSS}\n${dssCSS}`;
9
9
  document.head.appendChild(style);
10
10
  }
11
11
  export * from "./bootstrapper";
12
12
  export * from "./disposer";
13
13
  export * from "./api/region-manager/regions";
14
+ // Tipus de retorn de `regionManager.getRegisteredMainViews()`. El regionManager
15
+ // arriba als plugins tipat via `PrimariaApi`; això només és per poder-lo anomenar.
16
+ export type { RegisteredMainView } from "./api/region-manager/region-manager";
14
17
  export * from "./handle-plugins";
15
18
  // Superfície pública explícita: `primariaApiFactory`, `activityMonitor` i
16
19
  // `sessionRefreshTimer` són singletons interns del shell i no s'exposen.