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): Standalone organization pages - Read alert banner field from organization page #17031

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Nov 26, 2024

Standalone organization pages - Read alert banner field from organization page

What

  • Add alert banner "support" to standalone organization pages (mostly copied the alert banner code from the main layout)

Screenshots / Gifs

Before

Screenshot 2024-11-26 at 15 59 52

After

Screenshot 2024-11-26 at 15 59 04

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 the StandaloneAlertBanner component for displaying alert messages with dismiss functionality.
    • Integrated the StandaloneAlertBanner into the StandaloneLayout, enhancing user experience with relevant alerts.
  • Bug Fixes

    • Improved localization support for the alert banner close button.

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

coderabbitai bot commented Nov 26, 2024

Walkthrough

A new component named StandaloneAlertBanner has been added to the AlertBanner.tsx file, which displays an alert banner based on the alertBanner prop. This component checks for the existence of a cookie and the showAlertBanner property before rendering the AlertBanner from the @island.is/island-ui/core library. It integrates localization support and dismiss functionality. Additionally, the StandaloneAlertBanner is imported and utilized within the StandaloneLayout component in standalone.tsx, enhancing the layout with this alert feature.

Changes

File Path Change Summary
apps/web/layouts/organization/standalone/components/AlertBanner.tsx Introduced StandaloneAlertBanner component and StandaloneAlertBannerProps interface.
apps/web/layouts/organization/standalone/standalone.tsx Imported StandaloneAlertBanner and integrated it into the StandaloneLayout component.

Possibly related PRs

Suggested labels

high priority

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.

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 26, 2024

Datadog Report

Branch report: feature/web-standalone-layout-alert-banner
Commit report: 1001b9a
Test service: web

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

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

🧹 Outside diff range and nitpick comments (3)
apps/web/layouts/organization/standalone/components/AlertBanner.tsx (3)

22-24: Consider improving the banner ID generation.

The current implementation might lead to hash collisions if the alertBanner object structure changes. Consider including a version or type identifier in the hash input.

-  const bannerId = `standalone-alert-${stringHash(
-    JSON.stringify(alertBanner ?? {}),
-  )}`
+  const bannerId = `standalone-alert-v1-${stringHash(
+    `${alertBanner.title}-${alertBanner.description}-${alertBanner.bannerVariant}`,
+  )}`

26-28: Consider separating the visibility conditions.

The combined condition makes it harder to debug which check caused the banner to be hidden. Consider separating them for better maintainability.

-  if (Cookies.get(bannerId) || !alertBanner.showAlertBanner) {
+  if (!alertBanner.showAlertBanner) {
+    return null
+  }
+
+  if (Cookies.get(bannerId)) {
     return null
   }

43-43: Use translation keys for better maintainability.

Instead of hardcoding the close button label, consider using translation keys for better maintainability.

-      closeButtonLabel={activeLocale === 'is' ? 'Loka' : 'Close'}
+      closeButtonLabel={t('components.alertBanner.closeButton')}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3d9f462 and 3d9009e.

📒 Files selected for processing (2)
  • apps/web/layouts/organization/standalone/components/AlertBanner.tsx (1 hunks)
  • apps/web/layouts/organization/standalone/standalone.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
apps/web/layouts/organization/standalone/components/AlertBanner.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/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."
🔇 Additional comments (3)
apps/web/layouts/organization/standalone/components/AlertBanner.tsx (1)

1-11: LGTM! Well-structured imports and type definitions.

The code demonstrates good TypeScript practices with proper type safety for the alert banner prop.

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

18-18: LGTM!

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


208-208: Verify alert banner placement and styling.

The integration of StandaloneAlertBanner is correct and follows NextJS best practices. However, since this is a UI change, please ensure that:

  1. The alert banner renders correctly at different viewport sizes
  2. The banner's position doesn't interfere with the skip-to-main-content functionality
  3. The styling is consistent with the organization's theme properties

Let's verify the component's type safety:

✅ Verification successful

Based on the search results, I can verify the alert banner implementation. The code shows:

  1. The StandaloneAlertBanner component is properly typed with OrganizationPage['alertBanner']
  2. The component handles null/undefined cases and banner visibility based on cookies
  3. The banner is positioned correctly in the layout hierarchy, before the navigation and main content
  4. The component properly inherits styling and variants from the core AlertBanner component
  5. The skip-to-main-content functionality is preserved as the banner is placed before the main content element with id="main-content"

Alert banner implementation is correct and follows accessibility best practices.

  • The banner is properly positioned in the DOM order
  • Skip-to-main-content link remains functional
  • Alert banner state handling and styling are type-safe
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the AlertBanner component's type definitions and usage

# Check if the alertBanner prop is properly typed in the OrganizationPage interface
ast-grep --pattern 'interface OrganizationPage {
  $$$
  alertBanner$_
  $$$
}'

# Verify that StandaloneAlertBanner is exported with proper type definitions
ast-grep --pattern 'export $_StandaloneAlertBanner$_: $_'

Length of output: 141


Script:

#!/bin/bash
# Let's try a different approach to verify the component and its types

# Find the StandaloneAlertBanner component definition
rg -A 5 "StandaloneAlertBanner" --type typescript

# Find the OrganizationPage type/interface
rg -A 5 "OrganizationPage.*{" --type typescript

# Look for any alert banner related types
rg -A 3 "AlertBanner" --type typescript

Length of output: 311


Script:

#!/bin/bash
# Let's try without type filtering since typescript isn't recognized

# Find the StandaloneAlertBanner component definition
rg -A 5 "StandaloneAlertBanner"

# Find the OrganizationPage interface
rg -A 5 "interface OrganizationPage"

# Look for any alert banner related types
rg -A 3 "AlertBanner"

# Find the component file using fd
fd "standalone.tsx"

Length of output: 101108

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

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

Project coverage is 35.52%. Comparing base (fe303df) to head (a46c8df).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...organization/standalone/components/AlertBanner.tsx 0.00% 19 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17031      +/-   ##
==========================================
- Coverage   35.61%   35.52%   -0.10%     
==========================================
  Files        6933     6932       -1     
  Lines      146837   146544     -293     
  Branches    41745    41661      -84     
==========================================
- Hits        52297    52058     -239     
+ Misses      94540    94486      -54     
Flag Coverage Δ
web 1.73% <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% <ø> (ø)
...organization/standalone/components/AlertBanner.tsx 0.00% <0.00%> (ø)

... and 31 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 fe303df...a46c8df. Read the comment docs.

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