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

Optimize Pagination | Switch to TanStackQuery in ResourcesList | Prevent API calls | Fix Translation #10273

Conversation

rajku-dev
Copy link
Contributor

@rajku-dev rajku-dev commented Jan 29, 2025

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • Localization

    • Added new translation entries for consent status and user data error messages.
  • Performance Improvements

    • Enhanced data fetching across multiple components using React Query.
    • Added keepPreviousData to maintain smooth UI transitions.
    • Implemented staleTime to optimize data caching and reduce unnecessary network requests.
  • Bug Fixes

    • Improved error handling for user data retrieval.
    • Removed loading indicators from comment sections and questionnaire responses for a cleaner UI experience.

The changes focus on improving application performance, user experience, and error handling across various components.

@rajku-dev rajku-dev requested a review from a team as a code owner January 29, 2025 04:16
Copy link
Contributor

coderabbitai bot commented Jan 29, 2025

Walkthrough

This pull request introduces optimizations to data fetching across multiple components using TanStack Query. The changes primarily focus on improving user experience during data loading by implementing keepPreviousData and staleTime options. These modifications help retain previous data during new data fetching, reduce unnecessary API calls, and provide a smoother transition between data states. Additionally, new localization entries for consent status and error handling have been added to the English JSON file.

Changes

File Change Summary
public/locale/en.json Added two new localization entries: "consent__status" and "error_fetching_users_data"
src/components/Facility/FacilityUsers.tsx Updated useQuery to include keepPreviousData, added staleTime: 60 * 1000
src/components/Files/FilesTab.tsx Updated useQuery to include keepPreviousData, added staleTime: 60 * 1000 and enabled: !!type
src/components/Resource/ResourceList.tsx Replaced custom query with useQuery, updated variable names, added CSV fetching logic
src/pages/Encounters/EncounterList.tsx Updated useQuery to include keepPreviousData and staleTime: 60 * 1000
src/pages/Facility/FacilitiesPage.tsx Updated useQuery to include keepPreviousData and staleTime: 60 * 1000
src/pages/Facility/FacilityDetailsPage.tsx Updated useQuery to include keepPreviousData and staleTime: 60 * 1000
src/pages/Organization/OrganizationFacilities.tsx Updated useQuery to include keepPreviousData and staleTime: 60 * 1000
src/pages/Organization/OrganizationPatients.tsx Updated useQuery to include keepPreviousData and staleTime: 60 * 1000
src/CAREUI/misc/PaginatedList.tsx Modified rendering logic in Items and Paginator components to simplify loading state handling
src/Utils/request/useQuery.ts Added keepPreviousData import for enhanced query behavior
src/components/Resource/ResourceCommentSection.tsx Removed CircularProgress loading indicator from comments section
src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx Removed CardListSkeleton loading indicator from questionnaire responses section
src/pages/Organization/OrganizationUsers.tsx Updated useQuery to include keepPreviousData and replaced isFetching with isLoading
src/pages/Organization/OrganizationView.tsx Updated useQuery to include keepPreviousData and replaced isFetching with isLoading

Assessment against linked issues

Objective Addressed Explanation
Optimize Pagination Queries with TanStack Query v5 (#10220)
Minimize Skeleton Loader Switching (#10220)
Prevent Redundant API Calls (#10220)

Possibly related PRs

Suggested labels

needs review, needs testing

Suggested reviewers

  • rithviknishad
  • Jacobjeevan
  • bodhish

Poem

🐰 Queries dance with grace and might,
Data flows smooth, no loading fright!
Previous data holds its ground,
While fresh requests quietly sound.
TanStack magic, rabbit's delight! 🌟


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.

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.

Copy link

netlify bot commented Jan 29, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit a9a656e
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/679b026e586d2200080dc731
😎 Deploy Preview https://deploy-preview-10273--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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

🧹 Nitpick comments (7)
src/pages/Facility/FacilitiesPage.tsx (1)

62-63: LGTM! Consider standardizing staleTime format.

The optimization changes look good and work well with the enabled condition. However, for consistency across the codebase, consider standardizing the staleTime format:

-    staleTime: 60 * 1000,
+    staleTime: 1000 * 60,
src/pages/Facility/FacilityDetailsPage.tsx (1)

52-53: Consider applying optimizations to both queries.

While the optimization for the users query is good, the facility query could benefit from the same optimizations:

   const { data: facilityResponse, isLoading } = useQuery<FacilityModel>({
     queryKey: ["facility", id],
     queryFn: query(routes.getAnyFacility, {
       pathParams: { id },
     }),
+    placeholderData: keepPreviousData,
+    staleTime: 60 * 1000,
   });
src/pages/Organization/OrganizationFacilities.tsx (1)

51-52: LGTM! Consider standardizing staleTime format.

The optimization changes look good and work well with the enabled condition. However, for consistency across the codebase, consider standardizing the staleTime format:

-    staleTime: 60 * 1000,
+    staleTime: 1000 * 60,
src/pages/Organization/OrganizationPatients.tsx (1)

86-87: LGTM! Good optimization of data fetching.

The addition of keepPreviousData and staleTime options improves the user experience by:

  1. Preventing loading flickers during pagination
  2. Reducing unnecessary API calls with a 60-second stale time window

Consider extracting the stale time duration to a constant since it's used across multiple components.

+// Add to a constants file
+export const DEFAULT_QUERY_STALE_TIME = 60 * 1000;

-    staleTime: 60 * 1000,
+    staleTime: DEFAULT_QUERY_STALE_TIME,
src/components/Files/FilesTab.tsx (1)

111-113: LGTM! Good optimization with appropriate stale time for files.

The changes improve the component by:

  1. Preventing unnecessary API calls when type is not available
  2. Using a longer stale time (5 minutes) which is appropriate for files that change less frequently
  3. Preventing loading flickers with keepPreviousData

Consider adding a comment explaining why files use a longer stale time compared to other resources.

+    // Files are cached longer (5 minutes) as they change less frequently than other resources
     staleTime: 1000 * 60 * 5,
src/pages/Encounters/EncounterList.tsx (1)

Line range hint 175-183: Consider applying similar optimizations to the single encounter query.

For consistency, consider adding keepPreviousData and staleTime to the single encounter query as well.

   const { data: queryEncounter } = useQuery<Encounter>({
     queryKey: ["encounter", encounter_id],
     queryFn: query(routes.encounter.get, {
       pathParams: { id: encounter_id },
       queryParams: {
         facility: facilityId,
       },
     }),
     enabled: !!encounter_id,
+    placeholderData: keepPreviousData,
+    staleTime: 60 * 1000,
   });
src/components/Resource/ResourceList.tsx (1)

59-64: Add error handling for CSV download query.

Consider handling potential download failures to improve user experience.

 const { data: csvFile } = useQuery({
   queryKey: ["downloadResourcesCsv", appliedFilters],
   queryFn: query(routes.downloadResourceRequests, {
     queryParams: { ...appliedFilters, csv: true },
   }),
+  retry: 2,
+  onError: (error) => {
+    // Show error notification to user
+    console.error('Failed to download CSV:', error);
+  }
 });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 881610a and d723547.

📒 Files selected for processing (9)
  • public/locale/en.json (2 hunks)
  • src/components/Facility/FacilityUsers.tsx (2 hunks)
  • src/components/Files/FilesTab.tsx (2 hunks)
  • src/components/Resource/ResourceList.tsx (7 hunks)
  • src/pages/Encounters/EncounterList.tsx (2 hunks)
  • src/pages/Facility/FacilitiesPage.tsx (2 hunks)
  • src/pages/Facility/FacilityDetailsPage.tsx (2 hunks)
  • src/pages/Organization/OrganizationFacilities.tsx (2 hunks)
  • src/pages/Organization/OrganizationPatients.tsx (2 hunks)
🔇 Additional comments (5)
src/components/Facility/FacilityUsers.tsx (1)

46-47: LGTM! Optimization improves UX during pagination.

The addition of keepPreviousData and staleTime options effectively optimizes the data fetching strategy:

  • Prevents UI flicker during pagination by retaining previous data
  • Reduces unnecessary API calls with a 1-minute stale time window
src/pages/Encounters/EncounterList.tsx (1)

172-173: LGTM! Good optimization of encounter list fetching.

The addition of keepPreviousData and staleTime options improves the user experience by preventing loading flickers during filtering and reducing unnecessary API calls.

src/components/Resource/ResourceList.tsx (2)

1-1: Excellent implementation of TanStack Query!

The query configuration demonstrates best practices:

  • Using keepPreviousData prevents UI flicker during refetches
  • Setting staleTime: 1000 * 60 * 2 (2 minutes) reduces unnecessary API calls
  • Query key properly includes dependencies (qParams)

Also applies to: 42-57


213-213: LGTM! Clean implementation of export functionality.

The ExportButton action is simplified to directly use the query result.

public/locale/en.json (1)

580-580: LGTM! Translation entries added correctly.

The new entries support the translation key changes in the codebase:

  • Added "consent_status" to match the updated key in ResourceList.tsx
  • Added error message for user data fetching

Also applies to: 925-925

src/components/Resource/ResourceList.tsx Show resolved Hide resolved
@rajku-dev
Copy link
Contributor Author

@rithviknishad Please review the changes.
Thank you.

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)
src/components/Resource/ResourceList.tsx (1)

279-281: Optimize list rendering performance.

Consider memoizing the resource list rendering to prevent unnecessary re-renders.

+ const memoizedResourceList = useMemo(
+   () => showResourceCardList(resourcesList?.results || []),
+   [resourcesList?.results]
+ );

- <div>{showResourceCardList(resourcesList?.results || [])}</div>
+ <div>{memoizedResourceList}</div>

Don't forget to add the import:

+ import { useMemo } from 'react';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d723547 and 3fe7a80.

📒 Files selected for processing (2)
  • public/locale/en.json (2 hunks)
  • src/components/Resource/ResourceList.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • public/locale/en.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (2)
src/components/Resource/ResourceList.tsx (2)

1-1: LGTM! Clean import of TanStack Query utilities.

The imports are well-organized and correctly include the necessary TanStack Query hooks and utilities.

Also applies to: 22-22


Line range hint 270-270: Translation key inconsistency detected.

The translation key consent__status is still being used while other parts of the codebase have moved to consent_status. This inconsistency will cause translation issues.

This was previously flagged in earlier reviews. Please ensure consistent usage of translation keys across the entire application.

Comment on lines 59 to 64
const { data: csvFile } = useQuery({
queryKey: ["downloadResourcesCsv", appliedFilters],
queryFn: query(routes.downloadResourceRequests, {
queryParams: { ...appliedFilters, csv: true },
}),
});
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve CSV download implementation.

The current CSV download implementation has several potential issues:

  1. Missing error handling for failed downloads
  2. No loading state indication
  3. Potential null reference when csvFile is undefined
 const {
   data: csvFile,
+  isLoading: isDownloading,
+  error: downloadError
 } = useQuery({
   queryKey: ["downloadResourcesCsv", appliedFilters],
   queryFn: query(routes.downloadResourceRequests, {
     queryParams: { ...appliedFilters, csv: true },
   }),
+  retry: 2,
 });

 // In ExportButton
 <ExportButton
   variant="secondary"
   className="ml-4 bg-transparent shadow-none text-black rounded-full"
-  action={async () => csvFile ?? null}
+  action={async () => {
+    if (downloadError) {
+      throw new Error(t("error_downloading_csv"));
+    }
+    return csvFile ?? null;
+  }}
+  loading={isDownloading}
   filenamePrefix="resource_requests"
 />

Also applies to: 213-213

src/components/Resource/ResourceList.tsx Outdated Show resolved Hide resolved
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

🧹 Nitpick comments (3)
src/CAREUI/misc/PaginatedList.tsx (1)

Line range hint 185-198: Consider using optional chaining for better null safety.

The type simplification looks good, but the null check for data?.count could be more consistent.

Apply this diff to improve null safety:

-  if (hideIfSinglePage && (data?.count ?? 0) <= perPage) {
+  if (hideIfSinglePage && data?.count <= perPage) {
    return null;
  }

  return (
    <Pagination
      className={className}
      cPage={currentPage}
-      data={{ totalCount: data?.count ?? 0 }}
+      data={{ totalCount: data?.count || 0 }}
      defaultPerPage={perPage}
      onChange={setPage}
    />
  );

This change:

  • Uses a more idiomatic approach with optional chaining
  • Uses || instead of ?? since we specifically want to handle both null and undefined
src/Utils/request/useQuery.ts (2)

42-42: Consider making keepPreviousData configurable.

While keepPreviousData is excellent for pagination, applying it globally might not be optimal for all queries. Consider making it configurable through the options parameter:

 export interface QueryOptions<TData> extends RequestOptions<TData> {
   prefetch?: boolean;
   key?: string;
+  keepPreviousData?: boolean;
 }

 // In the useQuery config:
-    placeholderData: keepPreviousData,
+    placeholderData: options?.keepPreviousData ? keepPreviousData : undefined,

Line range hint 13-16: Enhance deprecation notice with migration examples.

The current deprecation notice could be more helpful by including:

  1. A brief example of how to migrate to direct TanStack Query usage
  2. A link to migration documentation
  3. The benefits of migrating (e.g., direct access to TanStack Query features)
 /**
- * @deprecated use `useQuery` from `@tanstack/react-query` instead.
+ * @deprecated Use `useQuery` from `@tanstack/react-query` instead.
+ * Example migration:
+ * ```typescript
+ * // Before:
+ * const { data, loading } = useTanStackQueryInstead(route, options);
+ * 
+ * // After:
+ * const { data, isLoading } = useQuery({
+ *   queryKey: [route.path, options?.pathParams],
+ *   queryFn: () => request(route, options),
+ *   placeholderData: keepPreviousData,
+ * });
+ * ```
+ * See our migration guide: <add_link_here>
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f02fc8c and 07d57e1.

📒 Files selected for processing (3)
  • src/CAREUI/misc/PaginatedList.tsx (2 hunks)
  • src/Utils/request/useQuery.ts (2 hunks)
  • src/components/Resource/ResourceCommentSection.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • src/components/Resource/ResourceCommentSection.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (2)
src/CAREUI/misc/PaginatedList.tsx (1)

157-159: LGTM! Improved loading state handling.

The simplified rendering condition aligns well with TanStack Query's keepPreviousData pattern, providing a better user experience by maintaining previous data visibility during loading states.

Consider implementing a minimum height container or consistent item heights to prevent layout shifts when data length changes. Run this script to check for potential layout shift issues:

✅ Verification successful

Layout shifts are properly managed ✓

The codebase implements consistent layout management through:

  • Fixed container heights with proper overflow handling
  • Uniform grid gaps and flex layouts
  • Viewport-based height constraints
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for height-related CSS classes or styles in components using PaginatedList
rg -l "PaginatedList" | xargs rg "height|min-h"

Length of output: 47


Script:

#!/bin/bash
# First, find files containing PaginatedList
echo "=== Files using PaginatedList ==="
rg -l "PaginatedList"

echo -e "\n=== Checking for CSS files ==="
fd -e css -e scss

echo -e "\n=== Checking for Tailwind classes in PaginatedList components ==="
rg "className.*(?:h-|min-h-|max-h-)" -A 2 -B 2 $(rg -l "PaginatedList")

echo -e "\n=== Checking for style props in PaginatedList components ==="
rg "style.*(?:height|minHeight|maxHeight)" -A 2 -B 2 $(rg -l "PaginatedList")

Length of output: 477


Script:

#!/bin/bash
# Check for flex/grid layouts and container styles in PaginatedList and its usage
echo "=== Checking PaginatedList implementation ==="
rg "className.*(?:flex|grid|container)" -A 2 -B 2 src/CAREUI/misc/PaginatedList.tsx

echo -e "\n=== Checking PaginatedList usage for container styles ==="
rg "(?:<PaginatedList.*>|className.*(?:flex|grid|container))" -A 3 -B 3 \
    src/components/Resource/ResourceCommentSection.tsx \
    src/components/Facility/ConsultationDetails/QuestionnaireResponsesList.tsx \
    src/components/Patient/PatientDetailsTab/EncounterHistory.tsx \
    src/components/Patient/PatientDetailsTab/patientUpdates.tsx

Length of output: 18702

src/Utils/request/useQuery.ts (1)

1-1: Consider migration strategy impact.

While adding keepPreviousData improves the functionality, adding new features to a deprecated utility might discourage migration to direct TanStack Query usage. Consider documenting the migration path to help users transition to the recommended approach.

Let's check how widely this deprecated utility is still used:

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

🧹 Nitpick comments (4)
src/pages/Organization/OrganizationView.tsx (2)

1-1: LGTM! Well-implemented query optimizations.

Good use of TanStack Query features:

  • keepPreviousData prevents UI flicker during pagination
  • staleTime of 1 minute reduces unnecessary API calls
  • Proper extraction of loading states

Consider adding retry: false to the query config if this is a user-initiated search, as retrying failed searches might not be desirable from a UX perspective.

Also applies to: 35-50


Line range hint 31-34: Consider these improvements to the component logic.

While the implementation is solid, here are some suggestions:

  1. The search input could benefit from debouncing to prevent excessive API calls during typing
  2. Consider moving the hardcoded limit = 12 to a constants file for better maintainability

Example implementation:

+ import { useDebouncedCallback } from 'use-debounce';
+ import { PAGINATION_LIMITS } from '@/constants';

- const limit = 12; // 3x4 grid
+ const limit = PAGINATION_LIMITS.ORGANIZATION_GRID;

+ const debouncedSetSearch = useDebouncedCallback(
+   (value: string) => {
+     setSearchQuery(value);
+     setPage(1);
+   },
+   300
+ );

  <Input
    placeholder="Search by name..."
    value={searchQuery}
-   onChange={(e) => {
-     setSearchQuery(e.target.value);
-     setPage(1);
-   }}
+   onChange={(e) => debouncedSetSearch(e.target.value)}
    className="w-full"
  />

Also applies to: 71-77

src/pages/Organization/OrganizationUsers.tsx (2)

40-44: Remove unused isFetchingUsers variable.

The isFetchingUsers variable is only used in the EntityBadge component. Consider using isLoading consistently throughout the component for better maintainability.

  const {
    data: users,
-   isFetching: isFetchingUsers,
    isLoading,
  } = useQuery({

Then update the EntityBadge component:

  <EntityBadge
    title={t("users")}
    count={users?.count}
-   isFetching={isFetchingUsers}
+   isFetching={isLoading}
    translationParams={{ entity: "User" }}
  />

Line range hint 110-114: Match loading skeleton layout with actual data grid.

The loading skeleton uses a different grid layout compared to the actual data. Consider matching the layouts for a smoother transition:

- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
+ <div className="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4">
    <CardGridSkeleton count={6} />
  </div>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff01eef and 3e1e144.

📒 Files selected for processing (4)
  • src/pages/Organization/OrganizationFacilities.tsx (4 hunks)
  • src/pages/Organization/OrganizationPatients.tsx (4 hunks)
  • src/pages/Organization/OrganizationUsers.tsx (4 hunks)
  • src/pages/Organization/OrganizationView.tsx (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/pages/Organization/OrganizationFacilities.tsx
  • src/pages/Organization/OrganizationPatients.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: cypress-run (1)
🔇 Additional comments (3)
src/pages/Organization/OrganizationView.tsx (1)

Line range hint 83-87: Great improvement in loading state handling!

Using isLoading instead of isFetching for skeleton display is the correct approach as it prevents unnecessary UI flicker during background updates while still showing loading states for initial data fetch.

src/pages/Organization/OrganizationUsers.tsx (2)

1-1: LGTM! Good addition of keepPreviousData.

The import of keepPreviousData aligns with the optimization strategy for pagination.


55-56: LGTM! Effective query optimization implementation.

The addition of placeholderData: keepPreviousData and staleTime: 1000 * 60 will:

  • Prevent UI flicker during pagination by retaining previous data
  • Reduce unnecessary API calls by caching data for 1 minute

@rajku-dev
Copy link
Contributor Author

Can we migrate to useQuery in PaginatedList.tsx?

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 30, 2025
@Jacobjeevan
Copy link
Contributor

#10220 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize Pagination Queries and Avoid Redundant API Calls
2 participants