tiagobento commented on code in PR #2508:
URL:
https://github.com/apache/incubator-kie-tools/pull/2508#discussion_r1765764491
##########
packages/dmn-editor/src/externalNodes/DmnObjectListItem.tsx:
##########
@@ -50,14 +52,70 @@ export function DmnObjectListItem({
);
const isAlternativeInputDataShape = useDmnEditorStore((s) =>
s.computed(s).isAlternativeInputDataShape());
- const displayName = dmnObject
- ? buildFeelQNameFromNamespace({
- namedElement: dmnObject,
- importsByNamespace,
- namespace,
- relativeToNamespace,
- }).full
- : dmnObjectHref;
+ // The dmnObject represented here can be a node from a 3rd model that is not
included in this model.
+ // For example, consider a "Local Decision Service" with an encapsulated
"Decision-A" from "Model A",
+ // but that "Decision-A" have an "Input-B" that is from "Model B", which is
not included in local model.
+ //
+ // Model Name: Local Model.dmn
+ // Nodes: Local Decision Service
+ // Included Models: Model-A.dmn
+ //
+ // Model Name: Model-A.dmn
+ // Nodes: Decision-A
+ // Included Models: Model-B.dmn
+ //
+ // Model Name: Model-B.dmn
+ // Nodes: Input-B
+ // Included Models: [none]
+ //
+ // So, the "Local Model" only "knows" the nodes from "Model-A" and NOT from
"Model-B".
+ // That's why we have different logic to build description for "known
dmnObjects" and "unknown dmnObjects".
+ const isNamespaceDirectlyIncluded = useMemo(
+ () => namespace === relativeToNamespace ||
importsByNamespace.has(namespace),
+ [importsByNamespace, namespace, relativeToNamespace]
+ );
+
+ const transitivelyIncludedNamespaceDescription = useMemo(() => {
+ return `${namespace.substring(0,
11)}...${namespace.substring(namespace.length - 4)}`;
+ }, [namespace]);
+
+ const displayName = useMemo(
+ () =>
+ dmnObject && isNamespaceDirectlyIncluded
+ ? buildFeelQNameFromNamespace({
+ namedElement: dmnObject,
+ importsByNamespace,
+ namespace,
+ relativeToNamespace,
+ }).full
+ : dmnObject?.["@_name"],
+ [dmnObject, importsByNamespace, isNamespaceDirectlyIncluded, namespace,
relativeToNamespace]
+ );
+
+ const nodeTypeTooltipDescription = useMemo(() => {
+ if (dmnObject === undefined) {
+ throw new Error("nodeTypeDescription can't be defined without a DMN
object");
Review Comment:
Yeah, the name `dmnObject` is definitely sub-optimal. That's on me, though.
We just need to be careful to not crash the editor over an error like this.
Let's define to the "Unknown" string and remove both `throw`s please.
@danielzhe
##########
packages/dmn-editor/src/externalNodes/DmnObjectListItem.tsx:
##########
@@ -50,14 +52,70 @@ export function DmnObjectListItem({
);
const isAlternativeInputDataShape = useDmnEditorStore((s) =>
s.computed(s).isAlternativeInputDataShape());
- const displayName = dmnObject
- ? buildFeelQNameFromNamespace({
- namedElement: dmnObject,
- importsByNamespace,
- namespace,
- relativeToNamespace,
- }).full
- : dmnObjectHref;
+ // The dmnObject represented here can be a node from a 3rd model that is not
included in this model.
+ // For example, consider a "Local Decision Service" with an encapsulated
"Decision-A" from "Model A",
+ // but that "Decision-A" have an "Input-B" that is from "Model B", which is
not included in local model.
+ //
+ // Model Name: Local Model.dmn
+ // Nodes: Local Decision Service
+ // Included Models: Model-A.dmn
+ //
+ // Model Name: Model-A.dmn
+ // Nodes: Decision-A
+ // Included Models: Model-B.dmn
+ //
+ // Model Name: Model-B.dmn
+ // Nodes: Input-B
+ // Included Models: [none]
+ //
+ // So, the "Local Model" only "knows" the nodes from "Model-A" and NOT from
"Model-B".
+ // That's why we have different logic to build description for "known
dmnObjects" and "unknown dmnObjects".
+ const isNamespaceDirectlyIncluded = useMemo(
+ () => namespace === relativeToNamespace ||
importsByNamespace.has(namespace),
+ [importsByNamespace, namespace, relativeToNamespace]
+ );
+
+ const transitivelyIncludedNamespaceDescription = useMemo(() => {
+ return `${namespace.substring(0,
11)}...${namespace.substring(namespace.length - 4)}`;
+ }, [namespace]);
+
+ const displayName = useMemo(
+ () =>
+ dmnObject && isNamespaceDirectlyIncluded
+ ? buildFeelQNameFromNamespace({
+ namedElement: dmnObject,
+ importsByNamespace,
+ namespace,
+ relativeToNamespace,
+ }).full
+ : dmnObject?.["@_name"],
+ [dmnObject, importsByNamespace, isNamespaceDirectlyIncluded, namespace,
relativeToNamespace]
+ );
+
+ const nodeTypeTooltipDescription = useMemo(() => {
+ if (dmnObject === undefined) {
+ throw new Error("nodeTypeDescription can't be defined without a DMN
object");
+ }
+ const nodeType = getNodeTypeFromDmnObject(dmnObject);
+ if (nodeType === undefined) {
+ throw new Error("Can't determine nodeTypeDescription with undefined node
type");
Review Comment:
Same as above. @danielzhe
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]