Skip to content

Conversation

@chesterkmr
Copy link
Contributor

@chesterkmr chesterkmr commented Jul 1, 2025

Summary by CodeRabbit

  • New Features
    • Improved filtering of entity IDs to ensure only valid IDs are included, with warnings logged when invalid or missing IDs are encountered.
  • Chores
    • Updated internal dependencies for data migrations.

@changeset-bot
Copy link

changeset-bot bot commented Jul 1, 2025

⚠️ No Changeset found

Latest commit: 8e3f5df

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

Walkthrough

A new utility function, safeEntityIdFilter, was introduced to filter arrays by a predicate and log warnings for missing entity IDs. This utility was then integrated into functions that extract director and UBO entity IDs from workflow data, ensuring only valid IDs are included. A subproject commit reference was also updated.

Changes

Files / Paths Change Summary
apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts Added safeEntityIdFilter utility function for filtering arrays with logging for missing IDs.
apps/backoffice-v2/src/lib/blocks/hooks/useDirectorsDocuments/helpers/get-directors-ids-from-workflow.ts
apps/backoffice-v2/src/lib/blocks/hooks/useUbosDocuments/helpers/get-ubos-entity-ids-from-workflow.ts
Updated to use safeEntityIdFilter for filtering valid director and UBO entity IDs from workflow data.
services/workflows-service/prisma/data-migrations Updated subproject commit reference.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant safeEntityIdFilter
    participant Console

    Caller->>safeEntityIdFilter: Call with (list, predicate)
    loop For each item in list
        safeEntityIdFilter->>safeEntityIdFilter: Apply predicate(item)
        alt Predicate is falsy
            safeEntityIdFilter->>Console: Log warning about missing entity ID
        end
    end
    safeEntityIdFilter-->>Caller: Return filtered list (only items with truthy predicate)
Loading

Possibly related PRs

  • ballerine-io/ballerine#3206: Also addresses filtering out falsy IDs from director and UBO ID arrays, but uses .filter(Boolean) instead of a utility function.

Suggested reviewers

  • alonp99

Poem

In the warren of code, a filter appears,
Catching IDs, chasing away fears.
Directors and UBOs, now only the true,
Warnings for those that just won’t do.
With every hop and every log,
The data’s clean—no need to slog! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3a5620 and 8e3f5df.

📒 Files selected for processing (1)
  • apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: test_linux
  • GitHub Check: lint
  • GitHub Check: format
  • GitHub Check: spell_check
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Analyze (javascript)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (1)
apps/backoffice-v2/src/lib/blocks/hooks/useBusinessDocuments/useBusinessDocuments.ts (1)

11-13: Consider simplifying the logic for single entity handling.

While the safety improvement is appreciated, the current implementation wraps a single entity in an array, filters it, then maps it back - this seems overly complex for a single entity scenario. Since we're dealing with a single entity rather than a collection, a simpler approach might be more appropriate.

Consider this simpler approach:

-        ? safeEntityIdFilter([workflow?.context?.entity], entity =>
-            Boolean(entity.ballerineEntityId),
-          ).map(entity => entity.ballerineEntityId)
+        ? workflow?.context?.entity?.ballerineEntityId
+          ? [workflow.context.entity.ballerineEntityId]
+          : []

Or if you want to keep the warning functionality:

-        ? safeEntityIdFilter([workflow?.context?.entity], entity =>
-            Boolean(entity.ballerineEntityId),
-          ).map(entity => entity.ballerineEntityId)
+        ? (() => {
+            const entity = workflow.context.entity;
+            if (!entity.ballerineEntityId) {
+              console.warn(`Missing entity id of entity: ${JSON.stringify(entity)}. Entity id will be skipped.`);
+              return [];
+            }
+            return [entity.ballerineEntityId];
+          })()
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b8d1a2 and c3a5620.

📒 Files selected for processing (5)
  • apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts (1 hunks)
  • apps/backoffice-v2/src/lib/blocks/hooks/useBusinessDocuments/useBusinessDocuments.ts (2 hunks)
  • apps/backoffice-v2/src/lib/blocks/hooks/useDirectorsDocuments/helpers/get-directors-ids-from-workflow.ts (1 hunks)
  • apps/backoffice-v2/src/lib/blocks/hooks/useUbosDocuments/helpers/get-ubos-entity-ids-from-workflow.ts (1 hunks)
  • services/workflows-service/prisma/data-migrations (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
services/workflows-service/prisma/data-migrations (2)

undefined

<retrieved_learning>
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: In Ballerine's workflow migration scripts (TypeScript), always establish the relationship between workflow definitions and UI definitions solely through the 'workflowDefinitionId' field in the UiDefinition model; do not create a separate junction table or relation.
</retrieved_learning>

<retrieved_learning>
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: Use consistent naming conventions for related components (workflows, UI definitions, filters) in Ballerine migrations to improve maintainability and clarity.
</retrieved_learning>

apps/backoffice-v2/src/lib/blocks/hooks/useUbosDocuments/helpers/get-ubos-entity-ids-from-workflow.ts (1)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: In Ballerine's workflow migration scripts (TypeScript), always establish the relationship between workflow definitions and UI definitions solely through the 'workflowDefinitionId' field in the UiDefinition model; do not create a separate junction table or relation.
apps/backoffice-v2/src/lib/blocks/hooks/useDirectorsDocuments/helpers/get-directors-ids-from-workflow.ts (1)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: In Ballerine's workflow migration scripts (TypeScript), always establish the relationship between workflow definitions and UI definitions solely through the 'workflowDefinitionId' field in the UiDefinition model; do not create a separate junction table or relation.
apps/backoffice-v2/src/lib/blocks/hooks/useBusinessDocuments/useBusinessDocuments.ts (3)
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: In Ballerine's workflow migration scripts (TypeScript), always establish the relationship between workflow definitions and UI definitions solely through the 'workflowDefinitionId' field in the UiDefinition model; do not create a separate junction table or relation.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: Use consistent naming conventions for related components (workflows, UI definitions, filters) in Ballerine migrations to improve maintainability and clarity.
Learnt from: CR
PR: ballerine-io/ballerine#0
File: .cursor/rules/data-migrations.mdc:0-0
Timestamp: 2025-06-24T09:35:54.963Z
Learning: For a workflow to be visible in the Ballerine backoffice, a corresponding filter must be created with a descriptive name that helps users identify the workflow.
🧬 Code Graph Analysis (3)
apps/backoffice-v2/src/lib/blocks/hooks/useUbosDocuments/helpers/get-ubos-entity-ids-from-workflow.ts (2)
apps/backoffice-v2/src/domains/workflows/fetchers.ts (1)
  • TWorkflowById (211-211)
apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts (1)
  • safeEntityIdFilter (1-14)
apps/backoffice-v2/src/lib/blocks/hooks/useDirectorsDocuments/helpers/get-directors-ids-from-workflow.ts (2)
apps/backoffice-v2/src/domains/workflows/fetchers.ts (1)
  • TWorkflowById (211-211)
apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts (1)
  • safeEntityIdFilter (1-14)
apps/backoffice-v2/src/lib/blocks/hooks/useBusinessDocuments/useBusinessDocuments.ts (1)
apps/backoffice-v2/src/common/utils/safe-entity-id-filter/safe-entity-id-filter.ts (1)
  • safeEntityIdFilter (1-14)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: test_linux
  • GitHub Check: lint
🔇 Additional comments (6)
services/workflows-service/prisma/data-migrations (1)

1-1: Verify the contents of the bumped migration submodule.

Only the submodule pointer changed, so we can’t review the actual migration code here. Please double-check that every new or modified migration inside services/workflows-service/prisma/data-migrations:

  1. Links UiDefinitionWorkflowDefinition strictly via the workflowDefinitionId field (no extra junction tables).
  2. Follows the established naming conventions for workflows, UI definitions, and filters.

If any migration deviates, please amend before merging.

apps/backoffice-v2/src/lib/blocks/hooks/useBusinessDocuments/useBusinessDocuments.ts (1)

1-1: LGTM! Import statement is correct.

The import statement for the safeEntityIdFilter utility is properly structured.

apps/backoffice-v2/src/lib/blocks/hooks/useUbosDocuments/helpers/get-ubos-entity-ids-from-workflow.ts (2)

1-1: LGTM! Import statement is correct.

The import statement for the safeEntityIdFilter utility is properly structured.


5-8: Excellent improvement in data safety.

The implementation correctly filters UBOs by variant first, then applies the safeEntityIdFilter to ensure only entities with valid IDs are processed. This prevents downstream issues with undefined or null IDs while providing helpful warning logs.

The logic flow is clear and the use of the utility function is appropriate for this collection scenario.

apps/backoffice-v2/src/lib/blocks/hooks/useDirectorsDocuments/helpers/get-directors-ids-from-workflow.ts (2)

1-1: LGTM! Import statement is correct.

The import statement for the safeEntityIdFilter utility is properly structured.


5-8: Excellent consistency and safety improvement.

The implementation follows the same robust pattern as the UBOs helper function - filtering directors by variant first, then applying safeEntityIdFilter to ensure only entities with valid IDs are processed. This consistency across helper functions improves maintainability and prevents downstream issues with invalid IDs.

The use of the utility function is well-suited for this collection scenario.

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.

3 participants