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): Boost chat panel - use pushUp prop #17271

Merged
merged 4 commits into from
Dec 17, 2024

Conversation

RunarVestmann
Copy link
Member

@RunarVestmann RunarVestmann commented Dec 17, 2024

Boost chat panel - use pushUp prop

  • Push chat bubble up in case there is an application below it
  • Add translation text to the chat bubble so it doesn't always say "Hæ, get ég aðstoðað?" on all locales
  • Open chat if query params are present

Screenshots / Gifs

Before

Screenshot 2024-12-17 at 13 54 58

After

Screenshot 2024-12-17 at 13 55 15

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

Summary by CodeRabbit

  • New Features

    • Enhanced chat panel functionality with dynamic localization support.
    • Introduced a new query to fetch namespace data for improved text retrieval.
    • Updated ChatBubble component to display localized strings.
    • Added logic to control chat panel visibility based on URL query parameters.
  • Bug Fixes

    • Improved responsiveness of the chat panel to changes in endpoints and locales.

@RunarVestmann RunarVestmann added the automerge Merge this PR as soon as all checks pass label Dec 17, 2024
@RunarVestmann RunarVestmann requested a review from a team as a code owner December 17, 2024 13:55
Copy link
Contributor

coderabbitai bot commented Dec 17, 2024

Walkthrough

The BoostChatPanel.tsx component has been enhanced with GraphQL integration for namespace management and localization. The changes introduce a new GraphQL query to fetch namespace data, which is then processed and used to retrieve localized strings. The component now dynamically handles endpoint changes and supports localization through the useI18n and useNamespaceStrict hooks. The chat panel's visibility logic has been updated to consider both the window.boost property and a URL query parameter.

Changes

File Change Summary
apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx - Added GraphQL GET_NAMESPACE_QUERY for fetching namespace data
- Implemented useQuery to retrieve namespace information
- Added useMemo to parse namespace fields
- Integrated useNamespaceStrict hook for localized strings
- Updated useEffect to include endpoint as a dependency
- Modified chat bubble text to use localized strings

Sequence Diagram

sequenceDiagram
    participant Component as BoostChatPanel
    participant GraphQL as GraphQL Server
    participant I18n as Localization Service

    Component->>GraphQL: Query namespace data
    GraphQL-->>Component: Return namespace fields
    Component->>Component: Parse namespace fields
    Component->>I18n: Retrieve localized strings
    I18n-->>Component: Return localized text
    Component->>Component: Render chat panel
Loading

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9891a9b and 67ccf96.

📒 Files selected for processing (1)
  • apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.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."

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Dec 17, 2024

Codecov Report

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

Project coverage is 35.71%. Comparing base (9891a9b) to head (67ccf96).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...onents/ChatPanel/BoostChatPanel/BoostChatPanel.tsx 0.00% 8 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17271      +/-   ##
==========================================
- Coverage   35.72%   35.71%   -0.01%     
==========================================
  Files        6944     6944              
  Lines      148493   148501       +8     
  Branches    42381    42383       +2     
==========================================
  Hits        53043    53043              
- Misses      95450    95458       +8     
Flag Coverage Δ
air-discount-scheme-web 0.00% <ø> (ø)
api 3.33% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-communications 39.42% <ø> (ø)
application-api-files 61.87% <ø> (ø)
application-core 75.78% <ø> (ø)
application-system-api 38.74% <ø> (-0.01%) ⬇️
application-template-api-modules 27.81% <ø> (-0.01%) ⬇️
application-templates-accident-notification 28.82% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.77% <ø> (ø)
application-templates-driving-license 18.16% <ø> (ø)
application-templates-estate 13.69% <ø> (ø)
application-templates-example-payment 24.72% <ø> (ø)
application-templates-financial-aid 14.46% <ø> (ø)
application-templates-general-petition 23.15% <ø> (ø)
application-templates-inheritance-report 6.59% <ø> (ø)
application-templates-marriage-conditions 15.19% <ø> (ø)
application-templates-mortgage-certificate 43.64% <ø> (ø)
application-templates-parental-leave 29.94% <ø> (ø)
application-types 6.51% <ø> (ø)
application-ui-components 1.22% <ø> (ø)
application-ui-shell 22.32% <ø> (ø)
clients-charge-fjs-v2 28.35% <ø> (ø)
cms 0.39% <ø> (ø)
cms-translations 38.75% <ø> (ø)
contentful-apps 4.72% <ø> (ø)
financial-aid-backend 51.40% <ø> (ø)
financial-aid-shared 17.88% <ø> (ø)
island-ui-core 30.40% <ø> (ø)
judicial-system-api 20.21% <ø> (ø)
judicial-system-backend 55.91% <ø> (ø)
judicial-system-web 27.77% <ø> (ø)
portals-admin-regulations-admin 1.80% <ø> (ø)
portals-core 19.61% <ø> (ø)
services-user-notification 46.54% <ø> (ø)
shared-components 29.64% <ø> (ø)
shared-form-fields 33.30% <ø> (ø)
web 2.41% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
...onents/ChatPanel/BoostChatPanel/BoostChatPanel.tsx 0.00% <0.00%> (ø)

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 9891a9b...67ccf96. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 17, 2024

Datadog Report

All test runs a87b4e4 🔗

11 Total Test Services: 0 Failed, 10 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.01%), 27 no change

Test Services
This report shows up to 10 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.16s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.03s 1 no change Link
api-domains-communications 0 0 0 5 0 34.25s 1 no change Link
api-domains-license-service 0 0 0 0 0 521.43ms 1 no change Link
application-system-api 0 0 0 46 0 2m 21.65s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 50.94s 1 increased (+0.01%) Link
cms-translations 0 0 0 3 0 30.3s 1 no change Link
judicial-system-api 0 0 0 61 0 6.99s 1 no change Link
judicial-system-backend 0 0 0 20726 0 0s N/A Link
services-user-notification 0 0 0 51 0 1m 36.86s 1 no change Link

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

🧹 Nitpick comments (1)
apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx (1)

79-93: Optimize data fetching for server-side rendering

Since this component is part of a Next.js application, consider leveraging Next.js data fetching methods like getStaticProps or getServerSideProps to fetch the namespace data. This can improve performance and SEO by pre-rendering the localized content.

Example using getStaticProps:

// In the page component that uses BoostChatPanel
export const getStaticProps: GetStaticProps = async ({ locale }) => {
  const apolloClient = initializeApollo()

  const { data } = await apolloClient.query<Query, QueryGetNamespaceArgs>({
    query: GET_NAMESPACE_QUERY,
    variables: {
      input: {
        lang: locale ?? 'is',
        namespace: 'ChatPanels',
      },
    },
  })

  return {
    props: {
      namespace: JSON.parse(data.getNamespace.fields ?? '{}'),
    },
    revalidate: 60, // Revalidate at most once per minute
  }
}

Then, pass the namespace prop to the component and remove the client-side useQuery:

- const { data, loading, error } = useQuery<Query, QueryGetNamespaceArgs>(GET_NAMESPACE_QUERY, { ... })
- const namespace = useMemo(() => { ... }, [data?.getNamespace?.fields])
+ const namespace = props.namespace

This adheres to Next.js best practices for data fetching and improves the application's performance.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c07421f and dc7463a.

📒 Files selected for processing (1)
  • apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.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 (6)
apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx (6)

26-26: Proper initialization of locale using useI18n

The use of const { activeLocale } = useI18n() correctly initializes the active locale for internationalization purposes.


77-77: Update dependency array in useEffect

Including endpoint in the dependency array of the useEffect hook ensures that the effect runs whenever the endpoint value changes, which is appropriate for re-initializing the chat panel with the new endpoint.


93-93: Confirm the usage of useNamespaceStrict

The useNamespaceStrict hook is appropriately used to handle namespace translations, ensuring that localized strings are correctly retrieved.


97-100: Pass pushUp prop to ChatBubble correctly

The pushUp prop is properly passed to the ChatBubble component, aligning with the PR objective to enhance chat panel functionality using the pushUp property.


1-7: Ensure all imported modules are necessary and correctly used

Review the added import statements to confirm that all imported modules (useQuery, Query, QueryGetNamespaceArgs, useNamespaceStrict, useI18n, GET_NAMESPACE_QUERY) are required and utilized appropriately within the component. Unused imports can lead to increased bundle size and potential confusion.

To verify the usage of imported modules, please run the following script:

✅ Verification successful

Based on the search results, I can generate the final response as we have clear evidence of the usage of all imported modules within the component:

All imported modules are correctly utilized in the component

The verification shows that each imported module is being used appropriately:

  • useQuery is used for executing the GraphQL query
  • Query and QueryGetNamespaceArgs are used as type parameters in the query execution
  • useNamespaceStrict is used to access namespace data
  • useI18n is used to get the active locale
  • GET_NAMESPACE_QUERY is used as the query parameter in useQuery hook
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if all imported modules are used in BoostChatPanel.tsx

# List all imports
echo "Imported modules:"
rg -o '@[a-zA-Z\/\-]+' apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx

# Search for usage of each imported module
echo "Usage of imported modules:"
rg 'useQuery|Query|QueryGetNamespaceArgs|useNamespaceStrict|useI18n|GET_NAMESPACE_QUERY' apps/web/components/ChatPanel/BoostChatPanel/BoostChatPanel.tsx

Length of output: 892


97-100: Verify default text and localization key

Ensure that the default text 'Hæ, get ég aðstoðað?' and the localization key 'chatBubbleText' are correctly defined in the namespace and appropriate for all supported locales.

Run the following script to verify that the key exists in the localization files:

If the key is missing in any locale, consider adding it to ensure consistency across languages.

@kodiakhq kodiakhq bot merged commit 2213255 into main Dec 17, 2024
141 checks passed
@kodiakhq kodiakhq bot deleted the fix/web-boost-chat-panel-push-up branch December 17, 2024 20:56
kodiakhq bot pushed a commit that referenced this pull request Dec 18, 2024
* Push chat panel up

* Add translation to text in chat bubble

* Open chat if query params are present
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