This is an automated email from the ASF dual-hosted git repository.

porcelli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git


The following commit(s) were added to refs/heads/main by this push:
     new 09bf0a69ce6 NO-ISSUE: DMN Editor: Blank screen with DMN models 1.1 
(#2379)
09bf0a69ce6 is described below

commit 09bf0a69ce6fd625ab89ce2ae81d68e562fbaaf1
Author: Daniel José dos Santos <[email protected]>
AuthorDate: Tue May 28 18:07:13 2024 -0300

    NO-ISSUE: DMN Editor: Blank screen with DMN models 1.1 (#2379)
---
 packages/dmn-editor-envelope/package.json          |  1 +
 packages/dmn-editor-envelope/src/DmnEditorRoot.tsx | 46 ++++++++++++++++++----
 packages/dmn-editor/src/DmnEditorErrorFallback.tsx |  1 -
 pnpm-lock.yaml                                     |  5 ++-
 4 files changed, 44 insertions(+), 9 deletions(-)

diff --git a/packages/dmn-editor-envelope/package.json 
b/packages/dmn-editor-envelope/package.json
index 44963a5078a..bc897c8afb1 100644
--- a/packages/dmn-editor-envelope/package.json
+++ b/packages/dmn-editor-envelope/package.json
@@ -36,6 +36,7 @@
     "@kie-tools/dmn-marshaller": "workspace:*",
     "@kie-tools/pmml-editor-marshaller": "workspace:*",
     "@kie-tools/xml-parser-ts": "workspace:*",
+    "@patternfly/react-core": "^4.276.6",
     "react": "^17.0.2",
     "react-dom": "^17.0.2"
   },
diff --git a/packages/dmn-editor-envelope/src/DmnEditorRoot.tsx 
b/packages/dmn-editor-envelope/src/DmnEditorRoot.tsx
index bfb9d1f0418..2cb5e5dafd7 100644
--- a/packages/dmn-editor-envelope/src/DmnEditorRoot.tsx
+++ b/packages/dmn-editor-envelope/src/DmnEditorRoot.tsx
@@ -19,9 +19,10 @@
 
 import * as __path from "path";
 import * as React from "react";
+import { useEffect, useMemo, useState } from "react";
 import * as DmnEditor from "@kie-tools/dmn-editor/dist/DmnEditor";
-import { Normalized, normalize } from 
"@kie-tools/dmn-editor/dist/normalization/normalize";
-import { getMarshaller } from "@kie-tools/dmn-marshaller";
+import { normalize, Normalized } from 
"@kie-tools/dmn-editor/dist/normalization/normalize";
+import { DMN_LATEST_VERSION, DmnLatestModel, DmnMarshaller, getMarshaller } 
from "@kie-tools/dmn-marshaller";
 import { generateUuid } from "@kie-tools/boxed-expression-component/dist/api";
 import {
   ContentType,
@@ -31,10 +32,8 @@ import {
   WorkspaceEdit,
 } from "@kie-tools-core/workspace/dist/api";
 import { DMN15_SPEC } from 
"@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/Dmn15Spec";
-import { DMN_LATEST_VERSION, DmnLatestModel, DmnMarshaller } from 
"@kie-tools/dmn-marshaller";
 import { domParser } from "@kie-tools/xml-parser-ts";
 import { ns as dmn15ns } from 
"@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/meta";
-import { useEffect, useMemo, useState } from "react";
 import { XML2PMML } from "@kie-tools/pmml-editor-marshaller";
 import { getPmmlNamespace } from "@kie-tools/dmn-editor/dist/pmml/pmml";
 import { getNamespaceOfDmnImport } from 
"@kie-tools/dmn-editor/dist/includedModels/importNamespaces";
@@ -43,6 +42,9 @@ import {
   PromiseImperativeHandle,
 } from "@kie-tools-core/react-hooks/dist/useImperativePromiseHandler";
 import { KeyboardShortcutsService } from 
"@kie-tools-core/keyboard-shortcuts/dist/envelope/KeyboardShortcutsService";
+import { Flex } from "@patternfly/react-core/dist/js/layouts/Flex";
+import { EmptyState, EmptyStateBody, EmptyStateIcon } from 
"@patternfly/react-core/dist/js/components/EmptyState";
+import { Title } from "@patternfly/react-core/dist/js/components/Title";
 
 export const EXTERNAL_MODELS_SEARCH_GLOB_PATTERN = "**/*.{dmn,pmml}";
 
@@ -75,6 +77,7 @@ export type DmnEditorRootState = {
   externalModelsManagerDoneBootstraping: boolean;
   keyboardShortcutsRegisterIds: number[];
   keyboardShortcutsRegistred: boolean;
+  error: Error | undefined;
 };
 
 export class DmnEditorRoot extends React.Component<DmnEditorRootProps, 
DmnEditorRootState> {
@@ -96,6 +99,7 @@ export class DmnEditorRoot extends 
React.Component<DmnEditorRootProps, DmnEditor
       externalModelsManagerDoneBootstraping: false,
       keyboardShortcutsRegisterIds: [],
       keyboardShortcutsRegistred: false,
+      error: undefined,
     };
   }
 
@@ -127,7 +131,7 @@ export class DmnEditorRoot extends 
React.Component<DmnEditorRootProps, DmnEditor
     openFilenormalizedPosixPathRelativeToTheWorkspaceRoot: string,
     content: string
   ): Promise<void> {
-    const marshaller = getMarshaller(content || EMPTY_DMN(), { upgradeTo: 
"latest" });
+    const marshaller = this.getMarshaller(content);
 
     // Save stack
     let savedStackPointer: Normalized<DmnLatestModel>[] = [];
@@ -177,12 +181,24 @@ export class DmnEditorRoot extends 
React.Component<DmnEditorRootProps, DmnEditor
     });
   }
 
-  // Internal methods
-
   public get model(): Normalized<DmnLatestModel> | undefined {
     return this.state.stack[this.state.pointer];
   }
 
+  // Internal methods
+
+  private getMarshaller(content: string) {
+    try {
+      return getMarshaller(content || EMPTY_DMN(), { upgradeTo: "latest" });
+    } catch (e) {
+      this.setState((s) => ({
+        ...s,
+        error: e,
+      }));
+      throw e;
+    }
+  }
+
   private setExternalModelsByNamespace = (externalModelsByNamespace: 
DmnEditor.ExternalModelsIndex) => {
     this.setState((prev) => ({ ...prev, externalModelsByNamespace }));
   };
@@ -455,6 +471,7 @@ export class DmnEditorRoot extends 
React.Component<DmnEditorRootProps, DmnEditor
   public render() {
     return (
       <>
+        {this.state.error && <DmnMarshallerFallbackError 
error={this.state.error} />}
         {this.model && (
           <>
             <DmnEditor.DmnEditor
@@ -648,3 +665,18 @@ function ExternalModelsManager({
 
   return <></>;
 }
+
+function DmnMarshallerFallbackError({ error }: { error: Error }) {
+  return (
+    <Flex justifyContent={{ default: "justifyContentCenter" }} style={{ 
marginTop: "100px" }}>
+      <EmptyState style={{ maxWidth: "1280px" }}>
+        <EmptyStateIcon icon={() => <div style={{ fontSize: "3em" }}>😕</div>} 
/>
+        <Title size={"lg"} headingLevel={"h4"}>
+          Unable to open file.
+        </Title>
+        <br />
+        <EmptyStateBody>Error details: {error.message}</EmptyStateBody>
+      </EmptyState>
+    </Flex>
+  );
+}
diff --git a/packages/dmn-editor/src/DmnEditorErrorFallback.tsx 
b/packages/dmn-editor/src/DmnEditorErrorFallback.tsx
index 3b18a217643..2a2cdc26ad6 100644
--- a/packages/dmn-editor/src/DmnEditorErrorFallback.tsx
+++ b/packages/dmn-editor/src/DmnEditorErrorFallback.tsx
@@ -19,7 +19,6 @@
 
 import * as React from "react";
 import { useDmnEditor } from "./DmnEditorContext";
-import { Bullseye } from "@patternfly/react-core/dist/js/layouts/Bullseye";
 import { Flex } from "@patternfly/react-core/dist/js/layouts/Flex";
 import {
   EmptyState,
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 04da3543cf4..186b2ed6ca4 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -3679,6 +3679,9 @@ importers:
       "@kie-tools/xml-parser-ts":
         specifier: workspace:*
         version: link:../xml-parser-ts
+      "@patternfly/react-core":
+        specifier: ^4.276.6
+        version: 4.276.6([email protected])([email protected])
       react:
         specifier: ^17.0.2
         version: 17.0.2
@@ -24051,7 +24054,7 @@ packages:
       react-dom: 17.0.2([email protected])
       react-dropzone: 11.7.1([email protected])
       tippy.js: 5.1.2
-      tslib: 2.5.0
+      tslib: 2.6.2
 
   /@patternfly/[email protected]([email protected])([email protected]):
     resolution:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to