-
Notifications
You must be signed in to change notification settings - Fork 268
feat: added safe filter with warnings for missing entity ids #3465
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
base: dev
Are you sure you want to change the base?
feat: added safe filter with warnings for missing entity ids #3465
Conversation
|
WalkthroughA new utility function, Changes
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)
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
⏰ 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)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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:
- Links
UiDefinition↔WorkflowDefinitionstrictly via theworkflowDefinitionIdfield (no extra junction tables).- 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
safeEntityIdFilterutility 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
safeEntityIdFilterutility is properly structured.
5-8: Excellent improvement in data safety.The implementation correctly filters UBOs by variant first, then applies the
safeEntityIdFilterto 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
safeEntityIdFilterutility 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
safeEntityIdFilterto 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.
Summary by CodeRabbit