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 additional fields to campaign model #946

Merged
merged 3 commits into from
Nov 22, 2024

Conversation

andrashee
Copy link
Contributor

@andrashee andrashee commented Nov 22, 2024

Summary by CodeRabbit

  • New Features
    • Introduced five new properties for campaigns:
      • link_website, link_instagram, link_tiktok, link_facebook, and link_x for social media and website links.
      • Public: Indicates if the campaign is listed on the campaign overview.
      • Featured: Indicates if the campaign is highlighted on the campaign overview.
      • Slug: For creating user-friendly URLs.
      • New structured Link type for better link representation.

These enhancements allow for improved visibility and promotion of campaigns within the application.

Copy link

vercel bot commented Nov 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
public ⬜️ Ignored (Inspect) Visit Preview Nov 22, 2024 10:08am

This comment was marked as resolved.

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)
shared/src/types/campaign.ts (1)

21-22: Add JSDoc comments to document the new properties.

While the property names are somewhat self-explanatory, adding documentation would help other developers understand their exact purpose and impact.

Consider adding JSDoc comments:

+/** Indicates if the campaign is visible to the public. Defaults to false in the collection. */
 public?: boolean;
+/** Indicates if the campaign should be highlighted/featured on the campaign overview. Defaults to false in the collection. */
 featured?: boolean;
admin/src/collections/Campaigns.ts (1)

107-118: Consider adding validation for featured campaigns

The implementation of the public and featured flags looks good, with appropriate defaults for security. However, consider adding validation to ensure that featured campaigns must also be public, as it wouldn't make sense to feature a private campaign.

 featured: {
   dataType: 'boolean',
   name: 'Featured',
   description: 'Featured on campaign overview',
   defaultValue: false,
+  validation: {
+    beforeSave: (value: boolean, values: Campaign) => {
+      if (value && !values.public) {
+        throw Error('Featured campaigns must be public');
+      }
+      return value;
+    }
+  },
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 64141ca and 09d4afb.

📒 Files selected for processing (2)
  • admin/src/collections/Campaigns.ts (1 hunks)
  • shared/src/types/campaign.ts (1 hunks)
🔇 Additional comments (2)
shared/src/types/campaign.ts (1)

21-22: Verify the impact of these new flags.

The addition of these optional flags looks good. Let's verify their usage across the codebase to ensure proper handling of undefined values.

admin/src/collections/Campaigns.ts (1)

107-118: Verify type definitions alignment

Let's verify that these new properties are properly reflected in the Campaign type definition.

✅ Verification successful

Type definitions are properly aligned

The Campaign type definition in shared/src/types/campaign.ts already includes both public and featured properties as optional boolean fields, which perfectly aligns with the collection schema definition.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Campaign type includes the new properties
# Expected: Find type definition with public and featured properties

rg -A 10 "type Campaign = {" shared/src/types/campaign.ts

Length of output: 157


Script:

#!/bin/bash
# Let's try a different approach to find Campaign type definition
# First, let's find the relevant type file
fd "campaign.ts|Campaign.ts" --type f

# Then let's use ast-grep to find type definitions
ast-grep --pattern 'type Campaign = {
  $$$
}'

# As a fallback, let's also try searching with ripgrep without special chars
rg -l "type Campaign"

Length of output: 1516

Copy link

github-actions bot commented Nov 22, 2024

Visit the preview URL for this PR (updated for commit bb0bc60):

https://si-admin-staging--pr946-ahee-campaign-model-3l4u4c3d.web.app

(expires Fri, 29 Nov 2024 10:12:32 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: b7b0969384059dce6ea8fad1ee1d1737e54e6676

@andrashee andrashee changed the title Add public and featured flag to campaign model Add additional fields to campaign model Nov 22, 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: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 09d4afb and 1f2257e.

📒 Files selected for processing (2)
  • admin/src/collections/Campaigns.ts (2 hunks)
  • shared/src/types/campaign.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • shared/src/types/campaign.ts

admin/src/collections/Campaigns.ts Outdated Show resolved Hide resolved
admin/src/collections/Campaigns.ts Show resolved Hide resolved
admin/src/collections/Campaigns.ts Show resolved Hide resolved
@ssandino ssandino linked an issue Nov 22, 2024 that may be closed by this pull request
2 tasks
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)
admin/src/collections/Campaigns.ts (2)

71-100: Consider implementing URL sanitization for social media links

While the implementation structure is good, consider adding URL sanitization to prevent potential security issues like XSS attacks when these URLs are rendered in the frontend.

Consider implementing a URL sanitization utility that:

  1. Validates protocol (https preferred)
  2. Sanitizes URL parameters
  3. Validates against allowed domains for each platform

Would you like me to provide an example implementation of such a utility?


137-148: Enhance visibility flag descriptions

The current descriptions could be more detailed to help administrators understand the implications of these flags.

Consider updating the descriptions like this:

 public: {
   dataType: 'boolean',
   name: 'Public',
-  description: 'Listed on campaign overview',
+  description: 'When enabled, the campaign will be visible in public campaign listings and searchable by users',
   defaultValue: false,
 },
 featured: {
   dataType: 'boolean',
   name: 'Featured',
-  description: 'Featured on campaign overview',
+  description: 'When enabled, the campaign will be highlighted in prominent positions like the homepage or featured sections',
   defaultValue: false,
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1f2257e and bb0bc60.

📒 Files selected for processing (1)
  • admin/src/collections/Campaigns.ts (2 hunks)
🔇 Additional comments (1)
admin/src/collections/Campaigns.ts (1)

149-159: Implement database-level uniqueness constraint for slugs

While the description mentions that slugs must be unique, there's no mechanism to enforce this at the database level.

Let's check if there are any existing unique constraints or indexes on the slug field:

Consider implementing:

  1. A Firestore security rule to enforce uniqueness
  2. A Cloud Function to validate uniqueness before write
  3. An index on the slug field for efficient lookups

Would you like me to provide implementation details for any of these suggestions?

@andrashee andrashee merged commit 383c570 into main Nov 22, 2024
19 checks passed
@andrashee andrashee deleted the ahee/campaign-model-public-featured branch November 22, 2024 10:53
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.

[Web]: Optimization of campaign pages
2 participants