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

feat(web): FAQ List and Accordion - Set single expand to false #15984

Merged
merged 2 commits into from
Sep 29, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Sep 12, 2024

FAQ List and Accordion - Set single expand to false

What

  • Prevent an item from closing when another gets opened

Why

  • When you have an item open and open another often the scroll takes you away from what you just opened
  • We shouldn't assume that the user wants to close other items when opening a new one

Screenshots / Gifs

Before

Screen.Recording.2024-09-12.at.16.41.33.mov

After

Screen.Recording.2024-09-12.at.16.42.27.mov

Summary by CodeRabbit

  • New Features
    • The Accordion component now supports multiple items being expanded simultaneously with the new singleExpand property set to false.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Sep 12, 2024
@RunarVestmann RunarVestmann requested review from a team as code owners September 12, 2024 16:43
Copy link
Contributor

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes involve the Accordion component within the AccordionSlice component, introducing a new prop called singleExpand, which is set to false. This allows multiple accordion items to be expanded simultaneously. The rendering logic for the accordion items remains unchanged. Additionally, the singleExpand property has been added to the Accordion component in the FaqList.tsx file.

Changes

Files Change Summary
apps/web/components/Organization/Slice/AccordionSlice/AccordionSlice.tsx
libs/island-ui/contentful/src/lib/FaqList/FaqList.tsx
Added singleExpand prop to the Accordion component, set to false, allowing multiple expansions.

Possibly related PRs

  • feat(web): Team List - Accordion variant #15289: This PR introduces an accordion variant to the TeamList component, which is directly related to the changes made in the Accordion component of the main PR, as both involve accordion functionality.
  • feat(web): Generic List - UX improvements #15983: This PR enhances the Generic List component, which shares a structural relationship with the Accordion component in terms of user interface design and interaction, although it does not directly modify the accordion behavior.

Suggested reviewers

  • mannipje
  • Toti91

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.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 12, 2024

Datadog Report

Branch report: feature/web-single-expand-faq-list
Commit report: d7c2d61
Test service: web

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

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.78%. Comparing base (a73abfa) to head (dd1c6b6).
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #15984      +/-   ##
==========================================
+ Coverage   36.70%   36.78%   +0.08%     
==========================================
  Files        6776     6722      -54     
  Lines      139608   137613    -1995     
  Branches    39691    39167     -524     
==========================================
- Hits        51243    50623     -620     
+ Misses      88365    86990    -1375     
Flag Coverage Δ
web 1.83% <ø> (ø)

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

Files with missing lines Coverage Δ
...ganization/Slice/AccordionSlice/AccordionSlice.tsx 0.00% <ø> (ø)

... and 307 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 cb65af3...dd1c6b6. Read the comment docs.

Copy link
Member

@disaerna disaerna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this change 👏🏼 I thought about it when viewing the "Tengjum ríkið" page as well 💯

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)
libs/island-ui/contentful/src/lib/FaqList/FaqList.tsx (2)

Line range hint 1-53: Enhance TypeScript usage for better type safety.

The component makes good use of TypeScript, but there's room for improvement:

  1. Consider using more specific types for the answer property in the questions array. Currently, it's typed as SliceType[] with an optional chaining operator, but it's always passed to the richText function. You could create a custom type that ensures answer is always an array of SliceType.

  2. The locale prop has a default value of 'is', but the Locale type might include other options. Consider creating a union type for supported locales to make it more explicit.

Here's a suggested improvement for the types:

import { Locale } from '@island.is/shared/types'

type SupportedLocale = 'is' | 'en' // Add other supported locales as needed

type Question = {
  id: string
  question: string
  answer: SliceType[] // Remove optional chaining as it's always used
}

export interface FaqListProps {
  title: string
  questions: Question[]
  showTitle?: boolean
  locale?: SupportedLocale
}

This change will provide better type safety and make the component's API more explicit.


Line range hint 1-53: Consider performance optimization for large FAQ lists.

The current implementation renders all FAQ items at once, which could lead to performance issues for very large lists. Consider implementing lazy loading or virtualization for better performance with large datasets.

You could use a library like react-window or react-virtualized to implement virtualization. Here's a high-level example of how you might modify the component to use react-window:

import { FixedSizeList as List } from 'react-window';

// ... (rest of the imports)

const FaqList: FC<React.PropsWithChildren<FaqListProps>> = ({
  title,
  questions,
  showTitle = true,
  locale = 'is',
}) => {
  const renderRow = ({ index, style }) => {
    const { id, question, answer } = questions[index];
    return (
      <div style={style}>
        <AccordionItem
          key={id}
          id={`faq_${id}`}
          label={question}
          labelUse="h2"
        >
          {richText(answer, undefined, locale)}
        </AccordionItem>
      </div>
    );
  };

  return (
    <Stack space={6}>
      {title && showTitle !== false && (
        <Text variant="h2" as="h2">
          <span data-sidebar-link={slugify(title)}>{title}</span>
        </Text>
      )}
      <Accordion singleExpand={false}>
        <List
          height={400} // Adjust based on your needs
          itemCount={questions.length}
          itemSize={100} // Adjust based on average item size
          width="100%"
        >
          {renderRow}
        </List>
      </Accordion>
    </Stack>
  );
};

This approach would significantly improve performance for large FAQ lists by only rendering the visible items.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cb65af3 and dd1c6b6.

📒 Files selected for processing (2)
  • apps/web/components/Organization/Slice/AccordionSlice/AccordionSlice.tsx (1 hunks)
  • libs/island-ui/contentful/src/lib/FaqList/FaqList.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/web/components/Organization/Slice/AccordionSlice/AccordionSlice.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."
libs/island-ui/contentful/src/lib/FaqList/FaqList.tsx (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (3)
libs/island-ui/contentful/src/lib/FaqList/FaqList.tsx (2)

36-36: LGTM: singleExpand prop change aligns with PR objectives.

The change to set singleExpand={false} on the Accordion component correctly implements the desired behavior of allowing multiple FAQ items to remain open simultaneously. This aligns with the PR objectives to enhance user experience by preventing previously opened items from closing when a new item is opened.


Line range hint 1-53: Verify reusability across different NextJS apps.

The component seems to be designed for reusability, as it's located in the libs directory. However, to ensure it adheres to best practices for reusability across different NextJS apps, consider the following:

  1. The component uses @island.is/island-ui/core for UI elements. Ensure this dependency is available and consistent across all NextJS apps that will use this component.
  2. The Locale type is imported from @island.is/shared/types. Verify that this shared type is accessible in all NextJS apps where this component will be used.

To confirm the availability and consistency of these dependencies across different NextJS apps, run the following script:

This will help ensure that the component remains reusable across different NextJS apps.

apps/web/components/Organization/Slice/AccordionSlice/AccordionSlice.tsx (1)

63-63: LGTM: Change aligns with PR objectives and improves user experience.

The modification to set singleExpand={false} on the Accordion component successfully implements the desired functionality described in the PR objectives. This change allows multiple FAQ items to remain open simultaneously, enhancing the user experience by preventing the closure of previously opened items when a new one is expanded.

The implementation adheres to NextJS best practices and makes good use of TypeScript for type safety. The change is straightforward and doesn't introduce any apparent performance implications.

@kodiakhq kodiakhq bot merged commit 85443f8 into main Sep 29, 2024
33 checks passed
@kodiakhq kodiakhq bot deleted the feature/web-single-expand-faq-list branch September 29, 2024 11:57
thoreyjona pushed a commit that referenced this pull request Oct 2, 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
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants