@gisce/react-ooui 1.1.57 → 1.1.58-rc.1

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": "@gisce/react-ooui",
3
- "version": "1.1.57",
3
+ "version": "1.1.58-rc.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "src",
@@ -1,4 +1,4 @@
1
- import { FormView, GenerateReportOptions } from "@/types";
1
+ import { FormView, GenerateReportOptions, ViewType } from "@/types";
2
2
  import React, {
3
3
  useContext,
4
4
  useRef,
@@ -261,33 +261,12 @@ const ContentRootProvider = (
261
261
 
262
262
  return {};
263
263
  } else {
264
- let initialView;
265
- const viewTypes = actionData.view_mode.split(",");
266
- const views = [];
267
-
268
- for (const viewType of viewTypes) {
269
- const viewData = await ConnectionProvider.getHandler().getView({
270
- model: actionData.res_model,
271
- type: viewType,
272
- context: mergedContext,
273
- });
274
- views.push([viewData.view_id, viewType]);
275
- }
276
-
277
- if (!actionData.view_id) {
278
- const type = actionData.view_mode.split(",")[0];
279
-
280
- const [retrievedViewId] = views.find(
281
- ([_, viewType]) => viewType === type
282
- )!;
283
-
284
- initialView = { id: retrievedViewId, type };
285
- } else {
286
- initialView = {
287
- id: actionData.view_id,
288
- type: actionData.view_mode.split(",")[0],
289
- };
290
- }
264
+ const { initialView, views } = await getViewsAndInitialView({
265
+ model: actionData.res_model,
266
+ context: mergedContext,
267
+ view_mode: actionData.view_mode,
268
+ views: actionData.views,
269
+ });
291
270
 
292
271
  openAction?.({
293
272
  target: "current",
@@ -415,4 +394,61 @@ const ContentRootProvider = (
415
394
  );
416
395
  };
417
396
 
397
+ async function getViewsAndInitialView({
398
+ views,
399
+ view_mode,
400
+ model,
401
+ context,
402
+ view_id,
403
+ }: {
404
+ views: any[];
405
+ view_mode: string;
406
+ model: string;
407
+ context: any;
408
+ view_id?: number;
409
+ }) {
410
+ const retriedViewData = [];
411
+ let initialView;
412
+
413
+ if (views) {
414
+ for (const view of views) {
415
+ const viewData = await ConnectionProvider.getHandler().getView({
416
+ model,
417
+ type: view[1],
418
+ id: view[0],
419
+ context,
420
+ });
421
+ retriedViewData.push([viewData.view_id, view[1]]);
422
+ }
423
+ } else {
424
+ const viewTypes = view_mode.split(",");
425
+ for (const viewType of viewTypes) {
426
+ const viewData = await ConnectionProvider.getHandler().getView({
427
+ model,
428
+ type: viewType as ViewType,
429
+ context,
430
+ });
431
+ retriedViewData.push([viewData.view_id, viewType]);
432
+ }
433
+ }
434
+ if (views && views.length > 0) {
435
+ const { id, type } = views[0];
436
+ initialView = {
437
+ id,
438
+ type,
439
+ };
440
+ } else if (!view_id) {
441
+ const type = view_mode.split(",")[0];
442
+ const [retrievedViewId] = views.find(([_, viewType]) => viewType === type)!;
443
+ initialView = { id: retrievedViewId, type };
444
+ } else {
445
+ initialView = {
446
+ id: view_id,
447
+ type: view_mode.split(",")[0],
448
+ };
449
+ }
450
+
451
+ return { views: retriedViewData, initialView };
452
+ }
453
+
418
454
  export default forwardRef(ContentRootProvider);