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(components): streamline details component properties access #3049

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

tomer-shvadron
Copy link
Collaborator

@tomer-shvadron tomer-shvadron commented Feb 11, 2025

  • Remove optional chaining for value.id and value.title
  • Improve readability by ensuring direct property access

refactor(hooks): add workflowId to bankAccount and credit check blocks

  • Update hooks to receive workflowId for better context handling
  • Simplify conditional checks for plugin outputs

chore(migrations): update subproject commit reference

  • Sync submodule to latest commit in workflows-service

Summary by CodeRabbit

  • New Features
    • Enhanced visual alerts now indicate when specific verification data is missing.
  • Refactor
    • Streamlined data access and parameter handling to improve overall stability.
  • Chores
    • Updated an external dependency for better integration consistency.

- Remove optional chaining for value.id and value.title
- Improve readability by ensuring direct property access

refactor(hooks): add workflowId to bankAccount and credit check blocks

- Update hooks to receive workflowId for better context handling
- Simplify conditional checks for plugin outputs

chore(migrations): update subproject commit reference

- Sync submodule to latest commit in workflows-service
Copy link

changeset-bot bot commented Feb 11, 2025

⚠️ No Changeset found

Latest commit: 118276a

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

Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

This PR updates several components and hooks in the backoffice-v2 application. The Details component now accesses properties directly without optional chaining. Both the Bank Account Verification and Commercial Credit Check hooks add a new workflowId parameter, update type definitions, simplify condition evaluations, and return blocks with warning indicators when data is missing. The Default Blocks logic now ensures that workflowId defaults to an empty string if not provided. Additionally, the subproject commit reference used by the workflows service data migrations has been updated.


Changes

File(s) Change Summary
apps/backoffice-v2/.../Details/Details.tsx Removed optional chaining from accessing value.id and value.title in the Details component.
apps/backoffice-v2/.../useBankAccountVerificationBlock.tsx
apps/backoffice-v2/.../useCommercialCreditCheckBlock.tsx
Added workflowId parameter with explicit type; simplified data checks; introduced warning blocks using WarningFilledSvg; updated dependency arrays to reflect new logic.
apps/backoffice-v2/.../useDefaultBlocksLogic.tsx Modified internal logic to set a default empty string for workflowId if undefined and pass it to dependent hooks.
services/workflows-service/.../data-migrations Updated the subproject commit reference from 96a420426151e15fd6001904537ee79641d02160 to c04b7033e17479b562e27a892066a3e8983aa66c.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Hook as Verification/CreditCheck Hook
    Client->>Hook: Call hook with { workflowId, pluginsOutput }
    alt Missing plugin key
        Hook->>Client: Return empty array []
    else Plugin exists but no data
        Hook->>Client: Return warning block (uses WarningFilledSvg)
    else Plugin exists with data
        Hook->>Client: Return block with extracted data and workflowId details
    end
Loading
sequenceDiagram
    participant UI
    participant DefaultLogic
    participant SubHooks
    UI->>DefaultLogic: Invoke useDefaultBlocksLogic()
    DefaultLogic->>SubHooks: Pass workflowId (or default '')
    SubHooks->>DefaultLogic: Return processed blocks
    DefaultLogic->>UI: Assemble and return updated blocks
Loading

Possibly related PRs

  • Blocks data sorting #2709: Related to the Details component changes; this PR also updates property access logic, affecting how value.data is handled.

Suggested labels

enhancement, Review effort [1-5]: 3


Suggested reviewers

  • Omri-Levy
  • alonp99

Poem

In a field of code, I hopped so free,
Updating values for all to see.
With workflowId leading the way so bright,
Warnings appear if data's not right.
A happy bunny sings as bugs take flight! 🐇


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>, please review it.
    • 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 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 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 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. (Beta)
  • @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: 0

🧹 Nitpick comments (6)
apps/backoffice-v2/src/lib/blocks/hooks/useBankAccountVerificationBlock/useBankAccountVerificationBlock.tsx (3)

6-12: Use a more specific type instead of any for pluginsOutput.

Relying on any reduces type safety. Consider defining an interface or type to capture the shape of the data.

 export const useBankAccountVerificationBlock = ({
   workflowId,
   pluginsOutput,
 }: {
   workflowId: string;
-  pluginsOutput: any;
+  pluginsOutput: BankAccountVerificationOutput; // Example
 }) => {

18-54: Consider extracting the fallback block into a shared component or helper.

This sizable UI block for the “no data available” warning pattern might be repeated across different hooks. A reusable helper could reduce duplication and improve maintainability.


87-95: Clarify the purpose of workflowId and validate unused fields.

• Passing workflowId to the details cell suggests you might need it for inline edits or references.
title is empty; ensure a more descriptive label if the UI eventually displays this field.

apps/backoffice-v2/src/lib/blocks/hooks/useCommercialCreditCheckBlock/useCommercialCreditCheckBlock.tsx (3)

6-12: Prefer a strict type for pluginsOutput.

Using any limits the benefits of TypeScript. Provide a dedicated interface or type to fully describe the commercial credit check data.

 export const useCommercialCreditCheckBlock = ({
   workflowId,
   pluginsOutput,
 }: {
   workflowId: string;
-  pluginsOutput: any;
+  pluginsOutput: CommercialCreditCheckData;
 }) => {

18-53: Consider centralized handling of “no data” warnings.

Similar to other hooks, extracting repeated fallback blocks into a shared component or helper can streamline the code.


79-86: Check usage of title and workflowId.

• If title remains empty, confirm it’s not needed for UI rendering.
workflowId presumably aids referencing data; verify it’s used downstream.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 130b240 and 49f3f00.

📒 Files selected for processing (5)
  • apps/backoffice-v2/src/lib/blocks/components/Details/Details.tsx (1 hunks)
  • apps/backoffice-v2/src/lib/blocks/hooks/useBankAccountVerificationBlock/useBankAccountVerificationBlock.tsx (3 hunks)
  • apps/backoffice-v2/src/lib/blocks/hooks/useCommercialCreditCheckBlock/useCommercialCreditCheckBlock.tsx (3 hunks)
  • apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx (2 hunks)
  • services/workflows-service/prisma/data-migrations (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • services/workflows-service/prisma/data-migrations
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: test_windows
  • GitHub Check: test_linux
  • GitHub Check: build (windows-latest)
  • GitHub Check: format
  • GitHub Check: spell_check
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: lint
🔇 Additional comments (10)
apps/backoffice-v2/src/lib/blocks/components/Details/Details.tsx (1)

40-40: Verify type safety after removal of optional chaining.

The removal of optional chaining for value.id and value.title could potentially cause runtime errors if value is undefined. While value.data is safely accessed with optional chaining on line 20, these properties are accessed directly.

Please confirm that:

  1. The type ExtractCellProps<'details'> guarantees that value is always defined with required id and title properties.
  2. There are no code paths where value could be undefined when accessing these properties.

Let's verify the type definition:

If the type safety cannot be guaranteed, consider maintaining consistent null checking:

-        valueId={value.id}
-        title={value.title}
+        valueId={value?.id}
+        title={value?.title}

Also applies to: 42-42

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check the type definition of ExtractCellProps to verify property requirements

# Search for the type definition
ast-grep --pattern 'type ExtractCellProps = {
  $$$
}'

# Search for any usages where value might be undefined
rg -A 5 'ExtractCellProps.*details'

Length of output: 1313


Type safety is guaranteed by the current props definition.

The Details component is typed as a FunctionComponent<ExtractCellProps<'details'>> and destructures value from its props. This type enforcement indicates that value—and by extension its id and title properties—must be provided. There is no evidence from the usage in the code (or from the search results) that there are any code paths where value could be undefined. Therefore, the removal of optional chaining for accessing value.id and value.title is safe as long as the consumers of this component adhere to the required prop types.

apps/backoffice-v2/src/lib/blocks/hooks/useBankAccountVerificationBlock/useBankAccountVerificationBlock.tsx (3)

4-4: Good addition of the import for the warning icon.

This makes it explicit that we display a warning icon when data is missing.


14-16: Straightforward null-guard check.

Returning an empty array prevents potential runtime errors when bankAccountVerification is absent.


114-114: Good practice including workflowId in the dependency array.

This ensures the memo recomputes whenever workflowId changes, preventing stale data issues.

apps/backoffice-v2/src/lib/blocks/hooks/useCommercialCreditCheckBlock/useCommercialCreditCheckBlock.tsx (3)

4-4: Useful import for warnings.

This import provides visual feedback for missing commercial credit data, enhancing clarity.


14-16: Null-guard logic approved.

Returning an empty array when commercialCreditCheck is missing prevents runtime crashes.


106-106: Correct memo dependency array.

Including workflowId ensures the memo recalculates when the workflow changes.

apps/backoffice-v2/src/lib/blocks/variants/DefaultBlocks/hooks/useDefaultBlocksLogic/useDefaultBlocksLogic.tsx (3)

169-169: Ensuring workflowId is set to an empty string avoids undefined values.

This fallback prevents runtime errors when workflow?.id is absent.


179-179: Consistent default assignment for workflowId.

Having a guaranteed non-null string helps all downstream logic that depends on a valid workflow ID.


184-184: Good defensive coding for workflowId.

Provides a clear fallback when workflow is not loaded, enhancing robustness.

@alonp99 alonp99 enabled auto-merge (squash) February 11, 2025 21:47
@alonp99 alonp99 merged commit 36b1b8c into dev Feb 12, 2025
18 checks passed
@alonp99 alonp99 deleted the bal-3490 branch February 12, 2025 08:59
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