-
Notifications
You must be signed in to change notification settings - Fork 204
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
Conversation
- 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
|
WalkthroughThis 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 Changes
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
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
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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: 0
🧹 Nitpick comments (6)
apps/backoffice-v2/src/lib/blocks/hooks/useBankAccountVerificationBlock/useBankAccountVerificationBlock.tsx (3)
6-12
: Use a more specific type instead ofany
forpluginsOutput
.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 ofworkflowId
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 forpluginsOutput
.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 oftitle
andworkflowId
.• 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
📒 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
andvalue.title
could potentially cause runtime errors ifvalue
is undefined. Whilevalue.data
is safely accessed with optional chaining on line 20, these properties are accessed directly.Please confirm that:
- The type
ExtractCellProps<'details'>
guarantees thatvalue
is always defined with requiredid
andtitle
properties.- 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 aFunctionComponent<ExtractCellProps<'details'>>
and destructuresvalue
from its props. This type enforcement indicates thatvalue
—and by extension itsid
andtitle
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 wherevalue
could beundefined
. Therefore, the removal of optional chaining for accessingvalue.id
andvalue.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 includingworkflowId
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
: EnsuringworkflowId
is set to an empty string avoids undefined values.This fallback prevents runtime errors when
workflow?.id
is absent.
179-179
: Consistent default assignment forworkflowId
.Having a guaranteed non-null string helps all downstream logic that depends on a valid workflow ID.
184-184
: Good defensive coding forworkflowId
.Provides a clear fallback when
workflow
is not loaded, enhancing robustness.
refactor(hooks): add workflowId to bankAccount and credit check blocks
chore(migrations): update subproject commit reference
Summary by CodeRabbit