Skip to content

fix: improved person fetching#3161

Merged
gupta-piyush19 merged 2 commits intomainfrom
improve-person-fetching
Sep 20, 2024
Merged

fix: improved person fetching#3161
gupta-piyush19 merged 2 commits intomainfrom
improve-person-fetching

Conversation

@Dhruwang
Copy link
Member

@Dhruwang Dhruwang commented Sep 19, 2024

What does this PR do?

Improved person fetching

How should this be tested?

  • Test A
  • Test B

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues
  • First PR at Formbricks? Please sign the CLA! Without it we wont be able to merge it 🙏

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Enhanced person data representation with additional attributes for improved detail.
    • Introduced conditional styling for table cells to enhance visual consistency.
  • Bug Fixes

    • Streamlined data fetching logic in the PersonDataView component, reducing complexity.
  • Chores

    • Improved configurability of pagination settings for the PersonDataView component.
    • Updated border colors for improved visual consistency across various table components.

@vercel
Copy link

vercel bot commented Sep 19, 2024

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

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2024 3:44am
formbricks-docs ⬜️ Ignored (Inspect) Visit Preview Sep 20, 2024 3:44am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The pull request introduces significant changes across multiple files, primarily focusing on simplifying data fetching and enhancing type definitions. The PersonDataView component has been streamlined by removing the getPersonAttributesAction function, relying solely on getPersonsAction for data retrieval. Additionally, new utility functions and updated type definitions have been added to improve the handling of person attributes, ensuring that the data structure is more comprehensive and maintainable.

Changes

File Path Change Summary
apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonDataView.tsx Removed getPersonAttributesAction and associated logic; updated persons state to use TPersonWithAttributes[].
apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonTable.tsx Added getCommonPinningStyles utility function for conditional styling of table cells based on column ID.
apps/web/app/(app)/environments/[environmentId]/(people)/people/page.tsx Replaced hardcoded itemsPerPage value with ITEMS_PER_PAGE constant from @formbricks/lib/constants.
packages/lib/person/service.ts Enhanced transformPrismaPerson function to include additional attributes; updated return types to TPersonWithAttributes[].
packages/types/people.ts Introduced ZPersonWithAttributes schema and TPersonWithAttributes type alias to represent a person with attributes.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTable.tsx Changed border color from border-slate-300 to border-slate-200 for improved visual consistency.
apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTableCell.tsx Changed border color class from border-slate-300 to border-slate-200.
packages/ui/DataTable/components/DataTableHeader.tsx Updated border color class from border-slate-300 to border-slate-200.

Possibly related PRs

  • feat: Data table for persons #3154: The PersonTable.tsx component introduced in this PR is related to the changes in PersonDataView.tsx, as both components are part of the same feature set for managing person-related data within the application.
  • fix: person loading skeleton #3160: The changes in PersonDataView.tsx enhance the data fetching logic, which is directly related to the modifications made in the main PR that removed the getPersonAttributesAction function and simplified data handling.

🐰 In the meadow, changes bloom,
A simpler path, dispelling gloom.
Attributes gathered, neat and bright,
With constants guiding, all feels right.
A table dressed in styles so fine,
Data flows smoothly, like sweet sunshine! 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7c849f2 and 5d166f7.

Files selected for processing (4)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonTable.tsx (3 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTable.tsx (1 hunks)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTableCell.tsx (1 hunks)
  • packages/ui/DataTable/components/DataTableHeader.tsx (1 hunks)
Files skipped from review due to trivial changes (3)
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTable.tsx
  • apps/web/app/(app)/environments/[environmentId]/surveys/[surveyId]/(analysis)/responses/components/ResponseTableCell.tsx
  • packages/ui/DataTable/components/DataTableHeader.tsx
Files skipped from review as they are similar to previous changes (1)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonTable.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.

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
Copy link
Contributor

github-actions bot commented Sep 19, 2024

Thank you for following the naming conventions for pull request titles! 🙏

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 0b55344 and 7c849f2.

Files selected for processing (5)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonDataView.tsx (4 hunks)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonTable.tsx (2 hunks)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/page.tsx (2 hunks)
  • packages/lib/person/service.ts (5 hunks)
  • packages/types/people.ts (1 hunks)
Additional comments not posted (13)
packages/types/people.ts (1)

19-23: LGTM! The changes enhance the person data model.

The introduction of the ZPersonWithAttributes schema and TPersonWithAttributes type alias is a valuable addition to the codebase. These changes:

  1. Provide a more comprehensive representation of a person entity by incorporating attributes directly into the person object structure.
  2. Improve type safety and clarity, allowing developers to work with a well-defined model of a person that includes their attributes.
  3. Enhance the maintainability of the codebase by providing a consistent and detailed structure for person data.

The changes align with the PR objectives of simplifying data fetching and enhancing type definitions related to person attributes.

apps/web/app/(app)/environments/[environmentId]/(people)/people/page.tsx (2)

4-4: LGTM!

Importing the ITEMS_PER_PAGE constant from a shared library is a good practice to avoid hardcoding values. It improves maintainability by allowing the value to be modified in a single location.


35-35: Verify the value of ITEMS_PER_PAGE constant.

Using the imported ITEMS_PER_PAGE constant to set the itemsPerPage prop is a good change that eliminates the hardcoded value and makes the code more maintainable.

Please ensure that the ITEMS_PER_PAGE constant is set to an appropriate value that provides a good balance between user experience and performance. Consider factors such as the typical number of people in an environment, the loading time for each page, and the usability of the pagination controls.

apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonDataView.tsx (6)

3-3: LGTM!

The import statement for getPersonsAction is valid and the imported function is used within the component.


8-8: LGTM!

The import statement for TPersonWithAttributes type is valid and the imported type is used within the component.


17-17: LGTM!

The change in the persons state type from TPerson[] to TPersonWithAttributes[] aligns with the simplified data fetching approach and eliminates the need for additional data manipulation.


44-45: LGTM!

The fetchData function is called with the appropriate dependencies in the useEffect hook, ensuring that the data is fetched whenever relevant parameters change.


68-75: LGTM!

The personTableData mapping now occurs directly within the component, utilizing the persons state which already contains the necessary data. This simplifies the data handling process and eliminates the need for additional data manipulation.


76-76: LGTM!

The addition of an empty line after the personTableData mapping improves code readability and follows common coding conventions.

apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonTable.tsx (1)

193-193: LGTM!

The usage of the getCommonPinningStyles function to conditionally apply styles to the table cell based on the column ID is a good approach. It enhances the visual consistency of the table and improves code readability and maintainability.

packages/lib/person/service.ts (3)

94-109: Ensure consumers of getPeople handle the updated return type

The getPeople function now returns Promise<TPersonWithAttributes[]>. Verify that all consuming code correctly handles the additional attributes in the returned person objects to prevent any unexpected behavior.

Run the following script to identify all usages of getPeople:

#!/bin/bash
# Description: Find all instances where 'getPeople' is called to ensure proper handling of the new return type.

# Test: Search for function calls to 'getPeople'.
rg 'getPeople\(' --type javascript --type typescript

Line range hint 46-62: Verify consistency of transformPrismaPerson return type across the codebase

The return type of transformPrismaPerson has been updated to TPersonWithAttributes. Ensure that all usages of this function are updated to handle the new return type, preventing any type mismatches or runtime errors.

Run the following script to find and review all usages of transformPrismaPerson:

#!/bin/bash
# Description: Locate all function calls to 'transformPrismaPerson' to verify they handle the new return type.

# Test: Search for usages of 'transformPrismaPerson'.
rg 'transformPrismaPerson\(' --type javascript --type typescript

20-29: Ensure the nested attributes selection aligns with the data model

The selectPerson object now includes a nested selection for attributes and attributeClass. Verify that the Prisma schema correctly defines these relationships, and that the fields value and attributeClass.name are correctly retrieved.

Run the following script to verify the Prisma schema definitions:

Verification successful

Nested attributes selection aligns with the data model

The Prisma schema correctly defines the relationships between Person, Attribute, and AttributeClass models. The attributes field in the Person model allows for the nested selection of value from Attribute and name from the related AttributeClass. This structure supports the query in the selectPerson object.

  • Person has a one-to-many relationship with Attribute
  • Attribute has a many-to-one relationship with both Person and AttributeClass
  • The unique constraint on [personId, attributeClassId] in the Attribute model ensures data integrity

The schema fully supports the nested selection of value and attributeClass.name as specified in the review comment.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Confirm that the Prisma schema defines the necessary relations for 'Person', 'Attribute', and 'AttributeClass'.

# Test: Check the 'Person' model for the relation to 'attributes'.
rg --no-filename -A 5 '^model Person' prisma/schema.prisma | rg 'attributes'

# Test: Check the 'Attribute' model for the relation to 'attributeClass'.
rg --no-filename -A 5 '^model Attribute' prisma/schema.prisma | rg 'attributeClass'

Length of output: 101


Script:

#!/bin/bash

# Attempt to find and display the contents of the Prisma schema file
echo "Searching for Prisma schema file:"
fd -p 'schema.prisma$'

echo "\nAttempting to display the contents of the schema file:"
fd -p 'schema.prisma$' -x cat {}

echo "\nIf schema file not found, searching for files that might define the data model:"
fd -e ts -e js | grep -i 'model\|schema\|entity'

echo "\nSearching for 'Person' model definition:"
rg -i 'model\s+Person' -A 10

echo "\nSearching for 'Attribute' model definition:"
rg -i 'model\s+Attribute' -A 10

echo "\nSearching for 'AttributeClass' model definition:"
rg -i 'model\s+AttributeClass' -A 10

Length of output: 26344

Copy link
Contributor

@gupta-piyush19 gupta-piyush19 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@gupta-piyush19 gupta-piyush19 added this pull request to the merge queue Sep 20, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 20, 2024
@gupta-piyush19 gupta-piyush19 added this pull request to the merge queue Sep 20, 2024
Merged via the queue into main with commit e4fceb2 Sep 20, 2024
@gupta-piyush19 gupta-piyush19 deleted the improve-person-fetching branch September 20, 2024 05:18
@coderabbitai coderabbitai bot mentioned this pull request Nov 26, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 2024
12 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 10, 2024
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants