-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix(web): Connect language toggler for standalone organization pages #17055
Conversation
WalkthroughThe changes in this pull request involve the addition of a global context provider to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 hookThe 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:
- Centralize language toggle logic
- Make the implementation more testable
- 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:
- Add JSDoc to document the component's purpose and side effects
- Use a more explicit TypeScript interface for props
- Add error handling for invalid IDs
- 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 languageavailableLanguages
- supported languagesalternateLanguages
- URLs for other language versionsThis 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
📒 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:
- Type safety of
organizationPage.id
- 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:
organizationPage
is properly typed as a required prop inStandaloneHomeProps
interfaceLanguageToggleSetup
component has proper type checking for theid
prop- 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:
- All required IDs are guaranteed to be non-null
- 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 returnsnull
- 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 usesuseContentfulId
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
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 38 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Datadog ReportBranch report: ✅ 0 Failed, 84 Passed, 0 Skipped, 30.39s Total Time |
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:
Summary by CodeRabbit
New Features
GlobalContextProvider
for enhanced global context management in the layout.LanguageToggleSetup
, for handling contentful IDs in both theStandaloneHome
andStandaloneParentSubpage
components.GET_ORGANIZATION_PARENT_SUBPAGE_QUERY
, for improved access to organization parent subpage data.Bug Fixes
Documentation