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): Connect language toggler for standalone organization pages #17055

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Nov 27, 2024

Connect language toggler for standalone organization pages

What

The "EN" button doesn't work at the moment so this PR adds the global context to the standalone layout which allows us to pass props to the LanguageToggler component

Screenshots / Gifs

Before

Screen.Recording.2024-11-27.at.15.59.23.mov

After

Screen.Recording.2024-11-27.at.16.00.17.mov
Screen.Recording.2024-11-27.at.16.04.34.mov

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a GlobalContextProvider for enhanced global context management in the layout.
    • Added a new component, LanguageToggleSetup, for handling contentful IDs in both the StandaloneHome and StandaloneParentSubpage components.
    • Implemented a new GraphQL query, GET_ORGANIZATION_PARENT_SUBPAGE_QUERY, for improved access to organization parent subpage data.
  • Bug Fixes

    • No bug fixes were included in this release.
  • Documentation

    • No documentation updates were made in this release.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Nov 27, 2024
@RunarVestmann RunarVestmann requested review from a team as code owners November 27, 2024 16:00
Copy link
Contributor

coderabbitai bot commented Nov 27, 2024

Walkthrough

The changes in this pull request involve the addition of a global context provider to the StandaloneLayout component and the introduction of a new functional component, LanguageToggleSetup, which utilizes a custom hook, useContentfulId. The LanguageToggleSetup component is integrated into both StandaloneHome and StandaloneParentSubpage components. Additionally, a new GraphQL query for retrieving organization parent subpage data is introduced. These modifications enhance the component structure and data handling capabilities without altering existing logic or control flow.

Changes

File Path Change Summary
apps/web/layouts/organization/standalone/standalone.tsx Added import for GlobalContextProvider and wrapped StandaloneLayout with this provider.
apps/web/screens/Organization/Standalone/Home.tsx Introduced LanguageToggleSetup component that uses useContentfulId, added to StandaloneHome.
apps/web/screens/Organization/Standalone/ParentSubpage.tsx Added LanguageToggleSetup component, updated props to include an array of IDs for contentful ID management.
apps/web/screens/queries/Organization.tsx Added new GraphQL query GET_ORGANIZATION_PARENT_SUBPAGE_QUERY for retrieving organization data.

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • mannipje
  • oddsson

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.

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

🧹 Outside diff range and nitpick comments (4)
apps/web/screens/Organization/Standalone/Home.tsx (1)

Line range hint 31-52: Consider extracting language toggle logic to a dedicated hook

The current implementation spreads language toggle setup across components. Consider creating a dedicated hook (e.g., useOrganizationLanguage) that encapsulates all language-related logic, making it more maintainable and reusable.

This would:

  1. Centralize language toggle logic
  2. Make the implementation more testable
  3. Reduce component complexity
apps/web/screens/Organization/Standalone/ParentSubpage.tsx (1)

56-59: Consider enhancing type safety and documentation.

The component could benefit from the following improvements:

  1. Add JSDoc to document the component's purpose and side effects
  2. Use a more explicit TypeScript interface for props
  3. Add error handling for invalid IDs
  4. Consider a more descriptive name that indicates its side-effect nature
+/** 
+ * Sets up language toggle functionality by registering contentful IDs
+ * for the current page and its parent pages with the global context.
+ */
+interface LanguageToggleSetupProps {
+  /** Array of contentful IDs for the current page hierarchy */
+  ids: readonly string[]
+}
-const LanguageToggleSetup = (props: { ids: string[] }) => {
+const LanguageToggleSetup = ({ ids }: LanguageToggleSetupProps) => {
+  if (!ids.every(Boolean)) {
+    console.warn('Invalid or missing contentful IDs:', ids)
+    return null
+  }
-  useContentfulId(...props.ids)
+  useContentfulId(...ids)
   return null
 }
apps/web/screens/queries/Organization.tsx (2)

Line range hint 425-432: LGTM! Consider adding language-related fields.

The query structure is clean and follows the established patterns. However, since this query is part of implementing language toggler functionality, consider adding language-related fields that might be needed for the feature.

Consider adding fields like:

  • locale - current language
  • availableLanguages - supported languages
  • alternateLanguages - URLs for other language versions

This would ensure all necessary data for language switching is available in a single query.


Line range hint 425-432: Add JSDoc documentation for the query.

To improve maintainability, consider adding documentation that explains:

  • The purpose of this query
  • When it should be used
  • The expected input parameters
  • The relationship with language toggling feature

Example documentation:

/**
 * Retrieves organization parent subpage data for standalone pages.
 * Used by the LanguageToggler component to enable language switching functionality.
 * 
 * @param input GetOrganizationParentSubpageInput - Input parameters for the query
 * @returns Organization parent subpage data including navigation structure
 */
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 15571ef and 9f91f53.

📒 Files selected for processing (4)
  • apps/web/layouts/organization/standalone/standalone.tsx (3 hunks)
  • apps/web/screens/Organization/Standalone/Home.tsx (3 hunks)
  • apps/web/screens/Organization/Standalone/ParentSubpage.tsx (3 hunks)
  • apps/web/screens/queries/Organization.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
apps/web/layouts/organization/standalone/standalone.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."
apps/web/screens/Organization/Standalone/Home.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."
apps/web/screens/Organization/Standalone/ParentSubpage.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."
apps/web/screens/queries/Organization.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 (7)
apps/web/screens/Organization/Standalone/Home.tsx (2)

14-14: LGTM: Import statement follows project conventions

The import statement is properly placed and follows the project's import structure.


52-52: Verify organizationPage.id existence and consider component placement

The component usage needs verification for:

  1. Type safety of organizationPage.id
  2. Handling of undefined organizationPage

Let's verify the type safety and usage:

✅ Verification successful

Based on the gathered information, I can now provide a final response:

Type safety and usage of organizationPage.id is verified

The code shows that:

  1. organizationPage is properly typed as a required prop in StandaloneHomeProps interface
  2. LanguageToggleSetup component has proper type checking for the id prop
  3. The usage is safe as organizationPage is a required prop, not optional
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if organizationPage.id is properly typed and required
ast-grep --pattern 'interface OrganizationPage {
  $$$
  id: string
  $$$
}'

# Check for undefined checks in other files
rg -A 3 "organizationPage\?.id" "apps/web/**/*.tsx"

Length of output: 190


Script:

#!/bin/bash
# Let's first find the correct path for the component
fd "Home.tsx" --type f

# Check the type definition and usage of organizationPage
rg -A 3 "organizationPage" --type tsx

# Look for LanguageToggleSetup component definition
fd "LanguageToggleSetup" --type f

# Check the component's props interface
ast-grep --pattern 'interface $_ {
  $$$
  id: $_
  $$$
}'

Length of output: 101930


Script:

#!/bin/bash
# Let's search for the LanguageToggleSetup component definition and its props
rg -l "LanguageToggleSetup" --type ts --type tsx

# Search for organizationPage type definition
rg -A 5 "organizationPage\s*:\s*{" --type ts --type tsx

# Search for organizationPage usage in Home.tsx
rg -A 5 "organizationPage" "apps/web/screens/Organization/Standalone/Home.tsx"

Length of output: 2527


Script:

#!/bin/bash
# Let's try with different file extension patterns
fd -e tsx -e ts "LanguageToggleSetup"

# Search for OrganizationPage interface definition
rg "interface\s+OrganizationPage" -A 10

# Check if organizationPage is properly typed in the component props
rg "interface\s+StandaloneHomeProps" -A 5

Length of output: 595

apps/web/screens/Organization/Standalone/ParentSubpage.tsx (2)

24-24: LGTM!

The import statement follows the project's conventions and is correctly placed with other hook imports.


78-80: Verify ID availability and SSR impact.

Please ensure:

  1. All required IDs are guaranteed to be non-null
  2. The component's placement doesn't negatively impact SSR
✅ Verification successful

Let me gather more information about the LanguageToggleSetup component and its usage.


Let me check one more thing about the parent component's props and type definitions to understand how these IDs are handled.


Based on the gathered information, I can now provide the final response:

IDs are safely accessed and SSR implementation is correct

The implementation is safe because:

  • The LanguageToggleSetup component is a client-side only component that returns null
  • The IDs are accessed without optional chaining in the component usage, indicating they are guaranteed to be available at render time
  • The component is correctly placed within StandaloneLayout and uses useContentfulId hook appropriately
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential null IDs in the codebase
# and verify SSR-safety of the hook usage

# Check for null checks on these IDs in the codebase
echo "Checking for null checks on organization page IDs..."
rg -A 2 "organizationPage\?.id|parentSubpage\?.id|subpage\?.id" 

# Check if useContentfulId is SSR-safe
echo "Checking if useContentfulId is SSR-safe..."
ast-grep --pattern 'export $_ function useContentfulId($$$) {
  $$$
  useEffect($$$)
  $$$
}'

Length of output: 3710


Script:

#!/bin/bash
# Check LanguageToggleSetup implementation and usage
echo "Checking LanguageToggleSetup implementation..."
ast-grep --pattern 'function LanguageToggleSetup($$$) {
  $$$
}'

echo "\nChecking LanguageToggleSetup props type..."
ast-grep --pattern 'interface $_ {
  ids: $$$
}'

echo "\nChecking for null checks in LanguageToggleSetup usage..."
rg "LanguageToggleSetup" -A 2 -B 2

Length of output: 2139


Script:

#!/bin/bash
# Check ParentSubpage component's props and type definitions
echo "Checking ParentSubpage component implementation..."
rg -B 10 "export const ParentSubpage" 

echo "\nChecking type definitions for organizationPage, parentSubpage, and subpage..."
ast-grep --pattern 'interface $_ {
  organizationPage: $$$
  parentSubpage: $$$
  subpage: $$$
}'

Length of output: 419

apps/web/screens/queries/Organization.tsx (1)

Line range hint 425-432: Verify query integration with LanguageToggleSetup component.

Let's ensure the query is properly integrated with the language toggler feature.

✅ Verification successful

Let me gather more information about the integration and error handling.


Let me gather one final piece of information about the query implementation in ParentSubpage.


Query integration with LanguageToggleSetup is properly implemented

The verification shows that:

  • LanguageToggleSetup component is correctly integrated in both StandaloneHome and StandaloneParentSubpage components
  • The component properly receives the required contentful IDs for language toggling
  • Error handling is implemented using CustomNextError for various edge cases
  • The query is used in the correct context with proper error boundaries
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the integration of GET_ORGANIZATION_PARENT_SUBPAGE_QUERY with LanguageToggleSetup

# Check for query usage in relevant components
echo "Checking query usage in components..."
rg -A 5 "GET_ORGANIZATION_PARENT_SUBPAGE_QUERY" "apps/web/screens"

# Check for proper error handling
echo "Checking error handling..."
ast-grep --pattern 'useQuery($_, { GET_ORGANIZATION_PARENT_SUBPAGE_QUERY }) {
  $$$
  if ($error) {
    $$$
  }
  $$$
}'

Length of output: 1959


Script:

#!/bin/bash
# Check for LanguageToggleSetup component usage and error handling
echo "Checking LanguageToggleSetup integration..."
rg -A 10 "LanguageToggleSetup" "apps/web/screens"

echo "Checking error handling in ParentSubpage..."
ast-grep --pattern 'const { data, loading, error } = useQuery($$$)'

echo "Checking loading and error states..."
rg -A 5 "loading|error" "apps/web/screens/Organization/Standalone/ParentSubpage.tsx"

Length of output: 14615


Script:

#!/bin/bash
# Check the query implementation in ParentSubpage
echo "Checking query implementation..."
rg -A 15 "useQuery.*GET_ORGANIZATION_PARENT_SUBPAGE_QUERY" "apps/web/screens/Organization/Standalone/ParentSubpage.tsx"

# Check for any error handling components
echo "Checking error handling components..."
rg "ErrorBoundary|ErrorPage|CustomNextError" "apps/web/screens/Organization/Standalone/ParentSubpage.tsx"

Length of output: 657

apps/web/layouts/organization/standalone/standalone.tsx (2)

13-13: LGTM: Clean import of GlobalContextProvider

The import follows the project's conventions and is correctly placed with other context-related imports.


Line range hint 91-274: LGTM: Proper implementation of GlobalContextProvider

The GlobalContextProvider is correctly positioned at the root level of the layout, ensuring proper context propagation to all child components including the language toggler. This implementation follows NextJS best practices for global state management.

Let's verify the GlobalContextProvider's usage in related components:

✅ Verification successful

GlobalContextProvider implementation is correctly positioned and not duplicated

The verification confirms that the GlobalContextProvider is properly implemented in the standalone layout and follows the same pattern as in the main layout. The provider is positioned at the root level, and there are no conflicting context providers. The LanguageToggler component is also correctly integrated within the component hierarchy under this context.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify GlobalContextProvider usage and LanguageToggler integration

# Check for LanguageToggler component usage in organization-related files
rg -A 3 "LanguageToggler" "apps/web/components" "apps/web/screens/Organization"

# Verify GlobalContextProvider is not duplicated in parent components
rg -A 3 "GlobalContextProvider" "apps/web/screens/Organization"

Length of output: 4006


Script:

#!/bin/bash
# Let's verify GlobalContextProvider implementation and usage

# Check GlobalContextProvider implementation
ast-grep --pattern 'export const GlobalContextProvider = ({ $$ }) => { $$ }'

# Check for any other GlobalContextProvider usage in layout files
rg -A 3 "GlobalContextProvider" "apps/web/layouts"

# Check if there are any other context providers that might conflict
rg -A 3 "ContextProvider" "apps/web/layouts" "apps/web/components"

Length of output: 3670

Copy link

codecov bot commented Nov 27, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 35.68%. Comparing base (bf0605a) to head (d00dad2).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
apps/web/screens/Organization/Standalone/Home.tsx 0.00% 3 Missing ⚠️
.../screens/Organization/Standalone/ParentSubpage.tsx 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17055      +/-   ##
==========================================
- Coverage   35.69%   35.68%   -0.02%     
==========================================
  Files        6938     6939       +1     
  Lines      147107   147004     -103     
  Branches    41823    41798      -25     
==========================================
- Hits        52516    52459      -57     
+ Misses      94591    94545      -46     
Flag Coverage Δ
web 2.45% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...web/layouts/organization/standalone/standalone.tsx 0.00% <ø> (ø)
apps/web/screens/queries/Organization.tsx 0.00% <ø> (ø)
apps/web/screens/Organization/Standalone/Home.tsx 0.00% <0.00%> (ø)
.../screens/Organization/Standalone/ParentSubpage.tsx 0.00% <0.00%> (ø)

... and 38 files 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 bf0605a...d00dad2. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 27, 2024

Datadog Report

Branch report: fix/web-organization-standalone-pages-language-toggler
Commit report: 2b55a3a
Test service: web

✅ 0 Failed, 84 Passed, 0 Skipped, 30.39s Total Time
➡️ Test Sessions change in coverage: 1 no change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants