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

Optional welcome dialog #1440

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Optional welcome dialog #1440

wants to merge 6 commits into from

Conversation

alex-Arc
Copy link
Collaborator

@alex-Arc alex-Arc commented Jan 9, 2025

Restructures the way we handle the welcome dialogs, making it easier to test as it can now be requested with search parameter and also allowing search parameter to diable it.

This is very beneficial as it can sometimes block the e2e test especially if run locally or out of order.

It also gives uses the option to dismis the dialog forever. Their is currently no way to get it back through the UI, it is easy to do I'm just not sure where it should be placed.

?skip-welcome will save in local storage to not show
?show-welcome will reverse that
?dialog=welcome will force it to show

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The pull request introduces a new dialog management system for a React application, transitioning from a Zustand store-based approach to a custom hook-based solution. The changes include creating a new useDialogHook with enum-based dialog keys, updating import statements across multiple files, and modifying the Welcome dialog component to support skipping functionality. The implementation allows for more flexible dialog visibility management using URL query parameters and local storage.

Changes

File Change Summary
apps/client/src/common/hooks/useDialogHook.ts - Added DialogKeys enum
- Implemented addDialog function
- Created useDialog hook with dialog state management
apps/client/src/common/hooks/useElectronEvent.ts - Updated addDialog import from useDialogHook
apps/client/src/common/stores/dialogStore.ts - Completely removed Zustand dialog store
apps/client/src/common/utils/socket.ts - Updated addDialog import
- Added logging for welcome dialog trigger
apps/client/src/features/editors/welcome/Welcome.tsx - Added skipDialog to WelcomeProps
- Updated component to support skipping dialog
apps/client/src/features/editors/welcome/WelcomePlacement.tsx - Replaced useDialogStore with useDialog
- Updated dialog rendering logic
- Added skipDialog functionality

Finishing Touches

  • 📝 Generate Docstrings

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.

@alex-Arc
Copy link
Collaborator Author

alex-Arc commented Jan 9, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 9, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (5)
apps/client/src/features/editors/welcome/WelcomePlacement.tsx (1)

8-10: Verify dialog visibility logic.

The condition showDialog !== 'welcome' might be better expressed as an enum value for type safety.

Consider using an enum for dialog types:

-  if (!showDialog || showDialog !== 'welcome') {
+  if (!showDialog || showDialog !== DialogKeys.Welcome) {

This would require adding Welcome = 'welcome' to the DialogKeys enum.

apps/client/src/common/hooks/useDialogHook.ts (2)

6-8: Consider expanding DialogKeys enum.

Add a Welcome key to maintain consistency and type safety across the application.

 export enum DialogKeys {
   SkipWelcome = 'ontime-skip-welcome',
+  Welcome = 'welcome',
 }

24-26: Simplify boolean expressions.

The ternary operators for boolean values can be simplified.

-  const skipWelcomeDialog = searchParams.get('skip-welcome') === null ? false : true;
-  const showWelcomeDialog = searchParams.get('show-welcome') === null ? false : true;
+  const skipWelcomeDialog = searchParams.get('skip-welcome') !== null;
+  const showWelcomeDialog = searchParams.get('show-welcome') !== null;
🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 26-26: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

apps/client/src/features/editors/welcome/Welcome.tsx (1)

15-16: Consider adding JSDoc for props interface.

Adding documentation for the new skipDialog prop would improve maintainability.

 interface WelcomeProps {
+  /** Callback to permanently dismiss the welcome dialog */
   skipDialog: () => void;
 }
apps/client/src/common/utils/socket.ts (1)

125-126: Consider removing or guarding the console.log statement.

While logging can be helpful during development, it's generally not recommended to keep debug logs in production code.

Consider either:

  1. Removing the log statement, or
  2. Guarding it with the existing isProduction flag:
-            console.log('w dialog');
+            if (!isProduction) {
+              console.log('w dialog');
+            }
             addDialog('welcome');
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e9a7cd0 and 52d1c56.

⛔ Files ignored due to path filters (8)
  • e2e/tests/000-upload-showfile.spec.ts is excluded by none and included by none
  • e2e/tests/001-smoke-tests.spec.ts is excluded by none and included by none
  • e2e/tests/features/203-delay-block.spec.ts is excluded by none and included by none
  • e2e/tests/features/204-editor-crud.spec.ts is excluded by none and included by none
  • e2e/tests/features/205-operator.spec.ts is excluded by none and included by none
  • e2e/tests/features/206-url-preset.spec.ts is excluded by none and included by none
  • e2e/tests/features/208-auxtimer.spec.ts is excluded by none and included by none
  • e2e/tests/features/301-spreadsheet-import.spec.ts is excluded by none and included by none
📒 Files selected for processing (6)
  • apps/client/src/common/hooks/useDialogHook.ts (1 hunks)
  • apps/client/src/common/hooks/useElectronEvent.ts (1 hunks)
  • apps/client/src/common/stores/dialogStore.ts (0 hunks)
  • apps/client/src/common/utils/socket.ts (2 hunks)
  • apps/client/src/features/editors/welcome/Welcome.tsx (2 hunks)
  • apps/client/src/features/editors/welcome/WelcomePlacement.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/client/src/common/stores/dialogStore.ts
🧰 Additional context used
🪛 Biome (1.9.4)
apps/client/src/common/hooks/useDialogHook.ts

[error] 25-25: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 26-26: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e-test
🔇 Additional comments (7)
apps/client/src/features/editors/welcome/WelcomePlacement.tsx (2)

1-1: LGTM! Clean transition to hook-based approach.

The change from useDialogStore to useDialog hook improves testability and maintainability.

Also applies to: 6-6


15-18: LGTM! Clear skip dialog implementation.

The implementation correctly handles both clearing the current dialog and setting the skip preference.

apps/client/src/common/hooks/useElectronEvent.ts (1)

4-4: Verify electron dialog handling with new hook.

While the import change is correct, we should ensure the electron dialog handling still works as expected with the new hook-based approach.

✅ Verification successful

Import change maintains dialog handling consistency

The new hook-based approach maintains the same dialog handling pattern across both websocket and electron events, ensuring consistent behavior.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for any other electron dialog handlers that might need updating
rg -l "dialog.*welcome" --type ts

Length of output: 168


Script:

#!/bin/bash
# Check the context of dialog usage in these files
echo "=== WebsocketAdapter.ts ==="
rg "dialog.*welcome" apps/server/src/adapters/WebsocketAdapter.ts -B 2 -A 2

echo -e "\n=== socket.ts ==="
rg "dialog.*welcome" apps/client/src/common/utils/socket.ts -B 2 -A 2

echo -e "\n=== useElectronEvent.ts ==="
rg "dialog.*welcome" apps/client/src/common/hooks/useElectronEvent.ts -B 2 -A 2

Length of output: 874

apps/client/src/common/hooks/useDialogHook.ts (1)

28-35: LGTM! Clear persistence logic.

The effect hook correctly handles the persistence of dialog preferences in local storage.

apps/client/src/features/editors/welcome/Welcome.tsx (1)

85-87: LGTM! Clear user interaction for dialog dismissal.

The "Do not show again" button is well-placed and provides clear user feedback.

apps/client/src/common/utils/socket.ts (2)

6-6: LGTM! Import change aligns with architectural shift.

The change from store-based to hook-based dialog management aligns with the PR's objective of restructuring welcome dialog handling.

Let's verify if this architectural change is consistently applied across the codebase:

✅ Verification successful

Import change verified - consistent architectural shift

The migration from store-based to hook-based dialog management is complete and consistent across the codebase. No remaining references to the old approach were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining imports from dialogStore
rg "from.*stores/dialogStore"

# Search for new hook usage
rg "from.*hooks/useDialogHook"

Length of output: 294


Script:

#!/bin/bash
# Search for any remaining dialog store references
rg -i "dialogstore|dialog[^h].*store"

# Search for dialog-related patterns
ast-grep --pattern 'dialog'

# Check for any store files related to dialogs
fd -e ts -e tsx "dialog.*store"

Length of output: 612


124-128: Verify interaction between WebSocket and URL parameter controls.

Given that the PR introduces URL parameters (?skip-welcome, ?show-welcome) to control the welcome dialog, we should ensure that the WebSocket-triggered dialog respects these settings. The current implementation might show the dialog even when it's meant to be skipped via URL parameters.

Consider checking the user's preferences before showing the dialog:

         case 'dialog': {
           if (payload.dialog === 'welcome') {
             if (!isProduction) {
               console.log('w dialog');
             }
-            addDialog('welcome');
+            // Assuming useDialogHook exports a function to check if dialog should be shown
+            if (shouldShowDialog('welcome')) {
+              addDialog('welcome');
+            }
           }
           break;
         }

Comment on lines +13 to +19
export function addDialog(name: string): void {
if (booleanFromLocalStorage(DialogKeys.SkipWelcome, false) && name === 'welcome') return;

const urlParams = new URLSearchParams(window.location.search);
urlParams.append('dialog', name);
window.location.search = urlParams.toString();
}
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

Potential race condition in addDialog.

The direct manipulation of window.location.search could lead to lost parameters if multiple dialogs are added simultaneously.

Consider using the URLSearchParams API more safely:

 export function addDialog(name: string): void {
   if (booleanFromLocalStorage(DialogKeys.SkipWelcome, false) && name === 'welcome') return;

   const urlParams = new URLSearchParams(window.location.search);
   urlParams.append('dialog', name);
-  window.location.search = urlParams.toString();
+  const newUrl = new URL(window.location.href);
+  newUrl.search = urlParams.toString();
+  window.history.pushState({}, '', newUrl);
 }
📝 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
export function addDialog(name: string): void {
if (booleanFromLocalStorage(DialogKeys.SkipWelcome, false) && name === 'welcome') return;
const urlParams = new URLSearchParams(window.location.search);
urlParams.append('dialog', name);
window.location.search = urlParams.toString();
}
export function addDialog(name: string): void {
if (booleanFromLocalStorage(DialogKeys.SkipWelcome, false) && name === 'welcome') return;
const urlParams = new URLSearchParams(window.location.search);
urlParams.append('dialog', name);
const newUrl = new URL(window.location.href);
newUrl.search = urlParams.toString();
window.history.pushState({}, '', newUrl);
}

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