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

chore(web): Move organization subpage content into separate component #16915

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Nov 18, 2024

Move organization subpage content into separate component

What

  1. Move the subpage content into its own component
  2. Skip rendering slices in case there is custom content

Why

  1. We are working on reusing the subpage content component at a later point so that is one reason for having it as its own component
  2. We don't want slices to be rendered in case there is custom content provided

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 new SubPageContent component for improved content rendering.
  • Refactor

    • Enhanced modularity by separating the SubPage component into distinct layout and content components.
    • Streamlined error handling and data fetching processes for better reliability.

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

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes in this pull request involve a significant refactor of the SubPage component located in apps/web/screens/Organization/SubPage.tsx. The component has been split into two separate components: SubPage and SubPageContent. The SubPage component manages layout and props, while SubPageContent focuses on rendering the subpage content. The refactor maintains existing functionality, such as error handling and navigation logic, while improving code readability and modularity.

Changes

File Path Change Summary
apps/web/screens/Organization/SubPage.tsx Refactored SubPage into SubPage and SubPageContent. Updated method signatures and props.

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.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

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

Project coverage is 36.45%. Comparing base (a8e03f5) to head (b37f307).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
apps/web/screens/Organization/SubPage.tsx 0.00% 29 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16915      +/-   ##
==========================================
- Coverage   36.46%   36.45%   -0.01%     
==========================================
  Files        6903     6903              
  Lines      144576   144559      -17     
  Branches    41284    41278       -6     
==========================================
- Hits        52714    52700      -14     
+ Misses      91862    91859       -3     
Flag Coverage Δ
judicial-system-backend 55.53% <ø> (+<0.01%) ⬆️
judicial-system-web 27.16% <ø> (ø)
web 1.77% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
apps/web/screens/Organization/SubPage.tsx 0.00% <0.00%> (ø)

... and 11 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 a8e03f5...b37f307. Read the comment docs.

---- 🚨 Try these New Features:

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

🧹 Outside diff range and nitpick comments (6)
apps/web/screens/Organization/SubPage.tsx (6)

69-69: Redundant namespace hook usage

The variable n is assigned using useNamespace(namespace), but it appears that n is only used once in the TOC component's title prop. Consider using useNamespace(namespace) directly within the component where it's needed to reduce unnecessary variable assignments.


Line range hint 98-101: Possible type assertion issues with subpage.description

The webRichText function is called with subpage?.description as SliceType[], which could lead to runtime errors if subpage.description is not of type SliceType[]. Casting with as does not perform any runtime checks.

Consider adding type guards or validations to ensure subpage.description is indeed an array of SliceType.


155-178: Simplify conditional rendering of the sign language video

The code for rendering the SignLanguageButton within the condition subpage?.signLanguageVideo?.url is quite nested and complex.

Consider extracting the SignLanguageButton rendering logic into its own component or simplifying the JSX to improve readability.


Line range hint 343-372: Add TypeScript types to the getProps method parameters

The getProps method lacks explicit TypeScript types for its parameters. Adding types improves code readability and helps prevent bugs.

Consider updating the method signature:

- SubPage.getProps = async ({ apolloClient, locale, query, req }) => {
+ SubPage.getProps = async ({
+   apolloClient,
+   locale,
+   query,
+   req,
+ }: GetServerSidePropsContext) => {

Ensure you import GetServerSidePropsContext from next.


Line range hint 437-454: Simplify the getSlugAndSubSlug function logic

The getSlugAndSubSlug function can be simplified by using optional chaining and default values.

Consider refactoring as follows:

const getSlugAndSubSlug = (query: ParsedUrlQuery, pathname: string) => {
  const pathSegments = pathname?.split('/') ?? []
  let { slug, subSlug } = query

- if (!slug && path.length >= 2) {
-   slug = path[path.length - 2]
+ slug = slug ?? pathSegments[pathSegments.length - 2]
- }
- if (!subSlug && path.length > 0) {
-   subSlug = path.pop()
+ subSlug = subSlug ?? pathSegments[pathSegments.length - 1]
- }

  return { slug, subSlug }
}

Line range hint 486-486: Consider customizing the exported component with Next.js types

When exporting the SubPage component wrapped with withMainLayout, consider specifying the component type to ensure proper typing with Next.js.

Update the export statement:

-export default withMainLayout(SubPage)
+export default withMainLayout(SubPage as NextPage)

Ensure NextPage is imported from next.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d89ae9c and 0e9218f.

📒 Files selected for processing (1)
  • apps/web/screens/Organization/SubPage.tsx (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/web/screens/Organization/SubPage.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 (2)
apps/web/screens/Organization/SubPage.tsx (2)

301-306: Pass only necessary props to SubPageContent

When rendering SubPageContent, you pass subpage, namespace, and organizationPage. Verify that SubPageContent does not require additional props that might be necessary for its internal logic.


283-285: Confirm navigation data adheres to expected structure

Ensure that the navigationData prop provided to OrganizationWrapper matches the expected structure, especially since navList may be empty if organizationPage?.menuLinks is undefined.

Run the following script to verify the structure of navigationData:

✅ Verification successful

Navigation data structure is correctly implemented

Based on the verification:

  • The NavigationData interface in OrganizationWrapper expects items to be NavigationItem[]
  • navList is correctly typed as NavigationItem[] and is constructed from organizationPage?.menuLinks
  • Even if menuLinks is undefined, the optional chaining (?.) will result in navList being undefined, which is safely handled by the Navigation component as seen in the NavigationItem interface where items is optional
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that navigationData.items is an array of NavigationItem

# Expected: All items should have 'title', 'href', and optional 'items' properties.

rg 'navigationData\s*=\s*{\s*title:\s*\w+,\s*items:\s*(.*)}' -A5 apps/web/components/OrganizationWrapper.tsx

Length of output: 270


Script:

#!/bin/bash
# Let's first check the OrganizationWrapper component to understand the expected structure
rg -A 5 "interface.*NavigationData" apps/web/components/OrganizationWrapper.tsx

# Then check how navList is constructed
rg -B 3 -A 3 "navList" apps/web/screens/Organization/SubPage.tsx

# Also check for any type definitions related to navigation
ast-grep --pattern 'interface $_ {
  $$$
  items?: $$$
  $$$
}'

Length of output: 3396


Script:

#!/bin/bash
# Let's check the OrganizationWrapper component in the current directory structure
fd -e tsx -e ts OrganizationWrapper

# Let's also check how navigationData is used in the component
rg -B 2 -A 2 "navigationData.*=" apps/web/screens/Organization/SubPage.tsx

# And check the NavigationData type definition
fd -e tsx -e ts -x rg -l "type.*NavigationData|interface.*NavigationData"

Length of output: 513


Script:

#!/bin/bash
# Let's check the NavigationData interface in the OrganizationWrapper
rg -B 2 -A 5 "interface.*NavigationData" apps/web/components/Organization/Wrapper/OrganizationWrapper.tsx

# And check how navList is typed and constructed
rg -B 5 -A 2 "const navList.*=" apps/web/screens/Organization/SubPage.tsx

# Also check the menuLinks type
ast-grep --pattern 'type $_ = {
  menuLinks: $$$
}'

Length of output: 738

apps/web/screens/Organization/SubPage.tsx Show resolved Hide resolved
apps/web/screens/Organization/SubPage.tsx Show resolved Hide resolved
apps/web/screens/Organization/SubPage.tsx Show resolved Hide resolved
@datadog-island-is
Copy link

Datadog Report

All test runs d99b235 🔗

5 Total Test Services: 0 Failed, 5 Passed
➡️ Test Sessions change in coverage: 19 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.2s 1 no change Link
application-system-api 0 0 0 112 2 3m 58.4s 1 no change Link
application-template-api-modules 0 0 0 113 0 2m 28.54s 1 no change Link
application-ui-shell 0 0 0 74 0 40.37s 1 no change Link
web 0 0 0 84 0 34.22s 1 no change Link

@kodiakhq kodiakhq bot merged commit 6e102a0 into main Nov 18, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the chore/web-organization-subpage-content-refactor branch November 18, 2024 16:48
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
…#16915)

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants