Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Oct 29, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a delete functionality for notifications, allowing users to remove specific notifications.
    • Added a formatted timestamp to notifications for enhanced information display.
  • Bug Fixes

    • Improved loading states for archive and delete operations to enhance user experience.
  • Documentation

    • Updated documentation for the GraphQL functions to include new mutations and their usage.

These updates enhance the notification management system, providing users with more control and improved information visibility.


@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The changes introduce a delete functionality for notifications in the system. This includes the addition of a deleteNotification mutation in the GraphQL schema, which allows users to delete notifications based on their ID and type. The front-end component Item.vue is updated to handle the new delete operation, including loading states and conditional rendering of buttons. Additional updates include enhancements to the Apollo cache to manage deleted notifications and the introduction of a new field in the Notification type for formatted timestamps.

Changes

File Path Change Summary
web/components/Notifications/Item.vue Added delete functionality for notifications; introduced deleteNotification mutation; updated loading states; modified button rendering based on notification type; added mutationError computed property.
web/components/Notifications/graphql/notification.query.ts Added deleteNotification mutation accepting id and type parameters, returning an object with an archive field.
web/composables/gql/gql.ts Introduced DeleteNotification mutation in the documents map; updated graphql function signature to include the new mutation; updated documentation comments.
web/composables/gql/graphql.ts Added formattedTimestamp to Notification type; introduced DeleteNotificationMutation with required variables; defined query and mutation documents for DeleteNotification.
web/helpers/apollo-cache/index.ts Added deleteNotification field in Apollo cache's Mutation type policies; implemented a merge function to handle cache eviction for deleted notifications; refined existing merge logic for better readability.
web/composables/gql/typename.ts Introduced NotificationType constant for Apollo cache reference.

Possibly related PRs

Suggested reviewers

  • zackspear
  • elibosley
  • mdatelle

Poem

🐇 In the meadow where notifications play,
A delete button hops in, bright as day.
With a click, they vanish, poof, and gone,
Leaving only the memories, like dew at dawn.
Archive or delete, the choice is clear,
Hooray for new features, let’s give a cheer! 🎉


🪧 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 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: 6

🧹 Outside diff range and nitpick comments (2)
web/components/Notifications/Item.vue (1)

42-54: Consider renaming deleteFromServer for consistency

The mutation setup is well-structured, and the renaming of loading to archiveInProgress improves clarity. However, for consistency with the archive mutation naming, consider renaming deleteFromServer to remove or delete.

-const { mutate: deleteFromServer, loading: deleting } = useMutation(
+const { mutate: delete, loading: deleting } = useMutation(
web/composables/gql/gql.ts (1)

61-64: Enhance the documentation comment for DeleteNotification.

The current documentation comment is generic. Consider adding specific details about the mutation's purpose and parameters.

Example enhancement:

 /**
  * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
+ *
+ * @description Mutation to delete a notification by its ID and type from the archive view
+ * @param {string} id - The unique identifier of the notification to delete
+ * @param {NotificationType} type - The type of the notification
+ * @returns {Promise<{ archive: { total: number } }>} The updated archive total after deletion
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fc9bd8f and 3d28b03.

📒 Files selected for processing (5)
  • web/components/Notifications/Item.vue (3 hunks)
  • web/components/Notifications/graphql/notification.query.ts (1 hunks)
  • web/composables/gql/gql.ts (2 hunks)
  • web/composables/gql/graphql.ts (3 hunks)
  • web/helpers/apollo-cache/index.ts (2 hunks)
🔇 Additional comments (8)
web/components/Notifications/graphql/notification.query.ts (1)

51-59: Verify the NotificationType enum usage.

The mutation requires a NotificationType enum parameter. Let's verify its definition in the schema.

✅ Verification successful

NotificationType enum is properly defined and matches the mutation usage

The NotificationType enum is correctly defined in both frontend (web/composables/gql/graphql.ts) and backend (api/src/graphql/generated/api/types.ts) with matching values ARCHIVE and UNREAD. The mutation's type parameter usage is valid and consistent with the schema definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for NotificationType enum definition
ast-grep --pattern 'enum NotificationType {
  $$$
}'

Length of output: 518

web/components/Notifications/Item.vue (1)

8-17: LGTM: Import changes are well-structured

The new imports for TrashIcon and deleteNotification mutation are properly organized and align with the feature requirements.

web/helpers/apollo-cache/index.ts (1)

53-55: LGTM! Clean formatting improvement.

The restructured format for passing the offset parameter improves readability while maintaining the same functionality.

web/composables/gql/gql.ts (1)

20-20: Verify GraphQL schema compatibility.

Let's verify that the mutation is properly defined in the GraphQL schema and that all required types are available.

Also applies to: 61-64

✅ Verification successful

GraphQL schema and mutation are correctly defined and implemented

The verification confirms that:

  1. The NotificationType enum is properly defined in the schema with UNREAD and ARCHIVE values
  2. The deleteNotification mutation is correctly defined in the schema with required parameters id: String! and type: NotificationType!
  3. The mutation returns NotificationOverview type as specified in the code
  4. The implementation in gql.ts matches the schema definition
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify GraphQL schema compatibility for DeleteNotification mutation

# Test 1: Check if NotificationType enum is defined in schema
rg -l "enum NotificationType" --type graphql

# Test 2: Check if deleteNotification mutation is defined in schema
rg -l "deleteNotification.*NotificationType!" --type graphql

# Test 3: Check for any existing usages of the mutation
rg "DeleteNotification.*mutation" --type typescript --type vue

Length of output: 273


Script:

#!/bin/bash
# Let's try different approaches to find GraphQL schema and related files

# Find potential GraphQL schema files
fd -e graphql -e gql

# Find TypeScript files that might contain the schema
fd -e ts -e tsx | xargs rg "NotificationType"

# Look for DeleteNotification mutation usage
fd -e ts -e tsx -e vue | xargs rg "DeleteNotification"

# Check for any schema.graphql or similar files
fd "schema" -e graphql -e gql

Length of output: 16729


Script:

#!/bin/bash
# Let's check the notifications GraphQL schema and resolver implementation

# Check notifications schema definition
cat api/src/graphql/schema/types/notifications/notifications.graphql

# Look for deleteNotification mutation implementation in resolver
rg -A 10 "deleteNotification.*NotificationType" api/src/unraid-api/graph/resolvers/notifications/notifications.resolver.ts

Length of output: 2247

web/composables/gql/graphql.ts (4)

824-824: LGTM: Optional formatted timestamp field added to Notification type

The addition of formattedTimestamp as an optional string field to the Notification type is well-defined and follows GraphQL schema best practices.


1687-1693: LGTM: DeleteNotification mutation properly defined

The mutation is well-structured with:

  • Required parameters: id (String) and type (NotificationType)
  • Return type: NotificationOverview with archive count

1746-1746: LGTM: DeleteNotification document implementation is complete

The GraphQL document definition properly maps to the mutation type and includes the necessary selections for the response.


Line range hint 1687-1746: Verify the mutation's error handling

While the implementation looks correct, it's important to verify error handling for common scenarios:

  1. Deleting non-existent notifications
  2. Deleting already deleted notifications
  3. Permission-related errors

@pujitm
Copy link
Member Author

pujitm commented Oct 29, 2024

think we should add a confirmation dialog or something before actually deleting the notification?

@elibosley
Copy link
Member

think we should add a confirmation dialog or something before actually deleting the notification?

I think we're good because the user has already dropped into another view (Unread -> Archived). Plus most people's notifications are already in memory and non-permanent.

Copy link
Contributor

@mdatelle mdatelle left a comment

Choose a reason for hiding this comment

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

Looks good man just a couple of suggestions. Also let me know when you think the UI is ready for design review.

mdatelle
mdatelle previously approved these changes Nov 1, 2024
@pujitm pujitm force-pushed the feat/delete-notifications branch from e8f8df9 to 9f5a7f8 Compare November 4, 2024 14:25
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

🧹 Outside diff range and nitpick comments (1)
web/components/Notifications/Item.vue (1)

92-92: Add success feedback for delete action.

Consider adding a success toast or notification to provide feedback when the deletion is successful. This improves user experience by confirming their action was completed.

 const deleteNotification = reactive(
   useMutation(deleteMutation, {
     variables: { id: props.id, type: props.type },
+    onCompleted: () => {
+      // Assuming you have a toast/notification system
+      showToast({
+        message: 'Notification deleted successfully',
+        type: 'success'
+      });
+    }
   })
 );

Also applies to: 111-120

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ae14886 and 9f5a7f8.

📒 Files selected for processing (1)
  • web/components/Notifications/Item.vue (3 hunks)
🧰 Additional context used
📓 Learnings (1)
web/components/Notifications/Item.vue (1)
Learnt from: pujitm
PR: unraid/api#941
File: web/components/Notifications/Item.vue:0-0
Timestamp: 2024-11-01T17:52:55.311Z
Learning: In the `web/components/Notifications/Item.vue` component, ensure that when delete or archive mutations fail, the notification remains displayed, and an error message is shown below the action buttons to inform the user.
🔇 Additional comments (2)
web/components/Notifications/Item.vue (2)

8-8: LGTM: Import changes are well-organized.

The imports are properly structured and include all necessary components for the new delete functionality.

Also applies to: 13-17


42-55: LGTM: Error handling implementation is robust.

The error handling implementation aligns with the learnings and properly displays errors from both mutations. The reactive wrappers and computed error property provide a clean way to manage mutation states.

elibosley
elibosley previously approved these changes Nov 4, 2024
Copy link
Member

@elibosley elibosley left a comment

Choose a reason for hiding this comment

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

This looks good, we can probably just ignore coderabbit suggestion for deletion.

mdatelle
mdatelle previously approved these changes Nov 4, 2024
@pujitm pujitm dismissed stale reviews from mdatelle and elibosley via 65c4fd7 November 5, 2024 14:22
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

🧹 Outside diff range and nitpick comments (1)
web/helpers/apollo-cache/index.ts (1)

91-102: Add type safety and error handling.

Consider adding TypeScript types for the args parameter and error handling for missing IDs:

-          merge(_, incoming, { cache, args }) {
+          merge(
+            _: unknown,
+            incoming: unknown,
+            { cache, args }: { 
+              cache: ApolloCache<unknown>;
+              args?: { id?: string | null } 
+            }
+          ) {
+            if (!args?.id) {
+              console.warn('deleteNotification: No notification ID provided');
+              return incoming;
+            }
             const id = cache.identify({
               id: args.id,
               __typename: NotificationType,
             });
             cache.evict({ id });
             cache.gc();
             return incoming;
           },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9f5a7f8 and 65c4fd7.

📒 Files selected for processing (2)
  • web/composables/gql/typename.ts (1 hunks)
  • web/helpers/apollo-cache/index.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • web/composables/gql/typename.ts
🔇 Additional comments (3)
web/helpers/apollo-cache/index.ts (3)

3-3: LGTM!

The import is correctly added and used in the new cache configuration.


54-56: LGTM!

The formatting changes improve readability while maintaining the same functionality.


80-103: LGTM! Well-implemented cache management for notification deletion.

The implementation correctly:

  • Uses cache.identify() for proper cache key generation
  • Performs garbage collection to prevent dangling references
  • Includes clear documentation

@pujitm pujitm merged commit b585222 into main Nov 5, 2024
3 checks passed
@pujitm pujitm deleted the feat/delete-notifications branch November 5, 2024 14:27
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.

3 participants