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(web): Add locale to organization page fetch #17015

Merged
merged 2 commits into from
Nov 25, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Nov 25, 2024

Add locale to organization page fetch

Summary by CodeRabbit

  • New Features

    • Added support for language context in organization page queries, improving localization.
  • Bug Fixes

    • Maintained existing error handling for organization page retrieval.

@RunarVestmann RunarVestmann added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 25, 2024
@RunarVestmann RunarVestmann requested review from a team as code owners November 25, 2024 15:13
Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request involve modifying the Component.getProps method in the apps/web/pages/s/[...slugs]/index.tsx file. A new lang property has been added to the variables object within the GraphQL query for fetching the organization page. This addition allows the language context to be included in the query, potentially affecting the data retrieved based on the specified language. The existing logic for handling slug lengths and error handling remains unchanged.

Changes

File Path Change Summary
apps/web/pages/s/[...slugs]/index.tsx Added lang property to variables object in GraphQL query.

Possibly related PRs

Suggested reviewers

  • mannipje

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.

@RunarVestmann RunarVestmann added the high priority VIP-Kodiak PR label Nov 25, 2024
Copy link

codecov bot commented Nov 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.59%. Comparing base (eb881d2) to head (6d43aa8).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17015   +/-   ##
=======================================
  Coverage   35.59%   35.59%           
=======================================
  Files        6924     6924           
  Lines      146382   146382           
  Branches    41560    41563    +3     
=======================================
+ Hits        52100    52104    +4     
+ Misses      94282    94278    -4     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
application-api-files 61.98% <ø> (ø)
application-core 70.79% <ø> (ø)
application-system-api 38.71% <ø> (-0.01%) ⬇️
application-template-api-modules 27.73% <ø> (ø)
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.14% <ø> (ø)
application-templates-estate 12.15% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.77% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.54% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.23% <ø> (ø)
application-templates-parental-leave 29.96% <ø> (ø)
application-types 6.57% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.54% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
web 1.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
apps/web/pages/s/[...slugs]/index.tsx 0.00% <ø> (ø)

... and 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eb881d2...6d43aa8. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 25, 2024

Datadog Report

All test runs 2243e33 🔗

21 Total Test Services: 0 Failed, 20 Passed
➡️ Test Sessions change in coverage: 92 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 8.95s 1 no change Link
api 0 0 0 4 0 2.97s 1 no change Link
application-api-files 0 0 0 2 0 4.31s 1 no change Link
application-core 0 0 0 97 0 15.12s 1 no change Link
application-system-api 0 0 0 40 0 2m 2.15s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 7.28s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 15.41s 1 no change Link
application-templates-criminal-record 0 0 0 2 0 9.98s 1 no change Link
application-templates-driving-license 0 0 0 13 0 13.13s 1 no change Link
application-templates-example-payment 0 0 0 2 0 10.29s 1 no change Link

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 (2)
apps/web/pages/s/[...slugs]/index.tsx (2)

Line range hint 182-263: Consider refactoring locale-based route handling.

The current implementation has repeated locale checks and hardcoded route names. This could be improved for better maintainability.

Consider extracting the route mappings to constants and simplifying the logic:

+const ROUTE_MAPPINGS = {
+  is: {
+    news: 'frett',
+    events: 'vidburdir',
+    publishedMaterial: 'utgefid-efni'
+  },
+  en: {
+    news: 'news',
+    events: 'events',
+    publishedMaterial: 'published-material'
+  }
+};
+
+const getLocalizedRoute = (route: keyof typeof ROUTE_MAPPINGS.en, locale: string) => 
+  ROUTE_MAPPINGS[locale === 'is' ? 'is' : 'en'][route];
+
 if (slugs.length === 2) {
-  if (locale !== 'is') {
-    if (slugs[1] === 'news') {
-      return {
-        page: {
-          type: PageType.ALL_NEWS,
-          props: await OrganizationNewsList.getProps(context),
-        },
-      }
-    }
-    // ... more conditions
-  } else {
-    if (slugs[1] === 'frett') {
+  const currentRoute = slugs[1];
+  if (currentRoute === getLocalizedRoute('news', locale)) {
       return {
         page: {
           type: PageType.ALL_NEWS,
           props: await OrganizationNewsList.getProps(context),
         },
       }
-    }
-    // ... more conditions
   }
+  // Similar refactoring for other routes

Line range hint 284-285: Remove ts-ignore by fixing the type definition.

The ts-ignore comment suggests an underlying type issue with the withLocale HOC that should be addressed properly.

Consider:

  1. Adding proper type definitions for the withLocale HOC
  2. Or creating a proper type assertion that explains why the type check can be safely ignored

If you need help with the type definitions, I can assist in creating them.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ac1a80f and 080ad40.

📒 Files selected for processing (1)
  • apps/web/pages/s/[...slugs]/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/web/pages/s/[...slugs]/index.tsx (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (1)
apps/web/pages/s/[...slugs]/index.tsx (1)

147-147: LGTM: Locale parameter addition looks correct.

The addition of the lang parameter to the GraphQL query variables is consistent with the PR objective and properly uses the context locale with a fallback to 'is'.

Let's verify that the GraphQL schema supports this parameter:

✅ Verification successful

The lang parameter is correctly supported in the GraphQL schema

Based on the search results, the lang parameter is properly supported in the GraphQL schema and consistently used across the codebase:

  1. The input type is defined in libs/cms/src/lib/dto/getOrganizationPage.input.ts with lang as a required string field
  2. The query is defined in apps/web/screens/queries/Organization.tsx and accepts this input
  3. Multiple components across the codebase use this parameter consistently with the same pattern
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the GraphQL schema supports the lang parameter
ast-grep --pattern 'type QueryGetOrganizationPageArgs {
  input: {
    $$$
    lang: $_
    $$$
  }
}'

Length of output: 104


Script:

#!/bin/bash
# Let's try a different approach to find the GraphQL schema definition
# First, let's locate potential GraphQL schema files
fd "\.(graphql|gql)$"

# Then, let's search for the GetOrganizationPage query definition
rg "GetOrganizationPage.*input.*lang" -A 5

Length of output: 19998


Script:

#!/bin/bash
# Let's try to find the GraphQL query definition in TypeScript files
rg "GetOrganizationPage.*\{" -A 10 --type ts

# Also search for the query type definition
rg "type.*GetOrganizationPage" -A 10 --type ts

Length of output: 22401

@kodiakhq kodiakhq bot merged commit eafbdd9 into main Nov 25, 2024
86 checks passed
@kodiakhq kodiakhq bot deleted the fix/web-organization-missing-locale-on-fetcj branch November 25, 2024 15:46
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass high priority VIP-Kodiak PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants