planet-webapp icon indicating copy to clipboard operation
planet-webapp copied to clipboard

Add locale as a query parameter to /app/projects API calls

Open mohitb35 opened this issue 7 months ago • 2 comments

Include locale in API calls to prevent caching issues when the locale changes, ensuring the correct response is fetched based on the current locale.

mohitb35 avatar Apr 30 '25 06:04 mohitb35

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

Name Status Preview Updated (UTC)
planet-webapp-multi-tenancy-setup ✅ Ready (Inspect) Visit Preview May 22, 2025 8:58am

vercel[bot] avatar Apr 30 '25 06:04 vercel[bot]

Walkthrough

This change updates multiple project-related components and contexts to include both the current tenant ID and locale as query parameters in their API requests. This ensures browser caching is effectively broken when either the tenant or locale changes. The effect hook dependencies are also updated accordingly. No other logic, control flow, or exported interfaces are altered.

Changes

File(s) Change Summary
src/features/projectsV2/ProjectDetails/index.tsx Adds tenant ID (tenantConfig.id) as a query parameter to the project details API call; updates effect dependencies to include tenant ID.
src/features/projectsV2/ProjectsContext.tsx Adds tenant ID as a query parameter to the projects list API call; updates effect dependencies to include tenant ID.
src/features/user/Widget/DonationLink/index.tsx Adds explicit typing for API response (MapProject[]), changes tenant ID access to direct property, and adds tenant and locale query parameters to break cache.
src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx Adds locale as a query parameter to the projects API call for cache busting; imports and uses useLocale.
src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx Adds tenant ID and locale as query parameters in project data API call; updates effect dependencies to include tenant ID and locale.
src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx Adds tenant ID and locale as query parameters; explicitly types API response as MapProject[]; removes type assertion on setProjects.
src/tenants/salesforce/VTOCampaign2024/components/ProjectGrid.tsx Adds tenant ID and locale as query parameters; explicitly types API response as MapProject[]; removes type assertion on setProjects.
src/tenants/salesforce/VTOCampaign2025/components/ProjectGrid.tsx Adds locale as a query parameter; explicitly types API response as MapProject[]; removes type assertion on setProjects.

Poem

🐇 Hopping through code with a tenant and locale,
Breaking old caches wherever they go.
Queries now fresh, no stale data in sight,
Fetching new projects, all shiny and bright.
With every new hop, the data’s brand new—
A rabbit’s delight in the code we pursue! 🥕✨

[!NOTE]

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. Learn more here.


[!NOTE]

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings. Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7532a5f6213ffaf965267e48bf07e4eb821e9db0 and a56d815216f02ff81abd2407d7618334ff02e506.

📒 Files selected for processing (8)
  • src/features/projectsV2/ProjectDetails/index.tsx (4 hunks)
  • src/features/projectsV2/ProjectsContext.tsx (4 hunks)
  • src/features/user/Widget/DonationLink/index.tsx (2 hunks)
  • src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx (3 hunks)
  • src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx (3 hunks)
  • src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx (1 hunks)
  • src/tenants/salesforce/VTOCampaign2024/components/ProjectGrid.tsx (1 hunks)
  • src/tenants/salesforce/VTOCampaign2025/components/ProjectGrid.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/features/projectsV2/ProjectDetails/index.tsx
  • src/features/projectsV2/ProjectsContext.tsx
🧰 Additional context used
🧬 Code Graph Analysis (4)
src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx (1)
src/hooks/useApi.ts (1)
  • useApi (93-321)
src/tenants/salesforce/VTOCampaign2025/components/ProjectGrid.tsx (3)
src/tenants/salesforce/VTOCampaign2024/components/ProjectGrid.tsx (1)
  • ProjectGrid (15-86)
src/hooks/useApi.ts (1)
  • useApi (93-321)
src/features/common/types/projectv2.d.ts (1)
  • MapProject (20-20)
src/features/user/Widget/DonationLink/index.tsx (1)
src/features/common/types/projectv2.d.ts (1)
  • MapProject (20-20)
src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx (3)
src/tenants/salesforce/VTOCampaign2025/components/ProjectGrid.tsx (1)
  • ProjectGrid (15-85)
src/hooks/useApi.ts (1)
  • useApi (93-321)
src/features/common/types/projectv2.d.ts (1)
  • MapProject (20-20)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: ESLint on Ubuntu
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (20)
src/tenants/salesforce/Mangroves/components/ProjectGrid.tsx (3)

12-13: Import change looks good.

Adding the useLocale hook from next-intl is necessary to access the current locale.


32-33: Locale usage implementation looks good.

Adding the locale to be used in the API request is consistent with the PR objective.


46-48: Good cache-busting implementation with clear comment.

The comment clearly explains why locale is being added as a query parameter: to break browser caching when locale changes.

src/tenants/salesforce/VTOCampaign2025/components/ProjectGrid.tsx (4)

12-13: Import change looks good.

Adding the useLocale hook from next-intl is necessary to access the current locale.


17-18: Locale usage implementation looks good.

Adding the locale to be used in the API request is consistent with the PR objective.


26-26: Type annotation improvement.

Adding the generic type parameter <MapProject[]> to the getApi call improves type safety.


30-31: Good cache-busting implementation.

Adding locale as a query parameter helps break browser caching when locale changes.

src/tenants/salesforce/OceanforceCampaign/components/ContentSection.tsx (4)

14-16: Import changes look good.

Adding the useLocale hook from next-intl and useTenant from tenant context is necessary for accessing the current locale and tenant configuration.


22-24: Locale and tenant usage implementation looks good.

Adding the locale and tenant config to be used in the API request is consistent with the PR objective.


38-39: Good cache-busting implementation.

Adding locale and tenant as query parameters helps break browser caching when locale or tenant changes.


51-51: Excellent dependency array update.

The useEffect dependency array correctly includes locale and tenantConfig.id, ensuring that project data is reloaded when either changes. This is important for the cache-busting mechanism to work properly.

src/features/user/Widget/DonationLink/index.tsx (3)

2-3: Type import looks good.

Adding the import for the MapProject type from projectv2 improves type safety in the API call.


27-27: Type annotation improvement.

Adding the generic type parameter <MapProject[]> to the getApi call improves type safety.


31-33: Good cache-busting implementation with clear comment.

The comment clearly explains why locale and tenant are being added as query parameters: to break browser caching when locale changes.

src/tenants/salesforce/VTOCampaign2023/components/ProjectGrid.tsx (3)

12-13: Good addition of locale and tenant hooks.

These imports allow the component to access the current locale and tenant information, which is essential for the API request parameters.


17-18: Properly initialized hooks for locale and tenant.

Using these hooks is the appropriate way to access the current locale and tenant configuration.


26-35: API request now includes locale parameter to prevent caching issues.

The addition of locale and tenant parameters to the API request aligns with the PR objective of preventing caching issues when locale changes. The explicit typing of getApi<MapProject[]> is also good practice.

However, the dependency array in the useEffect hook is empty, which means the API call won't be triggered when locale or tenantConfig changes. Consider updating it:

  }, []);
+  }, [locale, tenantConfig.id, getApi, setErrors, redirect]);

This ensures fresh data is fetched when the locale or tenant changes, fully addressing the caching issue mentioned in the PR objectives.

src/tenants/salesforce/VTOCampaign2024/components/ProjectGrid.tsx (3)

12-13: Good addition of locale and tenant hooks.

These imports allow the component to access the current locale and tenant information, which is essential for the API request parameters.


17-18: Properly initialized hooks for locale and tenant.

Using these hooks is the appropriate way to access the current locale and tenant configuration.


26-35: API request now includes locale parameter to prevent caching issues.

The addition of locale and tenant parameters to the API request aligns with the PR objective of preventing caching issues when locale changes. The explicit typing of getApi<MapProject[]> is also good practice.

However, the dependency array in the useEffect hook is empty, which means the API call won't be triggered when locale or tenantConfig changes. Consider updating it:

  }, []);
+  }, [locale, tenantConfig.id, getApi, setErrors, redirect]);

This ensures fresh data is fetched when the locale or tenant changes, fully addressing the caching issue mentioned in the PR objectives.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

coderabbitai[bot] avatar Apr 30 '25 06:04 coderabbitai[bot]

@mariahosfeld Have updated this PR, this should resolve the project data caching issue.

mohitb35 avatar May 21 '25 11:05 mohitb35

@mohitb35 When I opened the deployment link, I encountered the error below. Could you please address this? image

sunilsabatp avatar May 22 '25 07:05 sunilsabatp

@mohitb35 When I opened the deployment link, I encountered the error below. Could you please address this? image

Fixed, the error was related to the new header config. Merging from develop fixed the issue.

mohitb35 avatar May 22 '25 09:05 mohitb35