@gisce/react-ooui 1.1.62 → 1.1.63-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.
@@ -1 +1 @@
1
- {"version":3,"file":"ActionErrorDialog.d.ts","sourceRoot":"","sources":["ActionErrorDialog.tsx"],"names":[],"mappings":"AAMA,QAAA,MAAM,UAAU,QAAS,MAAM,SAgC9B,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"ActionErrorDialog.d.ts","sourceRoot":"","sources":["ActionErrorDialog.tsx"],"names":[],"mappings":"AAOA,QAAA,MAAM,UAAU,QAAS,MAAM,SAc9B,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare const ErrorAlert: ({ error, className, }: {
3
+ error: any;
4
+ className: string;
5
+ }) => JSX.Element;
6
+ //# sourceMappingURL=ErrorAlert.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorAlert.d.ts","sourceRoot":"","sources":["ErrorAlert.tsx"],"names":[],"mappings":";AAKA,eAAO,MAAM,UAAU;WAId,GAAG;eACC,MAAM;iBA0BlB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"ActionView.d.ts","sourceRoot":"","sources":["ActionView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAIf,OAAO,EAIL,eAAe,EAGf,QAAQ,EACT,MAAM,eAAe,CAAC;AAkBvB,aAAK,KAAK,GAAG;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;IAC7B,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;;AA4bF,wBAAsC"}
1
+ {"version":3,"file":"ActionView.d.ts","sourceRoot":"","sources":["ActionView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAIf,OAAO,EAIL,eAAe,EAGf,QAAQ,EACT,MAAM,eAAe,CAAC;AAkBvB,aAAK,KAAK,GAAG;IACX,MAAM,EAAE,GAAG,CAAC;IACZ,OAAO,EAAE,GAAG,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,WAAW,EAAE,eAAe,CAAC;IAC7B,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;;AAgcF,wBAAsC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["Form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AAkC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 function ChangeViewButton(props: Props) {
57
57
  {getIconForView(view)}
58
58
  </Col>
59
59
  <Col flex="auto" style={{ paddingRight: 20 }}>
60
- {view.type === "graph"
61
- ? (view as GraphView).name
62
- : view.type.charAt(0).toUpperCase() + view.type.slice(1)}
60
+ {view.type.charAt(0).toUpperCase() + view.type.slice(1)}
63
61
  </Col>
64
62
  <Col flex="none">
65
63
  <CheckOutlined
@@ -78,15 +78,6 @@ function FormActionBar({ toolbar }: { toolbar: any }) {
78
78
  TabManagerContext
79
79
  ) as TabManagerContextType;
80
80
  const { openRelate, openDefaultActionForModel } = tabManagerContext || {};
81
- const prevFormIsSavingRef = useRef<boolean>(false);
82
-
83
- useEffect(() => {
84
- if (!formIsSaving && prevFormIsSavingRef.current) {
85
- message.success(t("savedRegisters"));
86
- }
87
-
88
- prevFormIsSavingRef.current = formIsSaving || false;
89
- }, [formIsSaving]);
90
81
 
91
82
  function tryRefresh(callback: any) {
92
83
  if (formHasChanges) {
@@ -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);
@@ -0,0 +1,27 @@
1
+ export const parseError = (errorResponse: string) => {
2
+ let message;
3
+ let type;
4
+ let title;
5
+
6
+ if (
7
+ typeof errorResponse === "string" &&
8
+ errorResponse.indexOf(" -- ") !== -1 &&
9
+ errorResponse.indexOf("\n\n") !== -1
10
+ ) {
11
+ const splitted = errorResponse.split("\n\n");
12
+ message = splitted[1].replace(/\n/g, "<br />");
13
+ const args = splitted[0].split(" -- ");
14
+ type = args[0];
15
+ title = args[1];
16
+ } else {
17
+ message = errorResponse;
18
+ type = "error";
19
+ title = "Error";
20
+ }
21
+
22
+ return {
23
+ type,
24
+ message,
25
+ title,
26
+ };
27
+ };
@@ -1,38 +1,21 @@
1
1
  import React from "react";
2
2
  import { Modal } from "antd";
3
3
  import { ExclamationCircleOutlined, WarningOutlined } from "@ant-design/icons";
4
+ import { parseError } from "@/helpers/errorHelper";
4
5
 
5
6
  const { error, warning } = Modal;
6
7
 
7
8
  const showDialog = (err: string) => {
8
- let message;
9
- let type;
10
- let title;
9
+ const { message, type, title } = parseError(err);
11
10
 
12
- if (
13
- typeof err === "string" &&
14
- err.indexOf(" -- ") !== -1 &&
15
- err.indexOf("\n\n") !== -1
16
- ) {
17
- const splitted = err.split("\n\n");
18
- message = splitted[1];
19
- const args = splitted[0].split(" -- ");
20
- type = args[0];
21
- title = args[1];
22
- } else {
23
- message = err;
24
- type = "error";
25
- title = "Error";
26
- }
27
-
28
- const icon =
11
+ const iconComponent =
29
12
  type === "error" ? <ExclamationCircleOutlined /> : <WarningOutlined />;
30
13
 
31
14
  const modalType = type === "error" ? error : warning;
32
15
 
33
16
  modalType({
34
17
  title,
35
- icon,
18
+ icon: iconComponent,
36
19
  centered: true,
37
20
  content: message,
38
21
  });
@@ -0,0 +1,37 @@
1
+ import { parseError } from "@/helpers/errorHelper";
2
+ import { Alert } from "antd";
3
+ import React from "react";
4
+ import { Interweave } from "interweave";
5
+
6
+ export const ErrorAlert = ({
7
+ error,
8
+ className,
9
+ }: {
10
+ error: any;
11
+ className: string;
12
+ }) => {
13
+ let messageContent;
14
+ let messageType = "error";
15
+
16
+ if (
17
+ typeof error === "string" &&
18
+ error.indexOf(" -- ") !== -1 &&
19
+ error.indexOf("\n\n") !== -1
20
+ ) {
21
+ const { message, type, title } = parseError(error);
22
+ messageContent = <Interweave content={`${title}<br />${message}`} />;
23
+ messageType = type;
24
+ } else {
25
+ messageContent = error.message
26
+ ? JSON.stringify(error.message)
27
+ : JSON.stringify(error);
28
+ }
29
+ return (
30
+ <Alert
31
+ className={className}
32
+ message={messageContent}
33
+ type={messageType as any}
34
+ banner
35
+ />
36
+ );
37
+ };
@@ -107,6 +107,7 @@ function ActionView(props: Props, ref: any) {
107
107
  tabs,
108
108
  activeKey,
109
109
  openAction,
110
+ onRemoveTab,
110
111
  } = tabManagerContext || {};
111
112
 
112
113
  useHotkeys(
@@ -240,8 +241,9 @@ function ActionView(props: Props, ref: any) {
240
241
 
241
242
  if (!currentViewToAssign) {
242
243
  showErrorDialog(
243
- "Error determining the first view to show.\nPlease, make sure the view ids on the fields_view_get responses are the same as the ones defined in the action"
244
+ `Error determining the first view to show for model ${model}.\nPlease, make sure the view ids on the fields_view_get responses are the same as the ones defined in the action`
244
245
  );
246
+ onRemoveTab?.(tabKey);
245
247
  }
246
248
 
247
249
  setCurrentView(currentViewToAssign);
@@ -279,7 +281,9 @@ function ActionView(props: Props, ref: any) {
279
281
  }, [tabs, activeKey]);
280
282
 
281
283
  async function canWeClose() {
282
- if (currentView!.type === "form") {
284
+ if (!currentView) {
285
+ return true;
286
+ } else if (currentView!.type === "form") {
283
287
  return await (formRef.current as any).cancelUnsavedChanges();
284
288
  } else {
285
289
  return true;
@@ -55,6 +55,7 @@ import {
55
55
  ContentRootContextType,
56
56
  } from "@/context/ContentRootContext";
57
57
  import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
58
+ import { ErrorAlert } from "@/ui/ErrorAlert";
58
59
 
59
60
  export type FormProps = {
60
61
  model: string;
@@ -635,6 +636,7 @@ function Form(props: FormProps, ref: any) {
635
636
 
636
637
  await fetchValues();
637
638
  submitSucceed = true;
639
+ message.success(t("savedRegisters"));
638
640
  } catch (err) {
639
641
  formSubmitting.current = false;
640
642
  setIsSubmitting(false);
@@ -869,6 +871,10 @@ function Form(props: FormProps, ref: any) {
869
871
  model,
870
872
  action,
871
873
  payload: getCurrentId()!,
874
+ context: {
875
+ ...parentContext,
876
+ ...formOoui?.context,
877
+ },
872
878
  });
873
879
 
874
880
  if (response.type && response.type === "ir.actions.act_window_close") {
@@ -1058,14 +1064,7 @@ function Form(props: FormProps, ref: any) {
1058
1064
  >
1059
1065
  {({ measureRef }) => (
1060
1066
  <div className="pb-2" ref={measureRef}>
1061
- {error && (
1062
- <Alert
1063
- className="mt-10 mb-20"
1064
- message={JSON.stringify(error)}
1065
- type="error"
1066
- banner
1067
- />
1068
- )}
1067
+ {error && <ErrorAlert className="mt-10 mb-20" error={error} />}
1069
1068
  {content()}
1070
1069
  {showFooter && footer()}
1071
1070
  </div>