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 delete functionality for community guidelines #7284

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

reactoholic
Copy link
Contributor

@reactoholic reactoholic commented Dec 6, 2024

Introduce functionality to delete community guidelines, updating relevant method names and loading states for clarity.

Summary by CodeRabbit

  • New Features

    • Enhanced community guidelines management with clearer terminology.
    • Added loading state for deleting community guidelines.
    • Updated UI to reflect new terminology for delete actions.
    • Conditional rendering of delete functionality based on community guidelines content.
    • Introduced the ability to delete community guidelines directly from the interface.
  • Bug Fixes

    • Improved clarity of function and variable names related to community guidelines deletion.
  • Documentation

    • Updated prop names and button labels for consistency and clarity.

@reactoholic reactoholic added client UX Enhanced user experience labels Dec 6, 2024
@reactoholic reactoholic self-assigned this Dec 6, 2024
Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The changes in this pull request primarily involve renaming several keys and variables related to community guidelines across multiple files. The key "removeContent" in the translation file has been changed to "deleteCommunityGuidelines", and similar renaming has occurred in various components, such as CommunityGuidelinesContainer, CommunityGuidelinesForm, AdminSpaceCommunityPage, and AdminSubspaceCommunityPage. These modifications aim to enhance clarity and consistency in terminology without altering the overall functionality or structure of the components.

Changes

File Path Change Summary
src/core/i18n/en/translation.en.json Renamed key: "removeContent""deleteCommunityGuidelines"
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx Removed property: removeCommunityGuidelinesContentLoading; Renamed method: onDeleteAndSaveContentonDeleteCommunityGuidelinesContent with updated signature.
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx Renamed prop: removeCommunityGuidelinesContentLoadingdeleteCommunityGuidelinesLoading; Renamed prop: onDeleteAndSaveContentonDeleteCommunityGuidelines with updated signature; Renamed prop: hasDeleteContentButtoncanDeleteCommunityGuidelines.
src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx Removed variable: removeCommunityGuidelinesContentLoading; Renamed function: onDeleteAndSaveContentonDeleteCommunityGuidelines.
src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx Added prop: onDeleteCommunityGuidelines to CommunityGuidelinesContainer; Updated rendering logic to check for community guidelines content with hasDeleteContentButton.

Possibly related PRs

Suggested labels

bug squash, enhancement

Suggested reviewers

  • bobbykolev

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7eb70c0 and 43c353e.

📒 Files selected for processing (3)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (5 hunks)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2 hunks)
  • src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx
  • src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx

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 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.

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.

@reactoholic reactoholic linked an issue Dec 6, 2024 that may be closed by this pull request
Copy link

@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 (2)
src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx (2)

138-141: Consider simplifying the references length check

The condition for checking references length can be simplified using Boolean coercion.

  const hasDeleteContentButton =
    Boolean(communityGuidelines?.displayName) ||
    Boolean(communityGuidelines?.description) ||
-   Number(communityGuidelines?.references.length) > 0;
+   Boolean(communityGuidelines?.references?.length);

157-165: LGTM! Consider adding type safety for the onDeleteCommunityGuidelines prop

The integration of delete functionality looks good. However, to improve type safety, consider explicitly typing the onDeleteCommunityGuidelines callback.

interface CommunityGuidelinesFormProps {
  // ... other props
  onDeleteCommunityGuidelines: () => Promise<void>;
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 24b3ad7 and 8edfdf2.

📒 Files selected for processing (5)
  • src/core/i18n/en/translation.en.json (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (4 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (4 hunks)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2 hunks)
  • src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/core/i18n/en/translation.en.json (1)

Pattern src/**/*.json: Review the JSON files for correct syntax and structure.
Ensure that the configuration and data are accurate and follow the project's standards.
Check for sensitive data exposure and ensure that the data is properly validated.

src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
🔇 Additional comments (7)
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (1)

22-22: LGTM! Props renamed for better clarity.

The prop renaming from removeCommunityGuidelinesContentLoading to deleteCommunityGuidelinesLoading and onDeleteAndSaveContent to onDeleteCommunityGuidelines improves code readability by making the intent clearer.

Also applies to: 24-24

src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (3)

32-32: LGTM! Interface updated with consistent naming.

The interface properties have been renamed to match the new naming convention, improving code clarity.

Also applies to: 35-35


67-67: LGTM! Mutation loading state renamed.

The destructured loading state from the mutation has been renamed to match the new naming convention.


Line range hint 102-116: LGTM! Method renamed with consistent implementation.

The method has been renamed from onDeleteAndSaveContent to onDeleteCommunityGuidelines while maintaining the same implementation logic.

src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (1)

161-161: LGTM! Props updated consistently.

The component correctly implements the renamed props from the CommunityGuidelinesContainer and passes them down to the CommunityGuidelinesForm component.

Also applies to: 164-164, 204-204, 207-207

src/core/i18n/en/translation.en.json (1)

589-589: LGTM! The new translation key follows the naming convention.

The new translation key "deleteCommunityGuidelines" is properly added and follows the existing naming pattern for deletion-related actions.

src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx (1)

136-136: Verify authorization checks for delete functionality

Ensure that proper authorization checks are in place for the delete operation to prevent unauthorized access.

Also applies to: 164-164

@bobbykolev bobbykolev requested review from ccanos and removed request for bobbykolev December 6, 2024 12:07
Copy link

@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)
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (1)

63-65: Consider adding error handling for delete operation.

While the implementation is clean, consider adding error handling to provide feedback to the user when the delete operation fails.

 const [handleDeleteCommunityGuidelines, deleteCommunityGuidelinesLoading] = useLoadingState(async () => {
-    await onDeleteCommunityGuidelines?.();
+    try {
+      await onDeleteCommunityGuidelines?.();
+    } catch (error) {
+      // Handle error appropriately (e.g., show error notification)
+      console.error('Failed to delete community guidelines:', error);
+      throw error; // Re-throw to maintain the promise rejection
+    }
 });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8edfdf2 and 7eb70c0.

📒 Files selected for processing (5)
  • src/core/i18n/en/translation.en.json (2 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (4 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (5 hunks)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2 hunks)
  • src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx
  • src/domain/journey/subspace/pages/AdminSubspaceCommunityPage.tsx
🧰 Additional context used
📓 Path-based instructions (2)
src/core/i18n/en/translation.en.json (1)

Pattern src/**/*.json: Review the JSON files for correct syntax and structure.
Ensure that the configuration and data are accurate and follow the project's standards.
Check for sensitive data exposure and ensure that the data is properly validated.

src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (1)

Pattern src/**/*.{ts,tsx,js}: Review the React.js/TypeScript/JavaScript code for best practices and potential bugs.
Ensure that the code adheres to TypeScript's typing system and modern standards.
Use the following code guide documentation in the codebase: 'docs/code-guidelines.md'.
Ensure sufficient error handling and logging is present, but note:

  • We have a global error handler in place. So local try/catch blocks are not required unless they provide value beyond what the global error handler already covers.
  • Avoid flagging the absence of local error handling in cases where the global error handler suffices.
  • Avoid flagging the absence of logging in cases where the global logger is already in place (graphql usage).

Inform about the recommendation of not using non-null assertion,
except on GraphQL queries where the variable is asserted non-null and followed by a
skip: with the same variable.
Examples:

  • Not Required: there's a skip
    {
    variables: { templateId: templateId! },
    skip: !templateId,
    }

Check for common security vulnerabilities such as:

  • SQL Injection
  • XSS (Cross-Site Scripting)
  • CSRF (Cross-Site Request Forgery)
  • Insecure dependencies
  • Sensitive data exposure
🔇 Additional comments (6)
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (4)

15-15: LGTM! Type definitions and imports are well structured.

The changes improve type safety by properly typing the delete operation as a Promise, and the naming is more descriptive and aligned with the actual functionality.

Also applies to: 23-24


50-51: LGTM! Props destructuring is well implemented.

Good use of default value for canDeleteCommunityGuidelines as a defensive programming practice.


90-97: Verify the translation key path.

The translation key community.communityGuidelines.deleteCommunityGuidelines needs verification.

#!/bin/bash
# Description: Verify the translation key exists in the translation files
rg "community\.communityGuidelines\.deleteCommunityGuidelines" src/

120-127: LGTM! Confirmation dialog implementation is solid.

The async handling and loading state management are well implemented.

src/core/i18n/en/translation.en.json (2)

588-588: Formatting change looks good.


633-634: New translation key looks good but let's verify the migration.

The new key "deleteCommunityGuidelines" is more descriptive than the old "removeContent" key. However, let's verify that all occurrences of the old key have been properly updated.

✅ Verification successful

Migration to new translation key is complete and consistent

The verification shows that:

  • The old key "removeContent" is not present anywhere in the codebase
  • The new key "deleteCommunityGuidelines" is properly used across the codebase:
    • Defined in translation.en.json
    • Used consistently in component props and handlers in both Space and Subspace admin pages
    • Properly implemented in CommunityGuidelines components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usages of the old translation key

# Search for any remaining instances of the old key
echo "Checking for remaining instances of 'removeContent' key..."
rg -i "removeContent" --type json

# Search for usages of the new key to ensure it's being used
echo "Checking for usage of new 'deleteCommunityGuidelines' key..."
rg -i "deleteCommunityGuidelines" --type ts --type tsx

Length of output: 386


Script:

#!/bin/bash
# Let's try a different approach to search for both old and new keys

# Search for removeContent in all files
echo "Searching for 'removeContent' in all files..."
rg -i "removeContent"

# Search for deleteCommunityGuidelines in all files
echo "Searching for 'deleteCommunityGuidelines' in all files..."
rg -i "deleteCommunityGuidelines"

# Also check the translation file directly
echo "Content of the translation file around the new key..."
rg -C 5 "deleteCommunityGuidelines" src/core/i18n/en/translation.en.json

Length of output: 3893

src/core/i18n/en/translation.en.json Outdated Show resolved Hide resolved
@bobbykolev bobbykolev merged commit f04b698 into develop Dec 6, 2024
3 checks passed
@bobbykolev bobbykolev deleted the client-web/7011_del_community_guidelines_func branch December 6, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client UX Enhanced user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: allow admins to save community guidelines without content
3 participants