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: Add search parameters to inbox message link #1366

Conversation

mbacherycz
Copy link
Contributor

@mbacherycz mbacherycz commented Nov 13, 2024

Hva er endret?

Dokumentasjon / Storybook / testdekning

  • Dokumentasjon er oppdatert eller ikke relevant / nødvendig.
  • Ny komponent har en eller flere stories i Storybook, eller så er ikke dette relevant.
  • Det er blitt lagt til nye tester / eksiterende tester er blitt utvidet, eller tester er ikke relevant.

Skjermbilder eller GIFs (valgfritt)

Summary by CodeRabbit

  • New Features

    • Enhanced link handling in the InboxItem component to include current URL search parameters.
    • Improved hover effect consistency based on the updated link logic.
    • Refined dialog management with dynamic URL construction for inbox items.
  • Bug Fixes

    • Ensured that links generated in the InboxItem component correctly reflect any query parameters present in the current URL.
    • Improved error handling for saved searches in the Inbox component.

@mbacherycz mbacherycz requested a review from a team as a code owner November 13, 2024 15:12
Copy link

coderabbitai bot commented Nov 13, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

The pull request introduces changes to the InboxItem component in InboxItem.tsx, primarily by reorganizing import statements and refining how the linkTo prop is handled based on the inSelectionMode state. The useDialogs.tsx file is updated to include a new linkTo property in the mapDialogDtoToInboxItem function, enhancing dialog representation. Additionally, the SearchDropdown.tsx component now utilizes the useLocation hook to dynamically construct links with search parameters. The Inbox.tsx component also reflects these changes by updating the linkTo property to include relevant query parameters.

Changes

File Path Change Summary
packages/frontend/src/components/InboxItem/InboxItem.tsx - Reorganized import statements.
- Updated linkTo prop to conditionally pass based on inSelectionMode.
- Modified onClick handler for isMinimalistic check.
packages/frontend/src/api/useDialogs.tsx - Updated mapDialogDtoToInboxItem to include linkTo property.
- Adjusted useDialogs hook for dialog retrieval.
packages/frontend/src/components/Header/SearchDropdown.tsx - Added useLocation hook.
- Updated linkTo property to include current search parameters.
packages/frontend/src/pages/Inbox/Inbox.tsx - Altered linkTo property in InboxItemInput to include dynamic URL with search parameters.
- Improved error handling in handleSaveSearch function.

Possibly related PRs

Suggested reviewers

  • seanes

Warning

Rate limit exceeded

@mbacherycz has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ecdd08c and 698572b.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ecdd08c and 698572b.

📒 Files selected for processing (4)
  • packages/frontend/src/api/useDialogs.tsx (0 hunks)
  • packages/frontend/src/components/Header/SearchDropdown.tsx (3 hunks)
  • packages/frontend/src/components/InboxItem/InboxItem.tsx (1 hunks)
  • packages/frontend/src/pages/Inbox/Inbox.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/frontend/src/api/useDialogs.tsx
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/frontend/src/components/Header/SearchDropdown.tsx
  • packages/frontend/src/components/InboxItem/InboxItem.tsx
  • packages/frontend/src/pages/Inbox/Inbox.tsx

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

@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: 1

🧹 Outside diff range and nitpick comments (1)
packages/frontend/src/components/InboxItem/InboxItem.tsx (1)

103-108: Add test coverage for URL parameter handling

Consider adding test cases to verify:

  1. URL parameter preservation across navigation
  2. Handling of undefined linkTo
  3. Handling of existing search parameters in linkTo

Would you like me to help generate test cases for these scenarios?

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 532f2df and a158a68.

📒 Files selected for processing (1)
  • packages/frontend/src/components/InboxItem/InboxItem.tsx (5 hunks)
🔇 Additional comments (4)
packages/frontend/src/components/InboxItem/InboxItem.tsx (4)

4-4: LGTM: Import statement correctly updated

The addition of useLocation hook from react-router-dom is appropriate for accessing URL search parameters.


103-103: LGTM: Proper hook usage

The useLocation hook is correctly implemented at the component level, following React hooks best practices.


133-133: LGTM: Consistent link handling across views

The linkToWithParams is consistently applied in both minimalistic and standard views, maintaining the existing selection mode logic.

Also applies to: 179-179


168-168: Verify hoverable states in all scenarios

The hoverable class now depends on linkToWithParams. Please verify that the UI states are correct in these scenarios:

  1. When linkTo is undefined
  2. When in selection mode
  3. When URL has no search parameters
✅ Verification successful

Hoverable state implementation is correct and well-handled

The code correctly handles all the scenarios:

  1. When linkTo is undefined, linkToWithParams will be undefined, and hoverable class won't be applied
  2. In selection mode, the link is disabled (!inSelectionMode ? linkToWithParams : undefined) and hoverable state won't apply
  3. When URL has search parameters, they are properly appended (${linkTo}${location.search})

The implementation also maintains clear separation between hoverable and pointer states:

  • [styles.hoverable] for link navigation
  • [styles.pointer] for selection mode interactions
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests covering hoverable states
rg -l "hoverable.*inboxItem" --type=test

Length of output: 71


Script:

#!/bin/bash
# Search for test files related to InboxItem
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts InboxItem

# Search for hoverable class usage in InboxItem tests and component
rg -A 5 "hoverable" packages/frontend/src/components/InboxItem/

Length of output: 1455


Script:

#!/bin/bash
# Search for linkTo and linkToWithParams usage in InboxItem
rg -A 5 "linkTo(WithParams)?" packages/frontend/src/components/InboxItem/InboxItem.tsx

# Search for selection mode related code
rg "inSelectionMode|isChecked" packages/frontend/src/components/InboxItem/InboxItem.tsx

Length of output: 2478

Comment on lines 107 to 108
const linkToWithParams = `${linkTo}${location.search}`;

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add URL parameter handling safety checks

The current implementation has potential issues:

  1. No validation for undefined linkTo
  2. No handling of existing search parameters in linkTo
  3. Could result in malformed URLs if linkTo already contains search parameters

Consider using URL utilities for safer parameter handling:

-  const linkToWithParams = `${linkTo}${location.search}`;
+  const linkToWithParams = linkTo
+    ? new URL(linkTo, window.location.href).search
+      ? linkTo // If linkTo already has search params, leave it unchanged
+      : `${linkTo}${location.search}`
+    : undefined;

Committable suggestion skipped: line range outside the PR's diff.


const hideSummaryAndMeta = !summary || viewType === 'archive' || viewType === 'bin';

const linkToWithParams = `${linkTo}${location.search}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could I do suggest a little improvement here?

InboxItem should probably be so dumb as possible, and rather, let this linkTo + location.searche be lifted to Inbox. What do you think of the following:

  1. remove the prop linkTo from InboxItemInput (both fra the interface and from the item-mapping in useDialogs.tsx.
  2. In Inbox.tsx where the items are mapped into InboxItem, build the linkTo prop with following pattern /inbox/${item.id}/${location.search}
  3. Do the same for InboxItem used in SearchDropdown

Copy link

@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)
packages/frontend/src/components/Header/SearchDropdown.tsx (1)

70-70: Consider centralizing URL construction logic

The codebase has multiple locations where URLs are constructed with search parameters (both in linkTo and queryParams construction). This could lead to inconsistencies in URL handling.

Consider creating a centralized utility for URL construction to ensure consistent handling of search parameters across the application.

Example approach:

// utils/urlBuilder.ts
export const buildUrl = {
  inbox: (id: string, searchParams: string) => `/inbox/${id}${searchParams}`,
  search: (params: Record<string, string>) => {
    const queryParams = new URLSearchParams(params);
    return `?${queryParams.toString()}`;
  }
};

Also applies to: 98-102

packages/frontend/src/pages/Inbox/Inbox.tsx (1)

378-378: Improve URL construction for inbox item links

The addition of search parameters to the inbox item link implements the PR objective correctly. However, the URL construction could be improved to handle edge cases.

Consider using URL utilities to handle the search parameters more robustly:

-                  linkTo={`/inbox/${item.id}/${location.search}`}
+                  linkTo={`/inbox/${item.id}${location.search ? location.search : ''}`}

This change:

  • Prevents trailing slash when there are no search parameters
  • Maintains the existing search parameters as intended
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a158a68 and ecdd08c.

📒 Files selected for processing (4)
  • packages/frontend/src/api/useDialogs.tsx (0 hunks)
  • packages/frontend/src/components/Header/SearchDropdown.tsx (3 hunks)
  • packages/frontend/src/components/InboxItem/InboxItem.tsx (1 hunks)
  • packages/frontend/src/pages/Inbox/Inbox.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/frontend/src/api/useDialogs.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/frontend/src/components/InboxItem/InboxItem.tsx
🔇 Additional comments (3)
packages/frontend/src/components/Header/SearchDropdown.tsx (3)

5-5: LGTM: Import addition is appropriate

The addition of useLocation hook is necessary for accessing URL search parameters and maintaining them during navigation.


34-34: LGTM: Hook usage follows best practices

The useLocation hook is correctly initialized at the component level and follows React hooks rules.


70-70: ⚠️ Potential issue

Fix URL construction to prevent invalid format

The current URL construction '/inbox/${item.id}/${location.search}' will result in an invalid URL format because:

  1. location.search already includes the ? prefix
  2. Adding a / before the search string creates an invalid URL structure (e.g., /inbox/123/?search=test becomes /inbox/123//search=test)

Apply this fix to ensure proper URL construction:

-                linkTo={`/inbox/${item.id}/${location.search}`}
+                linkTo={`/inbox/${item.id}${location.search}`}

Let's verify the search parameter handling in other components:

@seanes seanes self-requested a review November 14, 2024 12:07
@mbacherycz mbacherycz force-pushed the fix/context_colour_switches_to_person_when_opening_company_message branch from ecdd08c to 791ba26 Compare November 14, 2024 12:21
@mbacherycz mbacherycz force-pushed the fix/context_colour_switches_to_person_when_opening_company_message branch from 791ba26 to 698572b Compare November 14, 2024 12:21
@mbacherycz mbacherycz merged commit 4196f0f into main Nov 14, 2024
22 checks passed
@mbacherycz mbacherycz deleted the fix/context_colour_switches_to_person_when_opening_company_message branch November 14, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev developer task
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Åpning av melding for organisasjon gjør at party droppes
2 participants