Skip to content

fix: person loading skeleton#3160

Merged
Dhruwang merged 1 commit intomainfrom
person-table-fix
Sep 19, 2024
Merged

fix: person loading skeleton#3160
Dhruwang merged 1 commit intomainfrom
person-table-fix

Conversation

@Dhruwang
Copy link
Member

@Dhruwang Dhruwang commented Sep 19, 2024

What does this PR do?

Fixes # (issue)

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 error handling during data fetching for improved application robustness.
    • Pagination limit for displayed person records is now set to a fixed value of 25.
  • Bug Fixes

    • Improved responsiveness to state changes by updating data fetching triggers.
  • Chores

    • Removed unnecessary imports to simplify the codebase.

@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) Sep 19, 2024 4:31pm
formbricks-docs ⬜️ Ignored (Inspect) Sep 19, 2024 4:31pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2024

Walkthrough

The changes in this pull request focus on improving data fetching and error handling within the PersonDataView.tsx component, along with a modification to the pagination configuration in the page.tsx file. The data fetching logic is enhanced by adjusting dependency management and implementing better error handling practices. Additionally, the pagination limit is simplified by hardcoding the value directly in the page.tsx file.

Changes

Files Change Summary
apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonDataView.tsx Enhanced error handling and dependency management in the data fetching logic, including the addition of personCount, itemsPerPage, and environment.id to the dependency array. Improved error handling with a try-catch-finally block and modified the deletePersons function for better state updates.
apps/web/app/(app)/environments/[environmentId]/(people)/people/page.tsx Changed the itemsPerPage property passed to PersonDataView from a constant import to a hardcoded value of 25, simplifying pagination configuration.

Possibly related PRs

  • feat: Data table for persons #3154: The changes in PersonDataView.tsx and page.tsx relate to the new PersonTable.tsx component introduced in this PR, as both involve managing and displaying person-related data, including pagination and data fetching logic.

Suggested reviewers

  • jobenjada

Poem

In a world of data, hopping so bright,
A rabbit brings changes, oh what a sight!
With fetching and handling, all tidy and neat,
Pagination simplified, oh what a treat!
So let’s celebrate, with a joyful cheer,
For smoother data flows, we hold dear! 🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6b64367 and f5e349a.

Files selected for processing (2)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/components/PersonDataView.tsx (2 hunks)
  • apps/web/app/(app)/environments/[environmentId]/(people)/people/page.tsx (1 hunks)
Additional comments not posted (5)
apps/web/app/(app)/environments/[environmentId]/(people)/people/page.tsx (1)

34-34: Consider using a constant for better flexibility and reusability.

Hardcoding the itemsPerPage value reduces flexibility and reusability. Consider the following suggestions:

  • Keep the ITEMS_PER_PAGE constant for better flexibility and reusability. This allows you to change the pagination limit in one place and have it reflected across the codebase.
  • If the ITEMS_PER_PAGE constant is not used anywhere else, consider renaming it to a more specific name like PEOPLE_PER_PAGE to improve code readability.

Please verify if the removal of the ITEMS_PER_PAGE constant affects other parts of the codebase. You can use the following script to search for its usage:

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

47-47: LGTM!

Adding personCount, itemsPerPage, and environment.id to the useEffect hook's dependency array is a good change. It ensures that the data fetch is triggered whenever these values change, improving the component's responsiveness to state changes.


52-73: LGTM!

The changes made to the second useEffect hook improve the error handling and reliability of the data fetching logic:

  • Wrapping the asynchronous data fetching logic in a try-catch-finally block allows for better error handling and logging.
  • Moving the setIsDataLoaded(true) call to the finally block ensures that the loading state is accurately reflected, regardless of whether the fetch was successful or not.
  • Removing the condition that checked persons.length before calling fetchAttributes allows for unconditional updates when persons changes.

These changes enhance the robustness and reliability of the component.


76-77: LGTM!

Calling fetchAttributes unconditionally within the useEffect hook is consistent with the removal of the condition that checked persons.length before calling the function. This change ensures that the component stays in sync with the latest attributes data whenever persons or environment.id changes.


97-97: LGTM!

Modifying the deletePersons function to use a functional update for setting the state of persons is a good change. Using a functional update (setPersons((prevPersons) => ...)) ensures that the state update is based on the most recent value of persons, which follows the best practice for state updates that depend on the previous state. This change improves the reliability and correctness of the state update.


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! 🙏

@Dhruwang Dhruwang requested a review from jobenjada September 19, 2024 16:34
@Dhruwang Dhruwang enabled auto-merge September 19, 2024 16:36
@Dhruwang Dhruwang added this pull request to the merge queue Sep 19, 2024
Merged via the queue into main with commit 0b55344 Sep 19, 2024
@Dhruwang Dhruwang deleted the person-table-fix branch September 19, 2024 16:53
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