Skip to content

Conversation

@anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Feb 13, 2025

Description

This PR includes following changes:

  • Fixes for Work Item Actions: Resolved issues with the state, assignee, and priority actions. These actions were not functioning as expected earlier, and this fix ensures they now behave correctly.
  • Context Indicator Improvement: Enhanced the work item context indicator for better clarity and improved user experience. This provides a more intuitive understanding of the current state and associated details of the work item.

Type of Change

  • Bug fix)
  • Improvement

Media

Preview
preview1
preview1

Test Scenarios

  1. Work Item Actions
  • Verify that state, assignee, and priority actions in Command K update correctly without errors.
  1. Work Item Context Indicator
  • Ensure the context indicator displays properly.

References

[WEB-3357 | WEB-3363 | WEB-3370]

Summary by CodeRabbit

  • New Features

    • Enhanced the command modal with an intuitive close button for issue search, allowing for clearer control over viewing detailed issue information.
    • Introduced new state management for issue searching, improving user interaction.
  • Refactor

    • Streamlined the issue update process and state management, resulting in more consistent behavior.
    • Optimized feedback notifications for operations, ensuring concise and reliable user responses.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

Walkthrough

This pull request refactors several components within the command palette. The primary change is replacing the usage of the useIssues hook with the useIssueDetail hook to directly extract the updateIssue function. In addition, type declarations have been condensed into a single line and error/toast handling has been simplified. The command modal component was also modified by introducing a new state variable and related logic for managing issue search behavior, alongside updating the UI with an added close icon.

Changes

Files Change Summary
web/core/components/command-palette/actions/issue-actions/actions-list.tsx
web/core/components/command-palette/actions/issue-actions/change-assignee.tsx
web/core/components/command-palette/actions/issue-actions/change-priority.tsx
web/core/components/command-palette/actions/issue-actions/change-state.tsx
Replaced the useIssues hook with useIssueDetail to directly extract updateIssue. Condensed type declarations and simplified toast/error handling in these issue action components.
web/core/components/command-palette/command-modal.tsx Added an import for the X icon, adjusted the initial state (isWorkspaceLevel now set to false), introduced a new state variable (searchInIssue) with a corresponding useEffect hook, and updated the UI logic for issue details.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant CM as CommandModal
    participant SE as State Effect
    participant UI as UI Elements

    U->>CM: Open command palette
    CM->>SE: Check if issueDetails exist
    SE-->>CM: Set searchInIssue to true
    U->>UI: View issue details with close (X) button
    U->>CM: Click close (X) button
    CM->>UI: Set searchInIssue to false
Loading

Possibly related PRs

Suggested labels

🌟enhancement, 🧹chore

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • rahulramesha

Poem

Oh, I’m a rabbit with code so spry,
Hopping through hooks as the changes fly.
With useIssueDetail as my secret key,
My nibbling fixes set the issues free.
A carrot treat for a job so neat! 🥕
Happy hops and clean commits complete!


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: 1

🧹 Nitpick comments (7)
web/core/components/command-palette/actions/issue-actions/change-priority.tsx (1)

26-33: Enhance error handling in submitChanges.

The current error handling only logs to console. Consider adding user feedback for failed operations.

 const submitChanges = async (formData: Partial<TIssue>) => {
   if (!workspaceSlug || !projectId || !issue) return;

   const payload = { ...formData };
-  await updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, payload).catch((e) => {
-    console.error(e);
-  });
+  try {
+    await updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, payload);
+  } catch (error) {
+    console.error(error);
+    setToast({ type: TOAST_TYPE.ERROR, title: "Failed to update priority" });
+  }
 };
web/core/components/command-palette/actions/issue-actions/change-state.tsx (1)

25-32: Enhance error handling in submitChanges.

The current error handling only logs to console. Consider adding user feedback for failed operations.

 const submitChanges = async (formData: Partial<TIssue>) => {
   if (!workspaceSlug || !projectId || !issue) return;

   const payload = { ...formData };
-  await updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, payload).catch((e) => {
-    console.error(e);
-  });
+  try {
+    await updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, payload);
+  } catch (error) {
+    console.error(error);
+    setToast({ type: TOAST_TYPE.ERROR, title: "Failed to update state" });
+  }
 };
web/core/components/command-palette/actions/issue-actions/change-assignee.tsx (1)

58-65: Enhance error handling in handleUpdateIssue.

The current error handling only logs to console. Consider adding user feedback for failed operations.

 const handleUpdateIssue = async (formData: Partial<TIssue>) => {
   if (!workspaceSlug || !projectId || !issue) return;

   const payload = { ...formData };
-  await updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, payload).catch((e) => {
-    console.error(e);
-  });
+  try {
+    await updateIssue(workspaceSlug.toString(), projectId.toString(), issue.id, payload);
+  } catch (error) {
+    console.error(error);
+    setToast({ type: TOAST_TYPE.ERROR, title: "Failed to update assignees" });
+  }
 };
web/core/components/command-palette/actions/issue-actions/actions-list.tsx (1)

33-40: Enhance error handling in handleUpdateIssue.

The current error handling only logs to console. Consider adding user feedback for failed operations.

 const handleUpdateIssue = async (formData: Partial<TIssue>) => {
   if (!workspaceSlug || !projectId || !issueDetails) return;

   const payload = { ...formData };
-  await updateIssue(workspaceSlug.toString(), projectId.toString(), issueDetails.id, payload).catch((e) => {
-    console.error(e);
-  });
+  try {
+    await updateIssue(workspaceSlug.toString(), projectId.toString(), issueDetails.id, payload);
+  } catch (error) {
+    console.error(error);
+    setToast({ type: TOAST_TYPE.ERROR, title: "Failed to update issue" });
+  }
 };
web/core/components/command-palette/command-modal.tsx (3)

59-64: Consider using TypeScript type for the results state.

The results state initialization could benefit from explicit TypeScript typing to improve type safety and code maintainability.

-  const [results, setResults] = useState<IWorkspaceSearchResults>({
-    results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] },
-  });
+  const [results, setResults] = useState<IWorkspaceSearchResults>(() => ({
+    results: {
+      workspace: [] as const,
+      project: [] as const,
+      issue: [] as const,
+      cycle: [] as const,
+      module: [] as const,
+      issue_view: [] as const,
+      page: [] as const,
+    },
+  }));

93-97: Consider cleanup in useEffect.

The useEffect hook should clean up its side effects when the component unmounts or when dependencies change.

  useEffect(() => {
    if (issueDetails && isCommandPaletteOpen) {
      setSearchInIssue(true);
    }
+   return () => {
+     setSearchInIssue(false);
+   };
  }, [issueDetails, isCommandPaletteOpen]);

238-267: Consider extracting the issue context indicator to a separate component.

The issue context indicator UI logic is complex enough to warrant its own component, which would improve maintainability and reusability.

+ // IssueContextIndicator.tsx
+ interface IssueContextIndicatorProps {
+   issueDetails: any; // Replace with proper type
+   onClose: () => void;
+ }
+ 
+ const IssueContextIndicator: React.FC<IssueContextIndicatorProps> = ({ issueDetails, onClose }) => (
+   <>
+     <span className="flex items-center text-sm">Update in:</span>
+     <span className="flex items-center gap-1 rounded px-1.5 py-1 text-sm bg-custom-primary-100/10 ">
+       {issueDetails.project_id && (
+         <IssueIdentifier
+           issueId={issueDetails.id}
+           projectId={issueDetails.project_id}
+           textContainerClassName="text-sm text-custom-primary-200"
+         />
+       )}
+       <X
+         size={12}
+         strokeWidth={2}
+         className="flex-shrink-0 cursor-pointer"
+         onClick={onClose}
+       />
+     </span>
+   </>
+ );

// In CommandModal component
- {searchInIssue && issueDetails && (
-   <>
-     <span className="flex items-center text-sm">Update in:</span>
-     ...
-   </>
- )}
+ {searchInIssue && issueDetails && (
+   <IssueContextIndicator
+     issueDetails={issueDetails}
+     onClose={() => setSearchInIssue(false)}
+   />
+ )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b88ae11 and 28f454c.

📒 Files selected for processing (5)
  • web/core/components/command-palette/actions/issue-actions/actions-list.tsx (3 hunks)
  • web/core/components/command-palette/actions/issue-actions/change-assignee.tsx (1 hunks)
  • web/core/components/command-palette/actions/issue-actions/change-priority.tsx (1 hunks)
  • web/core/components/command-palette/actions/issue-actions/change-state.tsx (1 hunks)
  • web/core/components/command-palette/command-modal.tsx (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (8)
web/core/components/command-palette/actions/issue-actions/change-priority.tsx (1)

8-8: LGTM! Clean hook refactoring.

The switch from useIssues to useIssueDetail makes the code more focused and direct.

Also applies to: 13-13

web/core/components/command-palette/actions/issue-actions/change-state.tsx (1)

10-10: LGTM! Clean hook refactoring.

The switch from useIssues to useIssueDetail makes the code more focused and direct.

web/core/components/command-palette/actions/issue-actions/change-assignee.tsx (1)

14-14: LGTM! Clean hook refactoring.

The switch from useIssues to useIssueDetail makes the code more focused and direct.

Also applies to: 23-23

web/core/components/command-palette/actions/issue-actions/actions-list.tsx (2)

13-13: LGTM! Clean hook refactoring.

The switch from useIssues to useIssueDetail makes the code more focused and direct.

Also applies to: 29-29


65-65: LGTM! Clean toast message handling.

The toast messages have been simplified while maintaining clarity.

Also applies to: 68-68

web/core/components/command-palette/command-modal.tsx (3)

8-8: LGTM! Imports are properly organized.

The new imports for X icon and cn utility function are correctly added and align with the component's enhanced functionality.

Also applies to: 15-15


217-217: LGTM! Smooth scrolling behavior added.

The addition of smooth scrolling behavior improves the user experience when navigating through items.


269-271: LGTM! Improved className handling with cn utility.

The use of the cn utility function for className composition is a good practice for managing conditional classes.

Comment on lines +147 to +156
<Dialog
as="div"
className="relative z-30"
onClose={() => {
closePalette();
if (searchInIssue) {
setSearchInIssue(true);
}
}}
>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix potential infinite loop in Dialog onClose.

The onClose handler sets searchInIssue to true when it's already true, which could lead to unnecessary re-renders.

  <Dialog
    as="div"
    className="relative z-30"
    onClose={() => {
      closePalette();
-     if (searchInIssue) {
-       setSearchInIssue(true);
-     }
    }}
  >
📝 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.

Suggested change
<Dialog
as="div"
className="relative z-30"
onClose={() => {
closePalette();
if (searchInIssue) {
setSearchInIssue(true);
}
}}
>
<Dialog
as="div"
className="relative z-30"
onClose={() => {
closePalette();
}}
>

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 (4)
web/core/components/command-palette/command-modal.tsx (4)

60-64: State initialization can be simplified.

The results state initialization can be further simplified using object shorthand notation since the property name matches the value name.

-  const [results, setResults] = useState<IWorkspaceSearchResults>({
-    results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] },
-  });
+  const [results, setResults] = useState<IWorkspaceSearchResults>({
+    results: { workspace: [], project: [], issue: [], cycle: [], module: [], issue_view: [], page: [] }
+  });

93-97: Consider adding cleanup for searchInIssue state.

The useEffect hook sets searchInIssue but doesn't clean up when the modal closes.

 useEffect(() => {
   if (issueDetails && isCommandPaletteOpen) {
     setSearchInIssue(true);
   }
+  return () => {
+    if (!isCommandPaletteOpen) {
+      setSearchInIssue(false);
+    }
+  };
 }, [issueDetails, isCommandPaletteOpen]);

99-105: Simplify isWorkspaceLevel logic.

The isWorkspaceLevel useEffect can be simplified to a single condition.

 useEffect(() => {
-  if (!projectId && !isWorkspaceLevel) {
-    setIsWorkspaceLevel(true);
-  } else {
-    setIsWorkspaceLevel(false);
-  }
+  setIsWorkspaceLevel(!projectId);
 }, [projectId]);

246-275: Consider extracting issue context indicator to a separate component.

The issue context indicator UI logic is complex enough to warrant its own component for better maintainability.

+const IssueContextIndicator: React.FC<{
+  issueDetails: any;
+  onClose: () => void;
+}> = ({ issueDetails, onClose }) => (
+  <>
+    <span className="flex items-center text-sm">Update in:</span>
+    <span className="flex items-center gap-1 rounded px-1.5 py-1 text-sm bg-custom-primary-100/10 ">
+      {issueDetails.project_id && (
+        <IssueIdentifier
+          issueId={issueDetails.id}
+          projectId={issueDetails.project_id}
+          textContainerClassName="text-sm text-custom-primary-200"
+        />
+      )}
+      <X
+        size={12}
+        strokeWidth={2}
+        className="flex-shrink-0 cursor-pointer"
+        onClick={onClose}
+      />
+    </span>
+  </>
+);

 // Then in the main component:
 {searchInIssue && issueDetails && (
   <IssueContextIndicator
     issueDetails={issueDetails}
     onClose={() => setSearchInIssue(false)}
   />
 )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 28f454c and f381e06.

📒 Files selected for processing (1)
  • web/core/components/command-palette/command-modal.tsx (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
web/core/components/command-palette/command-modal.tsx (2)

155-164: Fix potential infinite loop in Dialog onClose.

The onClose handler sets searchInIssue to true when it's already true, which could lead to unnecessary re-renders.


277-279: LGTM: Improved className handling.

Good use of the cn utility for className concatenation.

@sriramveeraghanta sriramveeraghanta merged commit 82eea3e into preview Feb 14, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore-command-k-enhancement-and-fixes branch February 14, 2025 13:34
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
…es (#6600)

* fix: command-k work item actions

* chore: command k work item context indicator improvement and default vale for workspace toggle updated

* chore: code refactor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants