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: AddressDrawer rework #1326

Merged
merged 24 commits into from
Jul 17, 2024
Merged

fix: AddressDrawer rework #1326

merged 24 commits into from
Jul 17, 2024

Conversation

JoeKarow
Copy link
Member

@JoeKarow JoeKarow commented Jul 15, 2024

Pull Request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no API changes)
  • Build-related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features
    • Enhanced address formatting by including organization locations in API responses.
  • Bug Fixes
    • Corrected cache-control header case for improved client-side caching.
    • Fixed port selection logic in getBaseUrl to ensure correct environment configuration.
  • Refactor
    • Updated useScreenSize to use useMemo for efficiency.
  • Chores
    • Added "certificates" entry to .gitignore file.
    • Updated scripts in package.json to include --no-hints flag and format enums.

Copy link

vercel bot commented Jul 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
inreach-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 17, 2024 5:01pm

Copy link
Contributor

coderabbitai bot commented Jul 15, 2024

Walkthrough

This update includes a variety of changes across multiple files, primarily focusing on header consistency, locale handling, caching mechanisms, and numerous refinements to address visibility and data fetching logic. It introduces improvements in API request handling, state management within React components, and database schema flexibility. These enhancements collectively aim to streamline data processing, improve localization, and ensure proper handling of user interface states and backend data interactions.

Changes

Files/Group Change Summary
apps/app/.gitignore Added entry for "certificates".
apps/app/src/pages/api/trpc/[trpc].ts Modified Cache-Control header key to lowercase.
apps/app/src/pages/org/[slug]/edit.tsx Updated getServerSideProps to include organizationId in translations.
apps/app/src/pages/_app.tsx Moved <SpeedInsights /> outside of <Providers>.
apps/app/src/providers/index.tsx Introduced mantineCache using useMemo.
packages/api/lib/context.ts Added locale assignment in createContextInner.
packages/api/router/geo/query.cityCoords.handler.ts Included region parameter in Places API request.
packages/api/router/location/query.forVisitCard.handler.ts Removed addressVisibility filter condition.
packages/api/router/location/query.forVisitCardEdits.handler.ts (2 changes) Imported formatAddressVisibility and added logic for formatting address visibility before processing.
packages/api/router/orgSocialMedia/mutation.upsert.handler.ts Conditional id assignment based on isCreate, refined username logic.
packages/api/router/orgWebsite/mutation.upsert.handler.ts Adjusted id generation logic based on isCreate.
packages/api/router/location/mutation.create.handler.ts Added orgId to input, restructured addressData, connected orgId to organization field.
packages/api/router/location/mutation.create.schema.ts Changed street2 and postCode fields to nullish.
packages/api/trpc/client.ts, packages/ui/lib/trpcClient.ts Corrected port selection logic in getBaseUrl function.
packages/auth/lib/userLogin.ts Included ClientId twice in AuthParameters.
packages/crowdin/cache/index.ts Calculated cacheArraySize for consistent logging.
packages/db/package.json Updated db:generate script and added format:enums script.
packages/eslint-config/base.js Updated ecmaVersion to 2020, set sourceType to 'module'.
packages/ui/components/core/LangPicker.tsx Added setCookie logic for NEXT_LOCALE, replaced useCallback with useEffect.
packages/ui/components/data-portal/AddressAutocomplete/index.tsx Extensive refactoring for state management, form values, and hooks.
packages/ui/components/data-portal/AddressDrawer/index.tsx Refactored state management, updated form values, modified functions for handling autocomplete and geocoding.
packages/ui/components/data-portal/SocialMediaDrawer/index.tsx Removed specific logging statements.
packages/ui/components/data-portal/WebsiteDrawer/index.tsx Removed specific logging statements.
packages/ui/components/sections/LocationCard.tsx Removed a console.log statement.
packages/ui/hooks/useFormattedAddress.ts Added useAddressFormatter function using useCallback.
packages/ui/hooks/useScreenSize.ts Refactored useScreenSize hook to use useMemo.
packages/api/router/organization/query.forOrgPageEdits.handler.ts Imported formatAddressVisibility and formatted address visibility for locations.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@github-actions github-actions bot added 📦 ui 📦 api 📦 db automerge Enable Kodiak auto-merge kodiak: merge.method = 'squash' Kodiak will squash merge this PR. labels Jul 15, 2024
@JoeKarow JoeKarow added the bugfix Inconsistencies or issues which will cause a problem for users or implementors. label Jul 15, 2024
Signed-off-by: InReach [bot] <108850934+InReach-svc@users.noreply.github.com>
Copy link

relativeci bot commented Jul 15, 2024

#925 Bundle Size — 3.52MiB (+1.93%).

5c15c04(current) vs 3709dcc dev#912(baseline)

Warning

Bundle contains 8 duplicate packages – View duplicate packages

Bundle metrics  Change 7 changes Regression 2 regressions
                 Current
#925
     Baseline
#912
Regression  Initial JS 3.09MiB(+0.97%) 3.06MiB
No change  Initial CSS 9.54KiB 9.54KiB
Change  Cache Invalidation 47.55% 68.04%
Change  Chunks 64(-3.03%) 66
Change  Assets 77(-2.53%) 79
Change  Modules 2086(+4.04%) 2005
Regression  Duplicate Modules 339(+30.89%) 259
Change  Duplicate Code 9.12%(+24.08%) 7.35%
No change  Packages 213 213
No change  Duplicate Packages 8 8
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#925
     Baseline
#912
Regression  JS 3.4MiB (+2.01%) 3.33MiB
No change  Fonts 94.54KiB 94.54KiB
No change  CSS 9.54KiB 9.54KiB
Improvement  Other 9.09KiB (-5.32%) 9.6KiB
No change  IMG 8.57KiB 8.57KiB

Bundle analysis reportBranch JoeKarow/address-drawer-fixesProject dashboard

Copy link
Contributor

github-actions bot commented Jul 15, 2024

📦 Next.js Bundle Analysis for @weareinreach/app

This analysis was generated by the Next.js Bundle Analysis action. 🤖

⚠️ Global Bundle Size Increased

Page Size (compressed)
global 413.33 KB (🟡 +1.58 KB)
Details

The global bundle is the javascript bundle that loads alongside every page. It is in its own category because its impact is much higher - an increase to its size means that every page on your website loads slower, and a decrease means every page loads faster.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

If you want further insight into what is behind the changes, give @next/bundle-analyzer a try!

Ten Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (575 KB)
/ 280.22 KB 693.55 KB 120.62% (🟢 -0.41%)
/org/[slug] 321.57 KB 734.9 KB 127.81% (🟢 -0.48%)
/org/[slug]/[orgLocationId] 319.14 KB 732.47 KB 127.39% (🟢 -0.40%)
/org/[slug]/[orgLocationId]/edit 320.37 KB 733.7 KB 127.60% (🟢 -0.40%)
/org/[slug]/edit 298.64 KB 711.97 KB 123.82% (🟡 +3.47%)
/org/[slug]/remote 278.89 KB 692.23 KB 120.39% (🟢 -0.40%)
/search/[...params] 272.36 KB 685.69 KB 119.25% (🟢 -0.40%)
/search/intl/[country] 271 KB 684.33 KB 119.01% (🟢 -0.40%)
/suggest 271.06 KB 684.39 KB 119.02% (🟢 -0.40%)
/support 16.53 KB 429.86 KB 74.76% (🟢 -0.39%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

Copy link

alwaysmeticulous bot commented Jul 15, 2024

🤖 No test run has been triggered as your Meticulous project has been deactivated (since you haven't viewed any test results in a while). Click here to reactivate.

Last updated for commit 5c15c04. This comment will update as new commits are pushed.

@JoeKarow
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jul 16, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Outside diff range, codebase verification and nitpick comments (3)
packages/api/router/location/query.forVisitCard.handler.ts (1)

Potential Issue with Removal of addressVisibility Filter Condition

The removal of the addressVisibility filter condition in the forVisitCard function could affect data privacy and visibility controls. The addressVisibility field is still being selected in the query, but without the filter, it may expose data that should be restricted.

Affected Files:

  • packages/api/router/location/query.forVisitCard.handler.ts
  • packages/api/router/location/query.forVisitCardEdits.handler.ts
  • packages/api/router/location/query.getAddress.handler.ts
  • packages/api/router/location/query.forLocationPage.handler.ts
  • packages/api/router/location/query.forGoogleMaps.handler.ts
  • packages/api/router/location/query.forLocationPageEdits.handler.ts
  • packages/api/router/location/query.forLocationCard.handler.ts
  • packages/api/router/location/mutation.update.schema.ts
  • packages/api/router/location/mutation.create.schema.ts
  • packages/api/router/location/lib.formatAddressVisibility.ts

Recommendation:

Please review the removal of the addressVisibility filter condition to ensure it aligns with the intended functionality and compliance requirements for data privacy and visibility.

Analysis chain

Line range hint 1-36: Removal of addressVisibility filter condition.

The AI-generated summary mentions the removal of the addressVisibility filter condition, specifically the constraint addressVisibility: { in: ['FULL'] }. However, the provided code snippet still shows addressVisibility: true in the select clause, indicating that it is still being fetched but not filtered. This change could potentially affect data privacy or visibility controls, so it's important to ensure that this change aligns with the intended functionality and compliance requirements.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of removing the `addressVisibility` filter on data privacy and visibility controls.

# Test: Search for usage of the `forVisitCard` function to see if the removal of the filter affects other parts of the application.
rg --type ts -A 5 -B 5 $'forVisitCard' packages/api/router/location/

Length of output: 6897


Script:

#!/bin/bash
# Description: Verify the impact of the removal of the `addressVisibility` filter condition by searching for its usage in the codebase.

# Test: Search for the `addressVisibility` filter condition in the codebase to see if it is used elsewhere or if there are any related conditions.
rg --type ts -A 5 -B 5 $'addressVisibility' packages/api/router/location/

Length of output: 10341

apps/app/src/pages/org/[slug]/edit.tsx (1)

172-175: Ensure organizationId is defined before using it in compact function

The getIdFromSlug function uses findUniqueOrThrow, which can throw an error if the organization is not found. This implies that organizationId could be undefined, leading to potential runtime errors. Add error handling to ensure organizationId is defined before passing it to the compact function in getServerSideTranslations.

  • apps/app/src/pages/org/[slug]/edit.tsx: Ensure organizationId is defined before using it in compact function.
Analysis chain

Review of addition of organizationId to compact function call.

The addition of organizationId to the compact function call in getServerSideTranslations is intended to enhance localization by fetching more specific data. Ensure that organizationId is always defined and non-null when passed to this function to avoid potential runtime errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that organizationId is always defined when passed to getServerSideTranslations.

# Test: Search for any potential null checks or undefined conditions for organizationId.
rg --type python -A 5 $'organizationId'

Length of output: 69


Script:

#!/bin/bash
# Description: Verify that organizationId is always defined when passed to getServerSideTranslations.

# Test: Search for any potential null checks or undefined conditions for organizationId in TypeScript files.
rg --type ts -A 5 'organizationId'

Length of output: 86763


Script:

#!/bin/bash
# Description: Verify the implementation of `ssg.organization.getIdFromSlug.fetch` to ensure it always returns a valid `organizationId`.

# Test: Search for the implementation of `getIdFromSlug` in the codebase.
rg 'getIdFromSlug' -A 10

Length of output: 38629


Script:

#!/bin/bash
# Description: Verify the implementation of `getIdFromSlug` to ensure it always returns a valid `organizationId`.

# Test: Extract the implementation of `getIdFromSlug` from the handler file.
rg 'const getIdFromSlug' -A 20 packages/api/router/organization/query.getIdFromSlug.handler.ts

Length of output: 788

packages/ui/components/data-portal/AddressDrawer/hookform.tsx (1)

41-41: Clarify the TODO comment.

The TODO comment is vague and does not specify what needs to be checked or improved.

Please clarify or expand this TODO to specify what exactly needs to be verified or refined.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3709dcc and e7bcd0b.

Files selected for processing (22)
  • apps/app/.gitignore (1 hunks)
  • apps/app/src/pages/api/trpc/[trpc].ts (1 hunks)
  • apps/app/src/pages/org/[slug]/edit.tsx (1 hunks)
  • packages/api/lib/context.ts (1 hunks)
  • packages/api/router/geo/query.cityCoords.handler.ts (1 hunks)
  • packages/api/router/location/query.forVisitCard.handler.ts (1 hunks)
  • packages/api/router/location/query.forVisitCardEdits.handler.ts (2 hunks)
  • packages/api/router/orgSocialMedia/mutation.upsert.handler.ts (1 hunks)
  • packages/api/router/orgWebsite/mutation.upsert.handler.ts (1 hunks)
  • packages/api/trpc/client.ts (1 hunks)
  • packages/auth/lib/userLogin.ts (1 hunks)
  • packages/crowdin/cache/index.ts (1 hunks)
  • packages/db/package.json (2 hunks)
  • packages/eslint-config/base.js (1 hunks)
  • packages/ui/components/core/LangPicker.tsx (3 hunks)
  • packages/ui/components/data-portal/AddressAutocomplete/index.tsx (6 hunks)
  • packages/ui/components/data-portal/AddressDrawer/hookform.tsx (1 hunks)
  • packages/ui/components/data-portal/AddressDrawer/index.tsx (14 hunks)
  • packages/ui/components/data-portal/LocationDrawer/index.tsx (4 hunks)
  • packages/ui/components/data-portal/WebsiteDrawer/index.tsx (1 hunks)
  • packages/ui/hooks/useFormattedAddress.ts (2 hunks)
  • packages/ui/lib/trpcClient.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • apps/app/.gitignore
Additional comments not posted (26)
packages/ui/lib/trpcClient.ts (1)

24-24: Corrected conditional logic in port selection.

The modification to add parentheses ensures that the ternary operator evaluates the entire condition before deciding which port number to use. This is a crucial fix for ensuring that the application connects to the correct port in different environments.

packages/api/trpc/client.ts (1)

21-21: Corrected conditional logic in port selection.

Identical to the change in trpcClient.ts, this modification corrects the evaluation order of the conditional expression, ensuring the application uses the correct port in various environments.

apps/app/src/pages/api/trpc/[trpc].ts (1)

62-62: Standardized HTTP header key casing.

Changing the Cache-Control header to lowercase ('cache-control') aligns with the common practice of using lowercase HTTP header keys, which can help avoid discrepancies in how headers are processed by different systems.

packages/api/router/orgSocialMedia/mutation.upsert.handler.ts (1)

30-30: Improved handling of id and username in upsert function.

The changes ensure that the id is appropriately set based on whether the operation is a creation or an update. Additionally, the logic to derive username from url when not explicitly provided helps maintain data integrity and consistency.

packages/api/router/geo/query.cityCoords.handler.ts (1)

48-48: Added region parameter to Places API request.

The addition of the region parameter set to searchCountry seems appropriate for the intended functionality of filtering results based on the country. This should help in narrowing down the search results to the specified region, which is a common practice when dealing with geocoding services.

packages/ui/hooks/useFormattedAddress.ts (2)

4-4: Import of useCallback.

The import of useCallback from React is appropriate here, as it is used in the new useAddressFormatter function to memoize the address formatting function. This is a good practice to avoid unnecessary re-renders and ensure performance optimization.


62-87: New useAddressFormatter function.

The useAddressFormatter function is well-implemented, using useCallback to memoize the formatting function, which takes an optional location parameter. The function uses the formatAddress utility and handles null cases appropriately. This should provide a robust way to format addresses based on the provided location data.

packages/ui/components/core/LangPicker.tsx (2)

2-5: Import changes and hook usage.

The addition of hasCookie and setCookie from 'cookies-next' and the inclusion of useEffect in the imports from 'react' are appropriate for the new functionality related to cookie management. The switch from useCallback to useEffect for handling the 'NEXT_LOCALE' cookie is a good use of React's lifecycle hooks to manage side effects.


78-83: New useEffect hook for 'NEXT_LOCALE' cookie management.

The new useEffect hook correctly checks for the existence of the 'NEXT_LOCALE' cookie and sets it if not present. This ensures that the user's language preference is preserved across sessions, which is a crucial aspect of user experience in multi-language applications.

packages/api/router/orgWebsite/mutation.upsert.handler.ts (1)

25-25: Change in id assignment logic in upsert function.

The modification to assign the id based on the isCreate condition is a sensible change, ensuring that a new id is generated only when creating a new entry. This prevents unintended overwrites and maintains data integrity.

packages/db/package.json (2)

15-15: Review of the updated db:generate script

The addition of the --no-hints flag to the db:generate script is a good practice if the intention is to streamline the output of the generation process. Ensure that the tools used in the script support this flag.


29-29: Introduction of the format:enums script

Adding a dedicated formatting script for the enums directory is a good practice to maintain code consistency. Ensure that the prettier configuration supports the file types found in the enums directory.

packages/ui/components/data-portal/LocationDrawer/index.tsx (3)

9-9: Proper import of AddressVisibility enum

The import of the AddressVisibility enum from @weareinreach/db/enums is correctly done. This ensures that the enum values are consistent across different parts of the application.


18-22: Setup of addressVisibilityOptions

The setup of addressVisibilityOptions using the AddressVisibility enum is correctly implemented. This provides a clear and manageable way to handle form options related to address visibility.


34-36: Update to form default values

Setting the default value of addressVisibility to AddressVisibility.FULL in the form is a sensible default, ensuring that there is a defined initial state. This is a good practice to avoid potential issues with undefined or unexpected values.

packages/eslint-config/base.js (1)

127-127: Update to parserOptions in ESLint configuration

Setting the ecmaVersion to 2020 and sourceType to module in the parserOptions is a crucial update for supporting modern JavaScript features and module syntax. This ensures that the linter can accurately analyze the code.

packages/crowdin/cache/index.ts (1)

82-85: Enhancements to cache size tracking

Calculating the cacheArraySize and using it in logging and event tracking enhances the consistency and reliability of cache-related metrics. This is a good practice for better monitoring and debugging of caching operations.

packages/ui/components/data-portal/WebsiteDrawer/index.tsx (1)

Line range hint 133-133: Approval of removal of console.log statement.

Removing the console.log statement is a good practice as it cleans up the code and avoids exposing potentially sensitive information in the production environment.

packages/ui/components/data-portal/AddressAutocomplete/index.tsx (1)

Line range hint 82-298: Comprehensive review of changes in AddressAutocomplete component.

The modifications in the AddressAutocomplete component include the addition of new hooks (usePrevious, useMemo), imports, and significant refactoring of state management and functions. These changes aim to enhance performance and maintainability. It is important to ensure that all new hooks are used appropriately and that the refactored functions maintain the component's functionality without introducing bugs.

Verification successful

Hooks usage verified

The usePrevious and useMemo hooks are used correctly within the AddressAutocomplete component. The usePrevious hook is used to store the previous value of addressVisibility, and the useMemo hook is used to memoize the govDistOptions based on countryOptions and formValues.address?.countryId. These usages follow standard practices and do not introduce any issues.

  • usePrevious: Verified at lines around usePrevious(addressVisibility).
  • useMemo: Verified at lines around useMemo(() => { ... }, [countryOptions, formValues.address?.countryId]).
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct usage of new hooks and the impact of refactored functions on the component's functionality.

# Test: Search for any potential issues with the new hooks usage.
rg --type python -A 5 $'usePrevious|useMemo'

Length of output: 76


Script:

#!/bin/bash
# Description: Verify the correct usage of new hooks and the impact of refactored functions on the component's functionality.

# Test: Search for any potential issues with the new hooks usage.
rg --type typescript -A 5 'usePrevious|useMemo'

Length of output: 84


Script:

#!/bin/bash
# Description: Verify the correct usage of new hooks and the impact of refactored functions on the component's functionality.

# Test: Search for any potential issues with the new hooks usage.
rg --type js -A 5 'usePrevious|useMemo'

Length of output: 41


Script:

#!/bin/bash
# Description: Verify the correct usage of new hooks within the AddressAutocomplete component.

# Test: Search for the usage of usePrevious and useMemo hooks within the AddressAutocomplete/index.tsx file.
rg 'usePrevious|useMemo' packages/ui/components/data-portal/AddressAutocomplete/index.tsx

Length of output: 339


Script:

#!/bin/bash
# Description: Extract lines of code around the usage of usePrevious and useMemo hooks for detailed review.

# Extract lines around the usage of usePrevious hook.
rg 'usePrevious' -A 5 -B 5 packages/ui/components/data-portal/AddressAutocomplete/index.tsx

# Extract lines around the usage of useMemo hook.
rg 'useMemo' -A 5 -B 5 packages/ui/components/data-portal/AddressAutocomplete/index.tsx

Length of output: 1595

packages/ui/components/data-portal/AddressDrawer/index.tsx (1)

Line range hint 46-481: Detailed review of modifications in AddressDrawer component.

The AddressDrawer component has undergone significant modifications, including the addition of new hooks (usePrevious, useMemo), changes in state management, and updates to form handling. These changes are intended to improve the functionality and user experience of the component. Careful review is necessary to ensure that these modifications are correctly implemented and do not introduce any new issues.

Verification successful

Verification successful for the implementation of new hooks and form handling changes.

The useForm, usePrevious, and useMemo hooks are correctly implemented and integrated within the AddressDrawer component. The form handling changes also appear to be correctly applied.

  • The hooks are used appropriately for managing state, memoizing values, and handling side effects.
  • Form validation and state updates are handled correctly using useForm.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct implementation of new hooks and the impact of changes on the component's functionality.

# Test: Search for any potential issues with the new hooks usage and form handling changes.
rg --type python -A 5 $'usePrevious|useMemo|form'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify the correct implementation of new hooks and the impact of changes on the component's functionality.

# Test: Search for any potential issues with the new hooks usage and form handling changes.
rg --type typescript -A 5 'usePrevious|useMemo|form'

Length of output: 89


Script:

#!/bin/bash
# Description: Verify the correct implementation of new hooks and the impact of changes on the component's functionality.

# Test: Search for any potential issues with the new hooks usage and form handling changes.
rg --type js -A 5 'usePrevious|useMemo|form'

Length of output: 777


Script:

#!/bin/bash
# Description: Verify the correct implementation of new hooks and the impact of changes on the component's functionality.

# Test: Search for any potential issues with the new hooks usage and form handling changes in the specific file.
rg 'usePrevious|useMemo|form' packages/ui/components/data-portal/AddressDrawer/index.tsx -A 5

Length of output: 9668

packages/ui/components/data-portal/AddressDrawer/hookform.tsx (4)

112-120: Conditional fetching based on organizationId.

The conditional fetching based on organizationId is a good use of React Query's enabled option.

This prevents unnecessary API calls when organizationId is not available, optimizing performance and resource usage.


146-151: Form initialization with dynamic default values.

The form is initialized with dynamic data which is a good practice in dynamic forms handling.

However, the commented-out transformValues might be necessary for proper data handling. If it's not used, ensure that its absence doesn't affect the form's functionality.


51-54: Use of custom notification hooks.

The custom notification hooks usage is clear and seems to be well-implemented.

However, ensure that these notifications are appropriately triggered in the UI to avoid confusion or spamming the user.

Verification successful

Notifications are appropriately triggered.

The notifications using useCoordNotification are triggered in specific scenarios related to setting coordinates, ensuring they inform the user of significant updates without spamming.

  • index.tsx and hookform.tsx:
    • Notifications are triggered when a place ID is set or the coordinate modal is opened.
    • Notifications are triggered when coordinates are set to the city center.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the triggering conditions for notifications to ensure they are not overly verbose or missing.

# Test: Search for usage of `useCoordNotification` and its context in the file.
rg --type typescript -A 5 -B 5 $'useCoordNotification'

Length of output: 88


Script:

#!/bin/bash
# Description: Verify the triggering conditions for notifications to ensure they are not overly verbose or missing.

# Test: Search for usage of `useCoordNotification` and its context in the file.
rg --type ts -A 5 -B 5 'useCoordNotification'

Length of output: 4668


Script:

#!/bin/bash
# Description: Verify the triggering conditions for notifications to ensure they are not overly verbose or missing.

# Test: Search for usage of `notifyCoordUpdate` and its context in the relevant files.
rg --type ts -A 10 -B 10 'notifyCoordUpdate' packages/ui/components/data-portal/AddressDrawer/index.tsx packages/ui/components/data-portal/AddressDrawer/hookform.tsx

Length of output: 11670


363-512: Overall structure of the Drawer component.

The Drawer component is well-structured with clear separation of concerns in its layout.

The use of multiple smaller components and hooks within the Drawer helps in managing the complexity. However, ensure that the props passed to each component are properly validated to avoid runtime errors.

packages/api/router/location/query.forVisitCardEdits.handler.ts (2)

40-40: Check for potential data races.

The merging of formattedAddress into transformed happens right before the return statement. This operation should be checked for potential data races, especially since it involves external data manipulation.

Verification successful

No data races detected for formattedAddress.

The search did not reveal any asynchronous or concurrent contexts around the usage of formattedAddress. Therefore, it is safe to conclude that there are no potential data races involving this variable.

  • packages/api/router/location/query.forVisitCardEdits.handler.ts
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential data races involving `formattedAddress`.

# Test: Search for concurrent modifications to `formattedAddress`. Expect: No concurrent modifications.
rg --type typescript -A 5 $'formattedAddress'

Length of output: 79


Script:

#!/bin/bash
# Description: Check for potential data races involving `formattedAddress`.

# Test: Search for concurrent modifications to `formattedAddress`. Expect: No concurrent modifications.
rg --glob '*.ts' -A 5 'formattedAddress'

Length of output: 4446


Script:

#!/bin/bash
# Description: Check for potential data races involving `formattedAddress` in asynchronous or concurrent contexts.

# Test: Search for asynchronous contexts around `formattedAddress`. Expect: No concurrent modifications.
rg --glob '*.ts' -A 10 -B 10 'formattedAddress' | rg 'async|await|Promise'

Length of output: 74


5-5: New import for formatAddressVisibility.

The addition of the formatAddressVisibility function from lib.formatAddressVisibility is noted. Ensure that this function is properly tested and documented since it's being used to process potentially sensitive data.

@JoeKarow JoeKarow marked this pull request as ready for review July 17, 2024 16:47
Copy link

socket-security bot commented Jul 17, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@terraformer/wkt@2.2.1 None 0 92.6 kB jgravois
npm/@types/node@18.19.40 None 0 1.97 MB types
npm/just-group-by@2.2.0 None 0 5.93 kB angus-c
npm/libphonenumber-js@1.11.4 None 0 8.27 MB catamphetamine
npm/slugify@1.6.6 None 0 20.9 kB simov
npm/social-links@1.14.0 None 0 186 kB gkucmierz
npm/tiny-invariant@1.3.3 None 0 14.8 kB alexreardon
npm/type-fest@0.21.3 None 0 119 kB sindresorhus

🚮 Removed packages: npm/@aws-lambda-powertools/logger@1.18.1, npm/@crowdin/ota-client@1.0.0, npm/@emotion/react@11.11.4, npm/@emotion/server@11.11.0, npm/@hookform/devtools@4.3.1, npm/@hookform/resolvers@3.9.0, npm/@mantine/carousel@6.0.22, npm/@mantine/core@6.0.22, npm/@mantine/dates@6.0.22, npm/@mantine/form@6.0.22, npm/@mantine/hooks@6.0.22, npm/@mantine/next@6.0.22, npm/@mantine/notifications@6.0.22, npm/@mantine/nprogress@6.0.22, npm/@mantine/utils@6.0.22, npm/@next/bundle-analyzer@14.2.5, npm/@next/third-parties@14.2.5, npm/@opentelemetry/core@1.25.1, npm/@opentelemetry/exporter-trace-otlp-http@0.52.1, npm/@opentelemetry/resources@1.25.1, npm/@opentelemetry/sdk-node@0.52.1, npm/@opentelemetry/sdk-trace-base@1.25.1, npm/@opentelemetry/sdk-trace-node@1.25.1, npm/@playwright/test@1.45.2, npm/@prisma/client@5.16.2, npm/@prisma/instrumentation@5.16.2, npm/@prisma/nextjs-monorepo-workaround-plugin@5.16.2, npm/@relative-ci/agent@4.2.9, npm/@sentry/browser@7.118.0, npm/@sentry/integrations@7.114.0, npm/@sentry/nextjs@7.118.0, npm/@sentry/node@7.118.0, npm/@sentry/opentelemetry-node@7.114.0, npm/@sentry/opentelemetry@7.118.0, npm/@sentry/profiling-node@7.118.0, npm/@tanstack/react-query-devtools@4.36.1, npm/@tanstack/react-query@4.36.1, npm/@tanstack/react-table-devtools@8.19.3, npm/@tanstack/react-table@8.19.3, npm/@trpc/client@10.45.2, npm/@trpc/next@10.45.2, npm/@trpc/react-query@10.45.2, npm/@types/eslint@8.56.10, npm/@types/react-dom@18.3.0, npm/@types/react@18.3.3, npm/@typescript-eslint/eslint-plugin@7.16.1, npm/@typescript-eslint/parser@7.16.1, npm/@vercel/analytics@1.3.1, npm/@vercel/edge-config@1.2.0, npm/@vercel/kv@2.0.0, npm/@vercel/speed-insights@1.0.12, npm/@welldone-software/why-did-you-render@8.0.3, npm/aws-lambda@1.0.7, npm/cookies-next@4.2.1, npm/embla-carousel-autoplay@7.1.0, npm/embla-carousel-react@7.1.0, npm/eslint-plugin-i18next@6.0.9, npm/eslint@8.57.0, npm/i18next-browser-languagedetector@8.0.0, npm/i18next-chained-backend@4.6.2, npm/i18next-hmr@3.1.2, npm/i18next-http-backend@2.5.2, npm/i18next-intervalplural-postprocessor@3.0.0, npm/i18next-multiload-backend-adapter@2.3.0, npm/just-compare@2.3.0, npm/mantine-react-table@1.3.4, npm/next-auth@4.24.7, npm/next-i18next@15.3.0, npm/next-seo@6.5.0, npm/next@14.2.5, npm/nextjs-google-analytics@2.3.3, npm/nextjs-routes@2.2.1, npm/object-sizeof@2.6.5, npm/prisma@5.16.2, npm/react-dom@18.3.1, npm/react-error-boundary@4.0.13, npm/react-hook-consent@3.5.3, npm/react-hook-form-mantine@2.0.0, npm/react-hook-form@7.52.1, npm/react-i18next@14.1.3, npm/react@18.3.1, npm/trpc-panel@1.3.4, npm/trpc-playground@1.0.4, npm/webpack-bundle-analyzer@4.10.2

View full report↗︎

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e7bcd0b and 1b8271f.

Files selected for processing (8)
  • apps/app/src/pages/_app.tsx (1 hunks)
  • apps/app/src/providers/index.tsx (1 hunks)
  • packages/api/router/location/mutation.create.handler.ts (2 hunks)
  • packages/api/router/location/mutation.create.schema.ts (1 hunks)
  • packages/ui/components/data-portal/AddressAutocomplete/index.tsx (6 hunks)
  • packages/ui/components/data-portal/SocialMediaDrawer/index.tsx (1 hunks)
  • packages/ui/components/sections/LocationCard.tsx (1 hunks)
  • packages/ui/hooks/useScreenSize.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/ui/components/data-portal/SocialMediaDrawer/index.tsx
Files skipped from review as they are similar to previous changes (1)
  • packages/ui/components/data-portal/AddressAutocomplete/index.tsx
Additional comments not posted (6)
packages/ui/hooks/useScreenSize.ts (2)

17-21: Approved use of useMemo for performance optimization.

The use of useMemo to memoize the screenSizes object is a good practice to avoid unnecessary recalculations of these values on re-renders.


3-3: Verify correct import of useMemo.

Ensure that useMemo is imported from the correct library (react), which is standard practice for React hooks.

Verification successful

Verified correct import of useMemo.

The useMemo hook is correctly imported from the react library in packages/ui/hooks/useScreenSize.ts.

  • import { useMemo } from 'react'
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct import of `useMemo` in `useScreenSize.ts`.

# Test: Search for the import statement of `useMemo`. Expect: Import from 'react'.
rg --type typescript -A 1 "useMemo" packages/ui/hooks/useScreenData.ts

Length of output: 105


Script:

#!/bin/bash
# Description: Verify the correct import of `useMemo` in `useScreenSize.ts`.

# Test: Search for the import statement of `useMemo`. Expect: Import from 'react'.
rg "useMemo" packages/ui/hooks/useScreenSize.ts -A 1

Length of output: 183

packages/api/router/location/mutation.create.schema.ts (1)

12-15: Approved schema changes for increased flexibility.

Changing street2 and postCode to nullish increases flexibility in handling optional data. Ensure that the backend and any data consumers are updated to handle null values appropriately.

packages/api/router/location/mutation.create.handler.ts (1)

39-56: Approved restructuring of create function for better data management.

The changes to the create function, including the extraction of countryId and govDistId from address and the connection of orgId to the organization field, enhance clarity and data handling in database operations.

apps/app/src/pages/_app.tsx (1)

92-92: Verify the impact of moving <SpeedInsights /> outside <Providers>.

Moving <SpeedInsights /> outside of <Providers> could affect its access to context or props provided by <Providers>. Verify that this change does not negatively impact its functionality or performance.

packages/ui/components/sections/LocationCard.tsx (1)

Line range hint 1-1: Logging statement removed.

The removal of the console.log statement for 'title variant' with getTextVariant is noted. This is generally a good practice for production code to avoid exposing potentially sensitive information and to reduce console clutter. Ensure that this change was intended and that no necessary debug information is lost.

apps/app/src/providers/index.tsx Show resolved Hide resolved
Copy link

sonarcloud bot commented Jul 17, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
5.7% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1b8271f and 5c15c04.

Files selected for processing (1)
  • packages/api/router/organization/query.forOrgPageEdits.handler.ts (2 hunks)
Additional comments not posted (2)
packages/api/router/organization/query.forOrgPageEdits.handler.ts (2)

6-6: Review the new import statement.

The addition of formatAddressVisiblity from ../location/lib.formatAddressVisibility is crucial for the new functionality. Ensure that the function is properly tested and that the import path is correct.


44-47: Optimize data handling and ensure consistency.

The destructuring of org to separate allowedEditors and locations is well-implemented. However, the mapping over locations to apply formatAddressVisiblity could potentially lead to performance issues if locations contains a large number of entries.

Consider adding a check to ensure that locations is not excessively large before proceeding with the map operation, or implement a more efficient method for handling large datasets.

- locations: locations.map((location) => ({ ...location, ...formatAddressVisiblity(location) })),
+ locations: locations.length > 100 ? locations : locations.map((location) => ({ ...location, ...formatAddressVisiblity(location) })),

Also, ensure that formatAddressVisiblity handles null or undefined location values gracefully to avoid runtime errors.

@JoeKarow JoeKarow merged commit 4731e8e into dev Jul 17, 2024
30 of 33 checks passed
@JoeKarow JoeKarow deleted the JoeKarow/address-drawer-fixes branch July 17, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 api 📦 app 📦 auth automerge Enable Kodiak auto-merge bugfix Inconsistencies or issues which will cause a problem for users or implementors. 📦 crowdin 📦 db 📦 eslint-config kodiak: merge.method = 'squash' Kodiak will squash merge this PR. 📦 ui
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants