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

Fix socials in adminjs #1881

Merged
merged 2 commits into from
Dec 2, 2024
Merged

Fix socials in adminjs #1881

merged 2 commits into from
Dec 2, 2024

Conversation

CarlosQ96
Copy link
Collaborator

@CarlosQ96 CarlosQ96 commented Nov 28, 2024

Related to: https://github.com/orgs/Giveth/projects/9/views/1?sliceBy%5Bvalue%5D=CarlosQ96&pane=issue&itemId=80410999&issue=Giveth%7Cgiveth-dapps-v2%7C4759

Summary by CodeRabbit

  • New Features

    • Introduced a new ProjectSocialMedia tab in the AdminJS interface for managing social media resources.
    • Added a socialMedia property to project management, enhancing how social media information is displayed.
  • Bug Fixes

    • Removed outdated socials property to streamline project data management.
  • Documentation

    • Updated visibility settings and configurations for new and existing properties in the AdminJS interface.

@CarlosQ96 CarlosQ96 force-pushed the hotfix_adminjs_editing_projects branch from d487090 to 5728a2a Compare December 2, 2024 13:31
@CarlosQ96 CarlosQ96 marked this pull request as ready for review December 2, 2024 13:33
Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request introduce a new resource tab, projectSocialMediaTab, to the AdminJS interface, enhancing the management of social media information related to projects. This involves adding an import statement for the new tab in adminJs.ts, which aggregates it into the resources array. Additionally, a new file, projectSocialMediaTab.ts, defines the configurations and permissions for managing social media actions. The projectsTab.ts file is updated to replace the socials property with a new socialMedia property, which references the ProjectSocialMedia entity, reflecting a reorganization in how social media data is handled.

Changes

File Path Change Summary
src/server/adminJs/adminJs.ts - Added import for projectSocialMediaTab.
- Included projectSocialMediaTab in the resources array in getResources.
src/server/adminJs/tabs/projectSocialMediaTab.ts - Created new file defining projectSocialMediaTab with configurations for managing project social media resources.
src/server/adminJs/tabs/projectsTab.ts - Removed socials property.
- Added socialMedia property as a reference to ProjectSocialMedia.
- Updated fillSocialProfileAndQfRounds function to remove fetching of social profiles by project ID.

Possibly related PRs

  • Zkevm integration #1635: The changes in this PR involve the integration of the projectSocialMediaTab into the AdminJS interface, which is relevant as it relates to managing project-related resources, similar to the modifications made in the projectsTab.ts file regarding social media properties.
  • Master #1638: This PR includes updates to the donationTab and qfRoundTab, which also involve project management and resource handling in the AdminJS interface, aligning with the changes made in the main PR regarding the addition of the projectSocialMediaTab.

🐰 In the garden of code, I hop with glee,
New tabs for social media, oh what a spree!
Projects now shine with a media glow,
In AdminJS, watch the connections grow!
With every change, our features expand,
Hopping along, isn’t it grand? 🌼✨


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.

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

🧹 Outside diff range and nitpick comments (1)
src/server/adminJs/tabs/projectSocialMediaTab.ts (1)

7-64: Configure pagination and sorting for better performance.

The resource configuration lacks pagination and sorting settings, which could impact performance with large datasets.

Add these configurations to the options object:

 options: {
+  sort: {
+    sortBy: 'createdAt',
+    direction: 'desc',
+  },
+  listProperties: ['type', 'link', 'project'],
+  perPage: 20,
   // ... rest of the options
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4c4ae45 and 5728a2a.

📒 Files selected for processing (3)
  • src/server/adminJs/adminJs.ts (2 hunks)
  • src/server/adminJs/tabs/projectSocialMediaTab.ts (1 hunks)
  • src/server/adminJs/tabs/projectsTab.ts (1 hunks)
🔇 Additional comments (2)
src/server/adminJs/adminJs.ts (1)

34-34: LGTM! Clean integration of the new social media tab.

The import and resource array addition are properly implemented.

Also applies to: 155-155

src/server/adminJs/tabs/projectsTab.ts (1)

801-811: Verify the relationship with ProjectSocialMedia entity.

The configuration looks correct, but let's verify the relationship is properly defined in the Project entity.

✅ Verification successful

The relationship between Project and ProjectSocialMedia entities is properly defined

The verification results show that:

  • In src/entities/project.ts, there's a proper @OneToMany relationship defined from Project to ProjectSocialMedia
  • In src/entities/projectSocialMedia.ts, there's a corresponding @ManyToOne relationship defined from ProjectSocialMedia to Project
  • The AdminJS configuration in projectsTab.ts correctly references the 'ProjectSocialMedia' entity

The relationship is bi-directional and properly configured in both entities, matching the AdminJS configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the relationship is properly defined in the Project entity
# and if ProjectSocialMedia entity exists with correct fields

# Check Project entity for socialMedia relationship
ast-grep --pattern 'class Project {
  $$$
  @OneToMany(() => ProjectSocialMedia, $_ => $_)
  socialMedia: ProjectSocialMedia[];
  $$$
}'

# Check ProjectSocialMedia entity definition
ast-grep --pattern 'class ProjectSocialMedia {
  $$$
  @ManyToOne(() => Project, $_ => $_)
  project: Project;
  $$$
}'

Length of output: 260


Script:

#!/bin/bash
# Let's try a different approach to find these entities and their relationships

# Find files containing Project and ProjectSocialMedia
fd -e ts -e js | xargs rg "ProjectSocialMedia|@Entity.*Project"

# Look for any file containing OneToMany and ManyToOne relationships between these entities
rg -A 3 -B 3 "@(OneToMany|ManyToOne).*(Project|ProjectSocialMedia)"

Length of output: 15901

Comment on lines +47 to +52
type: {
isVisible: true,
},
link: {
isVisible: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance type field with predefined social media platforms.

The type field could benefit from a predefined list of social media platforms to ensure consistency.

Consider adding available values:

 type: {
   isVisible: true,
+  availableValues: [
+    { value: 'twitter', label: 'Twitter' },
+    { value: 'facebook', label: 'Facebook' },
+    { value: 'instagram', label: 'Instagram' },
+    { value: 'linkedin', label: 'LinkedIn' },
+    { value: 'github', label: 'GitHub' },
+  ],
 },
📝 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
type: {
isVisible: true,
},
link: {
isVisible: true,
},
type: {
isVisible: true,
availableValues: [
{ value: 'twitter', label: 'Twitter' },
{ value: 'facebook', label: 'Facebook' },
{ value: 'instagram', label: 'Instagram' },
{ value: 'linkedin', label: 'LinkedIn' },
{ value: 'github', label: 'GitHub' },
],
},
link: {
isVisible: true,
},

Comment on lines +11 to +36
list: {
isVisible: true,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.LIST),
},
show: {
isVisible: true,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.SHOW),
},
delete: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.DELETE),
},
new: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.NEW),
},
edit: {
isVisible: false,
isAccessible: ({ currentAdmin }) =>
canAccessMainCategoryAction({ currentAdmin }, ResourceActions.EDIT),
},
},
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

Add input validation for social media links.

The actions configuration lacks input validation for social media links, which could lead to security issues or invalid data being stored.

Consider adding validation in the edit action:

 edit: {
   isVisible: false,
   isAccessible: ({ currentAdmin }) =>
     canAccessMainCategoryAction({ currentAdmin }, ResourceActions.EDIT),
+  before: async (request) => {
+    const { link } = request.payload;
+    if (link && !isValidUrl(link)) {
+      throw new Error('Invalid social media URL format');
+    }
+    return request;
+  },
 },

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Collaborator

@kkatusic kkatusic left a comment

Choose a reason for hiding this comment

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

LGTM ;) , thx @CarlosQ96

@CarlosQ96 CarlosQ96 force-pushed the hotfix_adminjs_editing_projects branch from 5728a2a to ae6c910 Compare December 2, 2024 14:47
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)
src/server/adminJs/tabs/projectsTab.ts (1)

801-811: LGTM: Improved social media data structure

The change from socials to socialMedia property with a proper entity reference improves the data structure and management of social media information. The configuration looks correct with appropriate visibility settings.

This change suggests better data modeling by:

  1. Using a dedicated entity for social media data
  2. Supporting multiple social media entries through isArray: true
  3. Maintaining proper data relationships through entity references
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5728a2a and ae6c910.

📒 Files selected for processing (4)
  • src/server/adminJs/adminJs.ts (2 hunks)
  • src/server/adminJs/tabs/projectSocialMediaTab.ts (1 hunks)
  • src/server/adminJs/tabs/projectsTab.ts (1 hunks)
  • src/services/chains/index.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/server/adminJs/adminJs.ts
  • src/server/adminJs/tabs/projectSocialMediaTab.ts
🔇 Additional comments (1)
src/services/chains/index.test.ts (1)

1001-1018: ⚠️ Potential issue

Verify if RAY token test should remain commented out

The test case for RAY token transfer on Solana mainnet has been commented out. This could reduce test coverage for Solana mainnet transactions.

Consider either:

  1. Re-enabling the test if RAY token transfers still need to be supported
  2. Adding a comment explaining why the test was disabled
  3. Adding alternative test cases to maintain coverage for Solana mainnet token transfers

@CarlosQ96 CarlosQ96 merged commit b77f184 into staging Dec 2, 2024
5 checks passed
@CarlosQ96 CarlosQ96 deleted the hotfix_adminjs_editing_projects branch December 2, 2024 22:30
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.

2 participants