-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[PE-93] refactor: accept generic function to search mentions #6249
Conversation
WalkthroughThe pull request introduces a new Changes
Sequence DiagramsequenceDiagram
participant Editor as RichTextEditor
participant Service as ProjectService
participant Callback as SearchMentionCallback
Editor->>Callback: Request entity search
Callback->>Service: Perform search with payload
Service-->>Callback: Return search results
Callback-->>Editor: Provide search results
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: 2
🧹 Nitpick comments (2)
web/core/components/issues/description-input.tsx (1)
Line range hint
132-144
: Extract common error handling logicThe error handling logic for file uploads is duplicated across components.
Consider extracting it into a shared utility:
// utils/file-upload.ts export const handleProjectAssetUpload = async ( fileService: FileService, workspaceSlug: string, projectId: string, entityId: string, entityType: EFileAssetType, file: File ): Promise<string> => { try { const { asset_id } = await fileService.uploadProjectAsset( workspaceSlug, projectId, { entity_identifier: entityId, entity_type: entityType, }, file ); return asset_id; } catch (error) { console.log("Error in uploading issue asset:", error); throw new Error("Asset upload failed. Please try again later."); } };web/core/components/issues/issue-modal/components/description-editor.tsx (1)
193-199
: Consider performance and error handling improvementsThe searchMentionCallback implementation is correct and aligns with the PR objectives. However, consider these improvements:
+ const searchMentionCallback = useCallback(async (payload) => { + try { return await projectService.searchEntity( workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload ); + } catch (error) { + console.error("Error searching mentions:", error); + return []; + } + }, [workspaceSlug, projectId]); <RichTextEditor - searchMentionCallback={async (payload) => - await projectService.searchEntity( - workspaceSlug?.toString() ?? "", - projectId?.toString() ?? "", - payload - ) - } + searchMentionCallback={searchMentionCallback}This would:
- Memoize the callback to prevent unnecessary re-renders
- Add error handling to gracefully handle failures
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
web/core/components/editor/rich-text-editor/rich-text-editor.tsx
(2 hunks)web/core/components/inbox/modals/create-modal/issue-description.tsx
(2 hunks)web/core/components/issues/description-input.tsx
(2 hunks)web/core/components/issues/issue-modal/components/description-editor.tsx
(3 hunks)
🔇 Additional comments (6)
web/core/components/editor/rich-text-editor/rich-text-editor.tsx (2)
19-19
: LGTM! Well-typed callback interface
The searchMentionCallback
property is properly typed with TSearchEntityRequestPayload
and TSearchResponse
, making the contract clear and type-safe.
27-33
: LGTM! Clean implementation of the generic search callback
The component correctly implements the dependency injection pattern by:
- Accepting the search callback as a prop
- Properly forwarding it to the mention hook
- Removing direct service dependencies
web/core/components/issues/description-input.tsx (2)
21-23
: Consider dependency injection for services
Similar to the previous file, creating service instances at the module level should be avoided.
123-129
: Improve null safety in searchMentionCallback
Similar null safety concerns as in the previous file.
web/core/components/issues/issue-modal/components/description-editor.tsx (2)
29-29
: LGTM: Service import and instantiation
The ProjectService import and instantiation follow the established pattern in the codebase, properly placed outside the component for optimal performance.
Also applies to: 53-53
Line range hint 31-48
: Verify the impact of projectId type change
The type change from string | undefined
to string | null
is a breaking change that requires verification of all consuming components.
✅ Verification successful
Type change from string | undefined
to string | null
is safe
The change is safe because:
- All usages of
projectId
in the component are already null-safe with checks likeif (!projectId)
orprojectId?.toString()
- The component handles both null and undefined cases similarly in its implementation
- The value is only used after null checks, making the type change non-breaking
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for components using IssueDescriptionEditor to verify type compatibility
rg -l "IssueDescriptionEditor" | while read -r file; do
echo "=== $file ==="
rg "projectId.*IssueDescriptionEditor" "$file" -A 2
done
Length of output: 580
Script:
#!/bin/bash
# Let's check how projectId is being used in the form component and any other related files
rg "projectId.*IssueDescriptionEditor" -B 5 -A 2 web/core/components/issues/issue-modal/form.tsx
# Also check for any direct usage of projectId in the description editor
rg "projectId" web/core/components/issues/issue-modal/components/description-editor.tsx -B 2 -A 2
# Let's also check if there are any other components passing projectId
ast-grep --pattern 'projectId={$_}'
Length of output: 2243
searchMentionCallback={async (payload) => | ||
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload) | ||
} |
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.
Improve null safety in searchMentionCallback
The current implementation uses optional chaining with toString() which could still result in "undefined" being passed as a string.
Consider this safer implementation:
- searchMentionCallback={async (payload) =>
- await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload)
- }
+ searchMentionCallback={async (payload) => {
+ if (!workspaceSlug || !projectId) throw new Error("Workspace slug and project ID are required");
+ return await projectService.searchEntity(workspaceSlug.toString(), projectId.toString(), payload);
+ }}
📝 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.
searchMentionCallback={async (payload) => | |
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload) | |
} | |
searchMentionCallback={async (payload) => { | |
if (!workspaceSlug || !projectId) throw new Error("Workspace slug and project ID are required"); | |
return await projectService.searchEntity(workspaceSlug.toString(), projectId.toString(), payload); | |
}} |
import { ProjectService } from "@/services/project"; | ||
const fileService = new FileService(); | ||
const projectService = new ProjectService(); |
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.
🛠️ Refactor suggestion
Consider dependency injection for services
Creating service instances at the module level can lead to:
- Multiple instances across imports
- Difficulties in testing
- Potential memory leaks
Consider injecting the service through props or a dependency injection container:
-const projectService = new ProjectService();
+interface Props {
+ projectService: ProjectService;
+ // ... other props
+}
Committable suggestion skipped: line range outside the PR's diff.
Description
This PR adds a generic
searchEntity
callback function for scalability.Type of Change
Summary by CodeRabbit
New Features
searchMentionCallback
in theRichTextEditor
for enhanced mention search functionality.Bug Fixes
Documentation