Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor bpmn diagram component for call activity nav #1984

Merged
merged 12 commits into from
Jul 24, 2024

Conversation

jasquat
Copy link
Contributor

@jasquat jasquat commented Jul 23, 2024

Supports sartography/bpmn-js-spiffworkflow#111

This adds an overlay to call activities on the process instance show page that will navigate to that call activity. This navigation will happen in the same tab instead of creating a new one.

Changes:

  • refactored ReactDiagramEditor to recognize the bpmn xml as a state so it will reload the diagram when xml changes
  • add overly to call activities on process instance show page only so it can be used to navigate instead of clicking on the call activity

Summary by CodeRabbit

  • New Features

    • Introduced a callback prop for interactive call activity overlays in the diagram editor.
  • Performance Improvements

    • Refactored multiple functions to use memoization for enhanced performance in the ProcessInstanceShow component.
  • Bug Fixes

    • Streamlined XML handling logic in the diagram editor for improved clarity and performance.
  • Documentation

    • Added comments for clarity on task states and navigation logic in the ProcessInstanceShow component.

Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

Walkthrough

The recent updates to the spiffworkflow-frontend codebase enhance both interactivity and performance in components related to diagram editing and process management. Key improvements include the addition of an optional callback for handling call activity overlays in the diagram editor and the optimization of multiple functions with the useCallback hook in the process instance display. These changes aim to improve user experience while maintaining a clear and efficient code structure.

Changes

Files Change Summary
src/components/ReactDiagramEditor.tsx Introduced onCallActivityOverlayClick prop for handling call activity overlays, refined XML handling logic, and added effects for display correctness.
src/routes/ProcessInstanceShow.tsx Refactored functions to use useCallback for improved performance and readability; removed unnecessary imports, and added comments for clarity.
cypress/e2e/process_instances.cy.js Replaced hardcoded string literals with a constant for maintainability and clarity in test cases.

Sequence Diagram(s)

sequenceDiagram
    participant Parent Component
    participant ReactDiagramEditor
    participant Call Activity Overlay

    Parent Component->>ReactDiagramEditor: Render with onCallActivityOverlayClick
    ReactDiagramEditor->>Call Activity Overlay: Create overlay on call activity
    Call Activity Overlay-->>ReactDiagramEditor: Click event triggered
    ReactDiagramEditor->>Parent Component: Invoke onCallActivityOverlayClick with task data
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bad764b and 3904a99.

Files selected for processing (3)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (11 hunks)
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx (6 hunks)
  • spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx (11 hunks)
Additional context used
Learnings (1)
spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx (3)
Learnt from: jasquat
PR: sartography/spiff-arena#919
File: spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx:108-228
Timestamp: 2024-01-26T16:31:45.083Z
Learning: The user, jasquat, has indicated a consideration for future refactor regarding the suggestion to abstract the API call logic in `getProcessInstances` function into a separate service or hook for improved modularity and reusability.
Learnt from: jasquat
PR: sartography/spiff-arena#919
File: spiffworkflow-frontend/src/components/ProcessInstanceListTable.tsx:130-181
Timestamp: 2024-01-26T16:06:18.478Z
Learning: The user, jasquat, has indicated a consideration for future refactor regarding the suggestion to abstract the API call logic in `getProcessInstances` function into a separate service or hook for improved modularity and reusability.
Learnt from: jasquat
PR: sartography/spiff-arena#1902
File: spiffworkflow-frontend/src/routes/ProcessInstanceMigratePage.tsx:353-353
Timestamp: 2024-07-11T14:30:49.271Z
Learning: Verify code changes using shell scripts when the user indicates a modification has been made.
Additional comments not posted (21)
spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (2)

80-80: LGTM!

The addition of the onCallActivityOverlayClick prop to the OwnProps type is straightforward and looks good.


113-113: LGTM!

The onCallActivityOverlayClick prop is correctly passed to the ReactDiagramEditor component.

spiffworkflow-frontend/src/routes/ProcessModelEditDiagram.tsx (13)

298-300: LGTM!

The onElementsChanged function is correctly wrapped in a useCallback hook, improving performance by memoizing the function.


417-422: LGTM!

The onServiceTasksRequested function is correctly wrapped in a useCallback hook, improving performance by memoizing the function.


424-434: LGTM!

The onDataStoresRequested function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


436-451: LGTM!

The onJsonSchemaFilesRequested function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


453-470: LGTM!

The onDmnFilesRequested function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


533-542: LGTM!

The setScriptUnitTestElementWithIndex function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


544-564: LGTM!

The onLaunchScriptEditor function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


1064-1071: LGTM!

The onLaunchMarkdownEditor function is correctly wrapped in a useCallback hook with an empty dependency array, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


1102-1109: LGTM!

The onLaunchMessageEditor function is correctly wrapped in a useCallback hook with an empty dependency array, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


1152-1159: LGTM!

The onSearchProcessModels function is correctly wrapped in a useCallback hook with an empty dependency array, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


1191-1209: LGTM!

The findFileNameForReferenceId function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


1211-1256: LGTM!

The onLaunchBpmnEditor function is correctly wrapped in a useCallback hook with dependencies, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.


1258-1265: LGTM!

The onLaunchJsonSchemaEditor function is correctly wrapped in a useCallback hook with an empty dependency array, improving performance by memoizing the function while ensuring it is only redefined when its dependencies change.

spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx (6)

737-759: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to initializeTaskDataToDisplay are correctly updated to use the memoized version.

Verification successful

All function calls to initializeTaskDataToDisplay are correctly updated to use the memoized version.

The code changes are approved, and the function usage is verified to be correct.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `initializeTaskDataToDisplay` are correctly updated.

# Test: Search for the function usage. Expect: Only occurances of the updated function.
rg --type tsx -A 5 $'initializeTaskDataToDisplay'

Length of output: 76


Script:

#!/bin/bash
# Description: Verify all function calls to `initializeTaskDataToDisplay` are correctly updated.

# Test: Search for the function usage. Expect: Only occurrences of the updated function.
rg --type ts -A 5 $'initializeTaskDataToDisplay'

Length of output: 3238


864-880: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to findMatchingTaskFromShapeElement are correctly updated to use the memoized version.

Verification successful

Verified: The function findMatchingTaskFromShapeElement is correctly updated and used within the codebase.

All occurrences of the function are within the spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx file, ensuring the memoized version is applied correctly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `findMatchingTaskFromShapeElement` are correctly updated.

# Test: Search for the function usage. Expect: Only occurances of the updated function.
rg --type tsx -A 5 $'findMatchingTaskFromShapeElement'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify all function calls to `findMatchingTaskFromShapeElement` are correctly updated.

# Test: Search for the function usage. Expect: Only occurrences of the updated function.
rg 'findMatchingTaskFromShapeElement'

Length of output: 370


815-862: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to makeProcessDataCallFromShapeElement are correctly updated to use the memoized version.

Verification successful

Function usage verified!

The function makeProcessDataCallFromShapeElement is correctly updated and used within the same file, ProcessInstanceShow.tsx.

  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx: Verified occurrences of makeProcessDataCallFromShapeElement.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `makeProcessDataCallFromShapeElement` are correctly updated.

# Test: Search for the function usage. Expect: Only occurances of the updated function.
rg --type tsx -A 5 $'makeProcessDataCallFromShapeElement'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify all function calls to `makeProcessDataCallFromShapeElement` are correctly updated.

# Test: Search for the function usage. Expect: Only occurrences of the updated function.
rg --type ts -A 5 $'makeProcessDataCallFromShapeElement'

Length of output: 1742


709-726: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to initializeTaskInstancesToDisplay are correctly updated to use the memoized version.

Verification successful

LGTM! Function usage is correctly updated.

The function initializeTaskInstancesToDisplay is correctly utilized in the codebase with the memoized version. No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `initializeTaskInstancesToDisplay` are correctly updated.

# Test: Search for the function usage. Expect: Only occurances of the updated function.
rg --type tsx -A 5 $'initializeTaskInstancesToDisplay'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify all function calls to `initializeTaskInstancesToDisplay` are correctly updated.

# Test: Search for the function usage. Expect: Only occurrences of the updated function.
rg -A 5 $'initializeTaskInstancesToDisplay'

Length of output: 2501


882-896: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to handleCallActivityNavigate are correctly updated to use the memoized version.

Verification successful

The function usage is correctly updated.

The function handleCallActivityNavigate is correctly used with the memoized version in spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx.

  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx: onCallActivityOverlayClick={handleCallActivityNavigate}
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `handleCallActivityNavigate` are correctly updated.

# Test: Search for the function usage. Expect: Only occurances of the updated function.
rg --type tsx -A 5 $'handleCallActivityNavigate'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify all function calls to `handleCallActivityNavigate` are correctly updated.

# Test: Search for the function usage. Expect: Only occurrences of the updated function.
rg --type ts -A 5 $'handleCallActivityNavigate'

Length of output: 1086


898-921: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to handleClickedDiagramTask are correctly updated to use the memoized version.

Verification successful

Function usage verified successfully.

The function handleClickedDiagramTask is correctly updated and used within the codebase.

  • Definition: spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx
  • Usage: spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `handleClickedDiagramTask` are correctly updated.

# Test: Search for the function usage. Expect: Only occurances of the updated function.
rg --type tsx -A 5 $'handleClickedDiagramTask'

Length of output: 73


Script:

#!/bin/bash
# Description: Verify all function calls to `handleClickedDiagramTask` are correctly updated.

# Find all .tsx files and search for the function usage within those files
fd --extension tsx --exec rg 'handleClickedDiagramTask' {}

Length of output: 160


Script:

#!/bin/bash
# Description: Verify all function calls to `handleClickedDiagramTask` are correctly updated.

# Search for all occurrences of handleClickedDiagramTask in the codebase
rg 'handleClickedDiagramTask'

Length of output: 245

Comment on lines 505 to 557
function addOverlayOnCallActivity(
task: Task,
bpmnProcessIdentifiers: string[],
) {
if (
!onCallActivityOverlayClick ||
diagramType !== 'readonly' ||
!diagramModelerState
) {
return;
}
function domify(htmlString: string) {
const template = document.createElement('template');
template.innerHTML = htmlString.trim();
return template.content.firstChild;
}
const createCallActivityOverlay = () => {
const overlays = diagramModelerState.get('overlays');
const ARROW_DOWN_SVG =
'<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
const button: any = domify(
`<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`,
);
button.addEventListener('click', () => {
onCallActivityOverlayClick(task);
});
overlays.add(task.bpmn_identifier, 'drilldown', {
position: {
bottom: -10,
right: -8,
},
html: button,
});
};
try {
if (
bpmnProcessIdentifiers.includes(
task.bpmn_process_definition_identifier,
)
) {
createCallActivityOverlay();
}
} catch (bpmnIoError: any) {
// the task list also contains task for processes called from call activities which will
// not exist in this diagram so just ignore them for now.
if (
bpmnIoError.message !==
"Cannot read properties of undefined (reading 'id')"
) {
throw bpmnIoError;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider improving error handling and code readability.

The addOverlayOnCallActivity function is well-implemented, but there are a few areas for potential improvement:

  1. Improve error handling by providing more specific error messages.
  2. Enhance code readability by breaking down the function into smaller, more manageable functions.
-    function addOverlayOnCallActivity(
-      task: Task,
-      bpmnProcessIdentifiers: string[],
-    ) {
-      if (
-        !onCallActivityOverlayClick ||
-        diagramType !== 'readonly' ||
-        !diagramModelerState
-      ) {
-        return;
-      }
-      function domify(htmlString: string) {
-        const template = document.createElement('template');
-        template.innerHTML = htmlString.trim();
-        return template.content.firstChild;
-      }
-      const createCallActivityOverlay = () => {
-        const overlays = diagramModelerState.get('overlays');
-        const ARROW_DOWN_SVG =
-          '<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
-        const button: any = domify(
-          `<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`,
-        );
-        button.addEventListener('click', () => {
-          onCallActivityOverlayClick(task);
-        });
-        overlays.add(task.bpmn_identifier, 'drilldown', {
-          position: {
-            bottom: -10,
-            right: -8,
-          },
-          html: button,
-        });
-      };
-      try {
-        if (
-          bpmnProcessIdentifiers.includes(
-            task.bpmn_process_definition_identifier,
-          )
-        ) {
-          createCallActivityOverlay();
-        }
-      } catch (bpmnIoError: any) {
-        // the task list also contains task for processes called from call activities which will
-        // not exist in this diagram so just ignore them for now.
-        if (
-          bpmnIoError.message !==
-          "Cannot read properties of undefined (reading 'id')"
-        ) {
-          throw bpmnIoError;
-        }
-      }
-    }
+    function addOverlayOnCallActivity(task: Task, bpmnProcessIdentifiers: string[]) {
+      if (!onCallActivityOverlayClick || diagramType !== 'readonly' || !diagramModelerState) {
+        return;
+      }
+
+      const domify = (htmlString: string) => {
+        const template = document.createElement('template');
+        template.innerHTML = htmlString.trim();
+        return template.content.firstChild;
+      };
+
+      const createCallActivityOverlay = () => {
+        const overlays = diagramModelerState.get('overlays');
+        const ARROW_DOWN_SVG = '<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
+        const button: any = domify(`<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`);
+        button.addEventListener('click', () => onCallActivityOverlayClick(task));
+        overlays.add(task.bpmn_identifier, 'drilldown', {
+          position: { bottom: -10, right: -8 },
+          html: button,
+        });
+      };
+
+      try {
+        if (bpmnProcessIdentifiers.includes(task.bpmn_process_definition_identifier)) {
+          createCallActivityOverlay();
+        }
+      } catch (bpmnIoError: any) {
+        if (bpmnIoError.message !== "Cannot read properties of undefined (reading 'id')") {
+          console.error('Error adding overlay on call activity:', bpmnIoError);
+        }
+      }
+    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function addOverlayOnCallActivity(
task: Task,
bpmnProcessIdentifiers: string[],
) {
if (
!onCallActivityOverlayClick ||
diagramType !== 'readonly' ||
!diagramModelerState
) {
return;
}
function domify(htmlString: string) {
const template = document.createElement('template');
template.innerHTML = htmlString.trim();
return template.content.firstChild;
}
const createCallActivityOverlay = () => {
const overlays = diagramModelerState.get('overlays');
const ARROW_DOWN_SVG =
'<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
const button: any = domify(
`<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`,
);
button.addEventListener('click', () => {
onCallActivityOverlayClick(task);
});
overlays.add(task.bpmn_identifier, 'drilldown', {
position: {
bottom: -10,
right: -8,
},
html: button,
});
};
try {
if (
bpmnProcessIdentifiers.includes(
task.bpmn_process_definition_identifier,
)
) {
createCallActivityOverlay();
}
} catch (bpmnIoError: any) {
// the task list also contains task for processes called from call activities which will
// not exist in this diagram so just ignore them for now.
if (
bpmnIoError.message !==
"Cannot read properties of undefined (reading 'id')"
) {
throw bpmnIoError;
}
}
}
function addOverlayOnCallActivity(task: Task, bpmnProcessIdentifiers: string[]) {
if (!onCallActivityOverlayClick || diagramType !== 'readonly' || !diagramModelerState) {
return;
}
const domify = (htmlString: string) => {
const template = document.createElement('template');
template.innerHTML = htmlString.trim();
return template.content.firstChild;
};
const createCallActivityOverlay = () => {
const overlays = diagramModelerState.get('overlays');
const ARROW_DOWN_SVG = '<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
const button: any = domify(`<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`);
button.addEventListener('click', () => onCallActivityOverlayClick(task));
overlays.add(task.bpmn_identifier, 'drilldown', {
position: { bottom: -10, right: -8 },
html: button,
});
};
try {
if (bpmnProcessIdentifiers.includes(task.bpmn_process_definition_identifier)) {
createCallActivityOverlay();
}
} catch (bpmnIoError: any) {
if (bpmnIoError.message !== "Cannot read properties of undefined (reading 'id')") {
console.error('Error adding overlay on call activity:', bpmnIoError);
}
}
}

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3904a99 and 9fb9f0b.

Files selected for processing (1)
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9fb9f0b and 4b3bdfb.

Files selected for processing (1)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (13 hunks)
Files skipped from review as they are similar to previous changes (1)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4b3bdfb and 57f70bd.

Files selected for processing (2)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (13 hunks)
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (2)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 57f70bd and 68d3711.

Files selected for processing (2)
  • spiffworkflow-frontend/cypress/e2e/process_instances.cy.js (1 hunks)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (14 hunks)
Files skipped from review due to trivial changes (1)
  • spiffworkflow-frontend/cypress/e2e/process_instances.cy.js
Additional comments not posted (4)
spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (4)

80-80: New optional prop added: onCallActivityOverlayClick.

This new prop allows the parent component to provide a callback function for call activity overlay clicks. Ensure that this prop is correctly passed and utilized in the component.


519-571: Consider improving error handling and code readability.

The addOverlayOnCallActivity function is well-implemented, but there are a few areas for potential improvement:

  1. Improve error handling by providing more specific error messages.
  2. Enhance code readability by breaking down the function into smaller, more manageable functions.
-    function addOverlayOnCallActivity(
-      task: Task,
-      bpmnProcessIdentifiers: string[],
-    ) {
-      if (
-        !onCallActivityOverlayClick ||
-        diagramType !== 'readonly' ||
-        !diagramModelerState
-      ) {
-        return;
-      }
-      function domify(htmlString: string) {
-        const template = document.createElement('template');
-        template.innerHTML = htmlString.trim();
-        return template.content.firstChild;
-      }
-      const createCallActivityOverlay = () => {
-        const overlays = diagramModelerState.get('overlays');
-        const ARROW_DOWN_SVG =
-          '<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
-        const button: any = domify(
-          `<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`,
-        );
-        button.addEventListener('click', () => {
-          onCallActivityOverlayClick(task);
-        });
-        overlays.add(task.bpmn_identifier, 'drilldown', {
-          position: {
-            bottom: -10,
-            right: -8,
-          },
-          html: button,
-        });
-      };
-      try {
-        if (
-          bpmnProcessIdentifiers.includes(
-            task.bpmn_process_definition_identifier,
-          )
-        ) {
-          createCallActivityOverlay();
-        }
-      } catch (bpmnIoError: any) {
-        // the task list also contains task for processes called from call activities which will
-        // not exist in this diagram so just ignore them for now.
-        if (
-          bpmnIoError.message !==
-          "Cannot read properties of undefined (reading 'id')"
-        ) {
-          throw bpmnIoError;
-        }
-      }
-    }
+    function addOverlayOnCallActivity(task: Task, bpmnProcessIdentifiers: string[]) {
+      if (!onCallActivityOverlayClick || diagramType !== 'readonly' || !diagramModelerState) {
+        return;
+      }
+
+      const domify = (htmlString: string) => {
+        const template = document.createElement('template');
+        template.innerHTML = htmlString.trim();
+        return template.content.firstChild;
+      };
+
+      const createCallActivityOverlay = () => {
+        const overlays = diagramModelerState.get('overlays');
+        const ARROW_DOWN_SVG = '<svg width="20" height="20" viewBox="0 0 24.00 24.00" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff"> <g id="SVGRepo_bgCarrier" stroke-width="0"> <rect x="0" y="0" width="24.00" height="24.00" rx="0" fill="#2196f3" strokewidth="0"/> </g> <g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round" stroke="#CCCCCC" stroke-width="0.048"/> <g id="SVGRepo_iconCarrier"> <path d="M7 17L17 7M17 7H8M17 7V16" stroke="#ffffff" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/> </g> </svg>';
+        const button: any = domify(`<button class="bjs-drilldown">${ARROW_DOWN_SVG}</button>`);
+        button.addEventListener('click', () => onCallActivityOverlayClick(task));
+        overlays.add(task.bpmn_identifier, 'drilldown', {
+          position: { bottom: -10, right: -8 },
+          html: button,
+        });
+      };
+
+      try {
+        if (bpmnProcessIdentifiers.includes(task.bpmn_process_definition_identifier)) {
+          createCallActivityOverlay();
+        }
+      } catch (bpmnIoError: any) {
+        if (bpmnIoError.message !== "Cannot read properties of undefined (reading 'id')") {
+          console.error('Error adding overlay on call activity:', bpmnIoError);
+        }
+      }
+    }

453-464: Ensure correct integration of onCallActivityOverlayClick.

The useEffect hook correctly integrates the new onCallActivityOverlayClick prop. Ensure that this prop is passed and utilized as expected.


614-619: Ensure correct integration of addOverlayOnCallActivity.

The onImportDone function correctly calls the addOverlayOnCallActivity function for call activities. Ensure that the addOverlayOnCallActivity function is correctly integrated and utilized.

…e opened in a new tab if desired w/ burnettk
…it can be opened in a new tab if desired w/ burnettk"

This reverts commit 1c12725.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 68d3711 and 1c12725.

Files selected for processing (1)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (17 hunks)
Files skipped from review as they are similar to previous changes (1)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1c12725 and 5e76120.

Files selected for processing (2)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx (14 hunks)
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (2)
  • spiffworkflow-frontend/src/components/ReactDiagramEditor.tsx
  • spiffworkflow-frontend/src/routes/ProcessInstanceShow.tsx

@burnettk burnettk merged commit 6f1af21 into main Jul 24, 2024
23 checks passed
@burnettk burnettk deleted the refactor-bpmn-diagram-component branch July 24, 2024 21:19
@burnettk burnettk changed the title Refactor bpmn diagram component Refactor bpmn diagram component for call activity nav Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants