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

Add dialog while waiting for rules to process #296

Merged
merged 4 commits into from
Jan 9, 2025
Merged

Conversation

elie222
Copy link
Owner

@elie222 elie222 commented Jan 8, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced dialog navigation for processing prompt files
    • Improved step-by-step workflow with more modular step components
    • Added result tracking for rule processing actions
    • Introduced a new function for pluralizing strings
  • Refactor

    • Simplified dialog state management
    • Restructured step navigation logic
    • Removed unused components and props
    • Eliminated carousel functionality from the application
  • Bug Fixes

    • Improved dialog functionality and user interaction flow
    • Fixed state management for dialog visibility and result handling

Copy link

vercel bot commented Jan 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
inbox-zero ✅ Ready (Inspect) Visit Preview Jan 9, 2025 8:14pm

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request focuses on significant refactoring of the ProcessingPromptFileDialog component in the web application's automation module. Key changes include the removal of the isLoading prop, the introduction of new step components, and a restructuring of the dialog's step navigation logic. Additionally, the RulesPrompt.tsx file has been updated to import and utilize the modified dialog, enhancing the integration of the processing prompt functionality. The carousel component has been entirely removed, along with its associated types and dependencies.

Changes

File Change Summary
apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx - Removed isLoading prop
- Introduced new step components (IntroStep, Step1, Step2, Step3, FinalStepWaiting, FinalStepReady)
- Added new type definitions (StepProps, StepContentProps, ResultProps)
- Refactored step navigation using useCallback
- Simplified dialog content rendering
apps/web/app/(app)/automation/RulesPrompt.tsx - Uncommented ProcessingPromptFileDialog import
- Restored isDialogOpen and result state variables
- Enabled dialog rendering with updated props
apps/web/components/ui/carousel.tsx - Entire file removed, eliminating carousel functionality and associated types
apps/web/package.json - Removed dependency on "embla-carousel-react": "^8.5.1"
apps/web/utils/string.ts - Added pluralize function to handle pluralization of words

Possibly related PRs

Poem

🐰 In a dialog's dance, the steps now align,
Hopping through prompts, all functions combine.
Components now leap, with clarity bright,
Refactored with joy, taking code to new heights.
A rabbit's delight in each line we write! 🚀


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 01038ab and 5457d28.

📒 Files selected for processing (2)
  • apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (1 hunks)
  • apps/web/app/(app)/automation/RulesPrompt.tsx (7 hunks)

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.

@elie222 elie222 changed the title Add dialog while waiting for rules to process WIP: Add dialog while waiting for rules to process Jan 8, 2025
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)
apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (4)

59-65: Remove or implement commented className logic.

The commented className logic suggests incomplete styling decisions. Either implement the conditional styling or remove the comments to maintain code clarity.


66-82: Consider simplifying step rendering logic.

The current step rendering logic could be simplified using an object map or switch statement for better maintainability.

-        {currentStep === 0 && <IntroStep next={next} />}
-        {currentStep === 1 && <Step1 back={back} next={next} />}
-        {currentStep === 2 && <Step2 back={back} next={next} />}
-        {currentStep === 3 && <Step3 back={back} next={next} />}
+        {(() => {
+          const steps = {
+            0: <IntroStep next={next} />,
+            1: <Step1 back={back} next={next} />,
+            2: <Step2 back={back} next={next} />,
+            3: <Step3 back={back} next={next} />
+          };
+          return currentStep <= 3 ? steps[currentStep as keyof typeof steps] : (
+            result ? (
+              <FinalStepReady
+                back={back}
+                next={() => onOpenChange(false)}
+                result={result}
+              />
+            ) : (
+              <FinalStepWaiting back={back} />
+            )
+          );
+        })()}

211-216: Maintain consistent navigation layout.

The button layout in FinalStepReady differs from the StepNavigation pattern used in other steps. Consider using the StepNavigation component here for consistency.

-      <div className="flex justify-center">
-        <Button variant="outline" onClick={back}>
-          Back
-        </Button>
-        <Button onClick={next}>Test them now!</Button>
-      </div>
+      <div className="flex justify-center">
+        <StepNavigation
+          back={back}
+          next={next}
+          nextText="Test them now!"
+        />
+      </div>

243-393: Remove commented out carousel implementation.

Large blocks of commented out code should be removed as they add unnecessary noise to the codebase. The code can be retrieved from Git history if needed in the future.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b3735ad and c5efe93.

📒 Files selected for processing (2)
  • apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (3 hunks)
  • apps/web/app/(app)/automation/RulesPrompt.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (6)
apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (2)

13-27: Well-structured type definitions!

The new type definitions are clear, reusable, and follow TypeScript best practices. The hierarchy from StepProps to StepContentProps is logical and promotes code reuse.


88-115: Well-designed reusable components!

The StepNavigation and Step components are well-structured, promoting consistency and reusability across all dialog steps.

apps/web/app/(app)/automation/RulesPrompt.tsx (4)

39-39: LGTM!

The import statement is correctly structured and follows the project's import conventions.


94-99: LGTM!

The state management is well-structured with appropriate types for tracking dialog state and processing results.


143-144: Consider handling concurrent submissions.

While the dialog management is good, there's a potential race condition if multiple submissions occur simultaneously. Consider adding a guard clause or disabling the submit button while processing.

Run this script to check for other similar patterns in the codebase:

Also applies to: 149-149


186-190: Verify dialog accessibility implementation.

The dialog integration looks good, but ensure that the ProcessingPromptFileDialog component implements proper accessibility features such as:

  • Keyboard navigation
  • Screen reader announcements for processing status
  • Focus management

Run this script to check the dialog component's accessibility implementation:

✅ Verification successful

Dialog implementation has proper accessibility features

The Dialog component is built on RadixUI's Dialog primitive, which provides comprehensive accessibility features including:

  • Proper ARIA attributes and roles
  • Keyboard navigation and focus management
  • Screen reader announcements
  • Focus trap within the dialog
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for accessibility-related attributes in the dialog component
rg -A 5 'aria-|role=|tabIndex|onKeyDown' "automation/ProcessingPromptFileDialog"

Length of output: 158


Script:

#!/bin/bash
# Find the dialog component file
fd -t f "ProcessingPromptFileDialog" 

# Once found, examine its contents
fd -t f "ProcessingPromptFileDialog" -x cat {}

Length of output: 11203


Script:

#!/bin/bash
# Look for the base Dialog component
fd -t f "dialog.tsx" "components/ui"

# If found, examine its contents
fd -t f "dialog.tsx" "components/ui" -x cat {}

Length of output: 283


Script:

#!/bin/bash
# Search for dialog component file anywhere in the repository
fd -t f "dialog.tsx"

# Search for Dialog component usage patterns
ast-grep --pattern 'import { Dialog } from "@/components'

Length of output: 263


Script:

#!/bin/bash
# Examine the base Dialog component
cat apps/web/components/ui/dialog.tsx

# Look for accessibility-related patterns
rg -A 3 'aria-|role=|focus|keydown' apps/web/components/ui/dialog.tsx

Length of output: 4765

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/web/utils/string.ts (1)

40-46: Consider enhancing pluralization logic for edge cases

While the current implementation works for basic cases, consider these improvements:

  1. Handle irregular plurals (e.g., child → children)
  2. Support special English rules (e.g., words ending in 'y', 'f')
  3. Add input validation for negative numbers

Example enhancement:

+const IRREGULAR_PLURALS = {
+  child: "children",
+  person: "people",
+  // Add more as needed
+};
+
 export function pluralize(
   count: number,
   singular: string,
   plural = `${singular}s`,
 ) {
+  if (count < 0) throw new Error("Count must be non-negative");
+  if (IRREGULAR_PLURALS[singular]) {
+    return count === 1 ? singular : IRREGULAR_PLURALS[singular];
+  }
   return count === 1 ? singular : plural;
 }
apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (5)

15-29: LGTM! Well-structured type definitions.

The type definitions are clean and follow TypeScript best practices. The separation of concerns between StepProps, StepContentProps, and ResultProps is well thought out.

Consider making the step types more reusable by moving them to a separate types file, as they might be useful in other dialog components:

+// types/dialog.ts
+export type StepProps = {
+  back?: () => void;
+  next?: () => void;
+};
+
+export type StepContentProps = StepProps & {
+  title: string;
+  children: React.ReactNode;
+};

61-67: Clean up commented code.

There are commented className configurations that should either be removed or implemented. Commented code can lead to confusion and maintenance issues.

Either remove the commented code or implement it with a clear explanation of its purpose:

-      // className={
-      //   currentStep !== 0
-      //     ? "max-h-[90vh] overflow-y-auto px-0 sm:max-w-7xl"
-      //     : undefined
-      // }
+      className="max-h-[90vh] overflow-y-auto px-0 sm:max-w-7xl"

90-117: Enhance accessibility for navigation components.

While the navigation components are well-structured, they could benefit from improved accessibility.

Consider these accessibility improvements:

 function StepNavigation({ back, next }: StepProps) {
   return (
-    <div className="flex gap-2">
+    <nav className="flex gap-2" aria-label="Dialog navigation">
       {back && (
-        <Button variant="outline" onClick={back}>
+        <Button 
+          variant="outline" 
+          onClick={back}
+          aria-label="Go to previous step"
+        >
           Back
         </Button>
       )}
-      {next && <Button onClick={next}>Next</Button>}
+      {next && (
+        <Button 
+          onClick={next}
+          aria-label="Proceed to next step"
+        >
+          Next
+        </Button>
+      )}
-    </div>
+    </nav>
   );
 }

147-153: Optimize image loading behavior.

The Image components could benefit from optimization attributes for better user experience.

Add loading and priority attributes to improve image loading behavior:

 <Image
   src="/images/automation/rules.png"
   alt="Analyzing prompt file"
   width={500}
   height={300}
+  loading="eager"
+  priority={true}
   className="rounded-lg shadow"
 />

Also applies to: 162-168, 183-189


218-243: Simplify message construction logic.

The message construction in getDescription could be simplified using array methods.

Consider this more maintainable approach:

 function getDescription() {
-  let message = "";
-
-  if (result.createdRules > 0) {
-    message += `We've created ${result.createdRules} ${pluralize(
-      result.createdRules,
-      "rule",
-    )} for you.`;
-  }
-
-  if (result.editedRules > 0) {
-    message += ` We edited ${result.editedRules} ${pluralize(
-      result.editedRules,
-      "rule",
-    )}.`;
-  }
-
-  if (result.removedRules > 0) {
-    message += ` We removed ${result.removedRules} ${pluralize(
-      result.removedRules,
-      "rule",
-    )}.`;
-  }
-
-  return message;
+  const messages = [
+    result.createdRules > 0 && 
+      `We've created ${result.createdRules} ${pluralize(result.createdRules, "rule")} for you`,
+    result.editedRules > 0 && 
+      `We edited ${result.editedRules} ${pluralize(result.editedRules, "rule")}`,
+    result.removedRules > 0 && 
+      `We removed ${result.removedRules} ${pluralize(result.removedRules, "rule")}`,
+  ].filter(Boolean);
+  
+  return messages.join(". ") + ".";
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c5efe93 and 01038ab.

⛔ Files ignored due to path filters (4)
  • apps/web/public/images/automation/process.png is excluded by !**/*.png
  • apps/web/public/images/automation/rule-edit.png is excluded by !**/*.png
  • apps/web/public/images/automation/rules.png is excluded by !**/*.png
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (2 hunks)
  • apps/web/components/ui/carousel.tsx (0 hunks)
  • apps/web/package.json (0 hunks)
  • apps/web/utils/string.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • apps/web/package.json
  • apps/web/components/ui/carousel.tsx
🔇 Additional comments (2)
apps/web/utils/string.ts (1)

40-46: Implementation looks good for basic pluralization needs!

The function provides a clean and simple way to handle basic English pluralization.

apps/web/app/(app)/automation/ProcessingPromptFileDialog.tsx (1)

50-56: LGTM! Clean step management implementation.

The step navigation logic using useCallback is well-implemented, and the conditional rendering of steps is clear and maintainable.

Also applies to: 73-84

@elie222 elie222 changed the title WIP: Add dialog while waiting for rules to process Add dialog while waiting for rules to process Jan 9, 2025
@elie222 elie222 merged commit 050bbd4 into main Jan 9, 2025
2 of 4 checks passed
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.

1 participant