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

remove community guidelines content functionality #7271

Conversation

reactoholic
Copy link
Contributor

@reactoholic reactoholic commented Dec 3, 2024

remove community guidelines content functionality
goes together with the server changes

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a delete button for community guidelines content in the form.
    • Added functionality to remove community guidelines content with user notifications.
    • Enhanced user feedback with new success messages for content removal.
    • Improved visibility of community guidelines content with a "See More" button.
    • Added confirmation dialog for deleting community guidelines content.
  • Bug Fixes

    • Improved input handling for line breaks in the Markdown input field.
  • Documentation

    • Updated user interface text for clarity and improved user experience in community guidelines management.

@reactoholic reactoholic self-assigned this Dec 3, 2024
Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

The pull request introduces multiple modifications across various components and files related to community guidelines management within the Alkemio platform. Key changes include the addition of new user interface text in the translation.en.json file, the implementation of a mutation for removing community guidelines content in the GraphQL schema, and updates to components for enhanced functionality, such as conditional rendering of delete buttons and improved input handling. The overall structure of the files remains intact, focusing on enhancing user feedback and interaction.

Changes

File Change Summary
src/core/i18n/en/translation.en.json Added new keys for removing community guidelines content and success messages. Updated existing sections for clarity and user experience.
src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx Updated handleChange function to trim input and handle <br> as an empty string. No changes to props or component interface.
src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql Added RemoveCommunityGuidelinesContent mutation for managing community guidelines content. Existing mutations remain unchanged.
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx Introduced new variables for community guidelines data extraction and updated rendering logic to improve visibility of the guidelines section.
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx Added useRemoveCommunityGuidelinesContentMutation hook and onDeleteAndSaveContent method for handling content deletion. Updated interface to include new method.
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx Added optional hasDeleteContentButton prop and onDeleteAndSaveContent callback for conditional rendering of the delete button. Updated layout for button spacing.
src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx Updated CommunityGuidelinesContainer and CommunityGuidelinesForm to include new props for enhanced functionality. Modified state management for template dialogs.

Possibly related PRs

Suggested labels

client

Suggested reviewers

  • bobbykolev

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 marked this pull request as ready for review December 3, 2024 10:09
@reactoholic
Copy link
Contributor Author

@coderabbitai full review

Copy link

coderabbitai bot commented Dec 3, 2024

✅ Actions performed

Full review triggered.

@reactoholic reactoholic linked an issue Dec 3, 2024 that may be closed by this pull request
@reactoholic reactoholic added enhancement UX Enhanced user experience labels Dec 3, 2024
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: 2

🧹 Outside diff range and nitpick comments (5)
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (1)

80-89: Consider adding a confirmation dialog for delete action.

Since deleting content is a destructive action, it would be beneficial to add a confirmation dialog to prevent accidental deletions.

Example implementation:

+ const [showConfirmDialog, setShowConfirmDialog] = useState(false);
+ 
+ const handleDelete = () => {
+   setShowConfirmDialog(true);
+ };
+ 
+ const handleConfirmDelete = () => {
+   onDeleteAndSaveContent?.();
+   setShowConfirmDialog(false);
+ };

  {hasDeleteContentButton && (
+   <>
    <LoadingButton
      loading={loading}
      variant="outlined"
      disabled={!isValid}
-     onClick={onDeleteAndSaveContent}
+     onClick={handleDelete}
    >
      {t('common.removeContent')}
    </LoadingButton>
+   <Dialog open={showConfirmDialog} onClose={() => setShowConfirmDialog(false)}>
+     <DialogTitle>{t('common.confirmDelete')}</DialogTitle>
+     <DialogContent>
+       <DialogContentText>
+         {t('common.confirmDeleteMessage')}
+       </DialogContentText>
+     </DialogContent>
+     <DialogActions>
+       <Button onClick={() => setShowConfirmDialog(false)}>{t('common.cancel')}</Button>
+       <Button onClick={handleConfirmDelete} color="error" autoFocus>
+         {t('common.delete')}
+       </Button>
+     </DialogActions>
+   </Dialog>
+   </>
  )}
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx (2)

44-45: Fix typo in variable names.

The variables comunityReferences and comunityDescription have a typo (missing 'm' in 'community').

- const comunityReferences = data?.lookup.community?.guidelines.profile.references;
- const comunityDescription = data?.lookup.community?.guidelines.profile.description;
+ const communityReferences = data?.lookup.community?.guidelines.profile.references;
+ const communityDescription = data?.lookup.community?.guidelines.profile.description;

49-50: Simplify length checks.

The Number() conversion is unnecessary since array length and string length are already numbers.

- const isReadMoreVisible = Number(comunityDescription?.length) > 0 || Number(comunityReferences?.length) > 0;
+ const isReadMoreVisible = (communityDescription?.length ?? 0) > 0 || (communityReferences?.length ?? 0) > 0;
src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2)

Line range hint 105-112: Improve error handling in handleSaveAsTemplate

The function silently fails if templatesSetId is undefined. Consider adding explicit error handling and user feedback.

Apply this improvement:

   const handleSaveAsTemplate = async (values: CommunityGuidelinesTemplateFormSubmittedValues) => {
     const { data: templatesSetData } = await fetchSpaceTemplatesSetId({ variables: { spaceNameId: spaceId } });
     const templatesSetId = templatesSetData?.space.templatesManager?.templatesSet?.id;
+    if (!templatesSetId) {
+      notify(t('errors.templateSetNotFound'), 'error');
+      return;
+    }
-    if (templatesSetId) {
     await createTemplate({
       variables: toCreateTemplateMutationVariables(templatesSetId, TemplateType.CommunityGuidelines, values),
     });
     setSaveAsTemplateDialogOpen(false);
-    }
   };

165-168: Simplify hasDeleteContentButton calculation

The boolean calculation can be simplified using the OR operator.

Apply this improvement:

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

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 36e7697 and 8f976ae.

⛔ Files ignored due to path filters (3)
  • src/core/apollo/generated/apollo-helpers.ts is excluded by !**/generated/**
  • src/core/apollo/generated/apollo-hooks.ts is excluded by !**/generated/**
  • src/core/apollo/generated/graphql-schema.ts is excluded by !**/generated/**
📒 Files selected for processing (7)
  • src/core/i18n/en/translation.en.json (2 hunks)
  • src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx (3 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (5 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (3 hunks)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1)

Pattern src/**/*.{graphql,gql}: Review the GraphQL schema and queries for best practices, potential bugs, and adherence to the project's GraphQL standards.
Ensure that the schema is well-defined and queries are optimized.
Check for security vulnerabilities.

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:

  • 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/CommunityGuidelinesBlock.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:

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

  • 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/ui/forms/MarkdownInput/FormikMarkdownField.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:

  • 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/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:

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

🔇 Additional comments (6)
src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1)

37-41: LGTM! The mutation is well-structured.

The new RemoveCommunityGuidelinesContent mutation follows GraphQL best practices:

  • Uses consistent naming convention
  • Properly marks input type as required
  • Reuses existing CommunityGuidelinesDetails fragment
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (2)

20-21: LGTM! Props are well-typed.

The new optional props hasDeleteContentButton and onDeleteAndSaveContent are properly typed and follow TypeScript best practices.


79-79: LGTM! Layout spacing is well-implemented.

The button container uses proper MUI spacing with gap property and correct alignment.

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

Line range hint 38-41: LGTM! Type safety is well-handled.

The GraphQL query properly uses optional chaining and the non-null assertion is safe due to the skip condition.

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

587-588: LGTM: Clear and descriptive text for the remove content action

The new translation key "removeContent" is well-placed in the common section and provides clear text for the action.


626-626: LGTM: Well-structured success message

The success message follows good UX practices by clearly confirming that the community guidelines content was removed and saved.

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

79-89: Consider adding confirmation dialog before deletion

The delete button implementation looks good, but given that content deletion is a destructive action, consider adding a confirmation dialog to prevent accidental deletions.

+ const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
+ 
  <Box display="flex" marginY={4} gap={1} justifyContent="flex-end">
    {hasDeleteContentButton && (
      <>
        <LoadingButton
          loading={loading}
          variant="outlined"
          disabled={!isValid}
-         onClick={onDeleteAndSaveContent}
+         onClick={() => setIsDeleteDialogOpen(true)}
        >
          {t('common.removeContent')}
        </LoadingButton>
+       <ConfirmDialog
+         open={isDeleteDialogOpen}
+         onClose={() => setIsDeleteDialogOpen(false)}
+         onConfirm={() => {
+           onDeleteAndSaveContent?.();
+           setIsDeleteDialogOpen(false);
+         }}
+         title={t('common.confirmDelete')}
+         description={t('common.deleteWarning')}
+       />
+     </>
    )}
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx (1)

49-50: Simplify length checks

The Number() conversion is unnecessary when checking array/string lengths.

- const hasGuidelines = Boolean(data?.lookup.community?.guidelines.profile.description);
- const isReadMoreVisible = Number(comunityDescription?.length) > 0 || Number(comunityReferences?.length) > 0;
+ const hasGuidelines = Boolean(data?.lookup.community?.guidelines.profile.description);
+ const isReadMoreVisible = Boolean(comunityDescription?.length || comunityReferences?.length);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 36e7697 and 8f976ae.

⛔ Files ignored due to path filters (3)
  • src/core/apollo/generated/apollo-helpers.ts is excluded by !**/generated/**
  • src/core/apollo/generated/apollo-hooks.ts is excluded by !**/generated/**
  • src/core/apollo/generated/graphql-schema.ts is excluded by !**/generated/**
📒 Files selected for processing (7)
  • src/core/i18n/en/translation.en.json (2 hunks)
  • src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx (3 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (5 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (3 hunks)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1)

Pattern src/**/*.{graphql,gql}: Review the GraphQL schema and queries for best practices, potential bugs, and adherence to the project's GraphQL standards.
Ensure that the schema is well-defined and queries are optimized.
Check for security vulnerabilities.

src/core/ui/forms/MarkdownInput/FormikMarkdownField.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:

  • 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/CommunityGuidelinesBlock.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:

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

  • 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/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:

  • 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/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:

  • 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 (9)
src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1)

37-41: Verify error handling for the new mutation

The mutation follows GraphQL conventions and maintains consistency by returning the same fragment. However, ensure proper error handling is implemented on the server side for cases such as:

  • Non-existent guidelines
  • Permission issues
  • Partial content removal failures
✅ Verification successful

Error handling appears to be implemented through Apollo's mutation handling

The implementation shows proper error handling through Apollo Client's mutation API:

  • Uses onCompleted callback for success scenarios with user notification
  • Implements awaitRefetchQueries to ensure data consistency
  • Follows Apollo's error handling patterns which automatically handle network errors and GraphQL errors
  • Validates input by checking communityGuidelinesId existence

The mutation follows best practices for error handling in a GraphQL/Apollo environment, where GraphQL errors are automatically propagated to the client.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for error handling in the resolver implementation
ast-grep --pattern 'class $_ implements $_ {
  $$$
  removeCommunityGuidelinesContent($_, $_) {
    $$$
  }
  $$$
}'

Length of output: 118


Script:

#!/bin/bash
# Let's try different approaches to find the resolver implementation

# Search for files containing "removeCommunityGuidelinesContent"
rg -l "removeCommunityGuidelinesContent"

# Search for resolver files related to community guidelines
fd "resolver|Resolver" | grep -i "communit.*guideline"

# Search for TypeScript/JavaScript files containing community guidelines
fd -e ts -e js | grep -i "communit.*guideline"

Length of output: 439


Script:

#!/bin/bash
# Let's examine the container component to understand the error handling implementation
rg -A 10 "removeCommunityGuidelinesContent" src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx

# Also check the generated types for any error types
rg "RemoveCommunityGuidelinesContent.*Error" src/core/apollo/generated/graphql-schema.ts

Length of output: 1069

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

20-21: LGTM! Props are well-typed and named clearly.

The new optional props hasDeleteContentButton and onDeleteAndSaveContent are appropriately typed and follow the component's naming conventions.

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

44-45: LGTM! Clear variable extraction

The variables are well-named and follow the pattern of safe property access from the GraphQL data.

src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx (1)

94-96: ⚠️ Potential issue

Fix inconsistent string handling logic

The current implementation has inconsistent string handling that could lead to bugs:

  1. Value is trimmed for comparison but untrimmed value is used for setting
  2. The '<br>' check will never match due to trimming before comparison

Apply this fix to ensure consistent behavior:

-      const trimmedValue = event.target.value.trim();
-      const newValue = trimmedValue === '<br>' ? '' : event.target.value;
-      helper.setValue(newValue);
+      const value = event.target.value;
+      const newValue = value === '<br>' ? '' : value;
+      helper.setValue(newValue.trim());

Likely invalid or redundant comment.

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

6-6: LGTM!

The new mutation import and interface extension are properly implemented.

Also applies to: 34-34


100-115: ⚠️ Potential issue

Fix incorrect ID usage in refetchQuery

The refetchQuery is using communityGuidelinesId instead of communityId. This will cause the query to fail as the schema expects a community ID.

Apply this fix:

       awaitRefetchQueries: true,
-      refetchQueries: [refetchCommunityGuidelinesQuery({ communityId: communityGuidelinesId })],
+      refetchQueries: [refetchCommunityGuidelinesQuery({ communityId })],

Likely invalid or redundant comment.

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

165-169: LGTM!

The hasDeleteContentButton logic and prop passing are implemented correctly. The visibility condition is well-defined and covers all relevant cases.

Also applies to: 204-205

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

587-588: LGTM: New translation key for removing content

The new translation key "removeContent" is well-structured and follows the established patterns for action messages in the application.


626-626: LGTM: New success message translation

The success message for saving and deleting content is clear, consistent with other success messages, and properly placed in the community guidelines section.

@reactoholic reactoholic force-pushed the client-web/7011_bugfix_allow-admins-to-save-community-guidelines-without-content branch from 8f976ae to 7bdb639 Compare December 3, 2024 10:19
Copy link
Contributor

@ccanos ccanos left a comment

Choose a reason for hiding this comment

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

Tested it, and it works,
I would change the button text to something shorter and I think a confirmation dialog is required. We have a ConfirmationDialog in core/ui

@reactoholic
Copy link
Contributor Author

Tested it, and it works, I would change the button text to something shorter and I think a confirmation dialog is required. We have a ConfirmationDialog in core/ui

Absolutely agree, on it!

@bobbykolev bobbykolev removed their request for review December 3, 2024 14:22
@reactoholic reactoholic force-pushed the client-web/7011_bugfix_allow-admins-to-save-community-guidelines-without-content branch 3 times, most recently from 3ed7767 to 647e5b8 Compare December 3, 2024 14:36
@reactoholic reactoholic requested a review from ccanos December 3, 2024 14:37
@reactoholic reactoholic force-pushed the client-web/7011_bugfix_allow-admins-to-save-community-guidelines-without-content branch from 9f8c1e5 to 03ff5fc Compare December 3, 2024 14:41
Signed-off-by: reactoholic <petar.georgiev.kolev@gmail.com>
@reactoholic reactoholic force-pushed the client-web/7011_bugfix_allow-admins-to-save-community-guidelines-without-content branch from 03ff5fc to 7231b44 Compare December 3, 2024 14:44
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 (2)
src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (1)

166-169: Simplify content presence check

The current implementation can be simplified using array length and optional chaining.

Consider this more concise version:

-const hasDeleteContentButton =
-  Boolean(communityGuidelines?.displayName) ||
-  Boolean(communityGuidelines?.description) ||
-  Number(communityGuidelines?.references.length) > 0;
+const hasDeleteContentButton = Boolean(
+  communityGuidelines?.displayName ||
+  communityGuidelines?.description ||
+  communityGuidelines?.references?.length
+);
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (1)

86-96: Consider improving the delete button's UX.

The delete button's placement and styling could be improved:

  1. The delete button should be visually distinct from the update button to prevent accidental clicks
  2. Consider adding a warning color to emphasize the destructive action
 {hasDeleteContentButton && (
   <LoadingButton
     loading={loading}
     variant="outlined"
+    color="error"
     disabled={!isValid}
     onClick={() => setDeleteDialogOpen(true)}
   >
     {t('common.removeContent')}
   </LoadingButton>
 )}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8f976ae and dbc3593.

⛔ Files ignored due to path filters (3)
  • src/core/apollo/generated/apollo-helpers.ts is excluded by !**/generated/**
  • src/core/apollo/generated/apollo-hooks.ts is excluded by !**/generated/**
  • src/core/apollo/generated/graphql-schema.ts is excluded by !**/generated/**
📒 Files selected for processing (7)
  • src/core/i18n/en/translation.en.json (3 hunks)
  • src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql (1 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx (3 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (5 hunks)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (4 hunks)
  • src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelines.graphql
  • src/core/ui/forms/MarkdownInput/FormikMarkdownField.tsx
  • src/domain/community/community/CommunityGuidelines/CommunityGuidelinesBlock.tsx
🧰 Additional context used
📓 Path-based instructions (4)
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:

  • 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/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:

  • 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/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:

  • 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 (13)
src/domain/journey/space/pages/AdminSpaceCommunityPage.tsx (3)

102-104: LGTM: Appropriate use of GraphQL hooks

The lazy query is well-suited for this use case as it loads template data only when needed.


Line range hint 105-113: Add error handling for template creation

The implementation still silently fails if templatesSetId is not available. Consider adding error handling and user feedback.


211-221: LGTM: Well-structured template dialog implementation

The implementation follows React best practices:

  • Proper state management for dialog visibility
  • Clear separation of concerns
  • Consistent prop passing
  • Appropriate use of translation keys
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesForm.tsx (3)

14-14: LGTM: Props interface changes are well-structured.

The new props for delete functionality are properly typed and follow TypeScript best practices:

  • removeCommunityGuidelinesContentLoading: boolean for loading state
  • hasDeleteContentButton: boolean for conditional rendering
  • onDeleteAndSaveContent: optional callback function

Also applies to: 22-24


44-54: LGTM: Component signature updated correctly.

The component signature properly destructures the new props with a sensible default value for hasDeleteContentButton.


107-126: LGTM: Confirmation dialog implementation is robust.

The confirmation dialog implementation:

  • Uses proper translation keys for internationalization
  • Handles loading state correctly
  • Provides clear cancel/confirm actions
src/domain/community/community/CommunityGuidelines/CommunityGuidelinesContainer.tsx (4)

6-6: LGTM: Import statement is correctly added.

The new mutation hook is properly imported.


32-32: LGTM: Interface updates are properly typed.

The interface changes correctly add:

  • Loading state for remove operation
  • Optional callback for delete operation

Also applies to: 35-35


67-68: LGTM: Mutation hook is properly initialized.

The mutation hook setup includes loading state destructuring.


102-117: 🛠️ Refactor suggestion

Verify error handling in the delete operation.

While the implementation is generally good, consider adding error handling for the mutation:

 const onDeleteAndSaveContent = async () => {
   if (!communityGuidelinesId) {
     return;
   }

   await removeCommunityGuidelinesContent({
     variables: {
       communityGuidelinesData: {
         communityGuidelinesID: communityGuidelinesId,
       },
     },
     onCompleted: () => notify(t('community.communityGuidelines.saveAndDeleteContentSuccessMessage'), 'success'),
+    onError: (error) => notify(error.message, 'error'),
     awaitRefetchQueries: true,
     refetchQueries: [refetchCommunityGuidelinesQuery({ communityId })],
   });
 };

Likely invalid or redundant comment.

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

587-588: LGTM: Common translation key is properly added.

The removeContent translation key is appropriately placed in the common section.


626-626: LGTM: Success message translation is well-defined.

The success message translation key is properly added to the community guidelines section.


696-699: LGTM: Confirmation dialog translations are complete.

The confirmation dialog translations include both title and content with appropriate warning about irreversible action.

@ccanos ccanos merged commit 5edb27e into develop Dec 3, 2024
3 checks passed
@ccanos ccanos deleted the client-web/7011_bugfix_allow-admins-to-save-community-guidelines-without-content branch December 3, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug squash enhancement 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
2 participants