Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fleet UI: Fix export button dependencies#45020

Merged
RachelElysia merged 4 commits into
mainfrom
45018-export-bug
May 8, 2026
Merged

Fleet UI: Fix export button dependencies#45020
RachelElysia merged 4 commits into
mainfrom
45018-export-bug

Conversation

@RachelElysia
Copy link
Copy Markdown
Member

@RachelElysia RachelElysia commented May 8, 2026

Issue

Closes #45018

Description

Reviewer note

Hide whitespace for easier time reviewing diff

Screenshot 2026-05-08 at 10 56 05 AM

Screen recording of fix

https://fleetdm.zoom.us/clips/share/zUs8dkogS2mi7FvjIEGvIA

Checklist for submitter

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

Testing

  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Fixed the "Export hosts" button so exported CSV now always respects the current table state — including active sort, search, filters, visible columns, and selected team — preventing outdated or mismatched export results.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 8.33333% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.77%. Comparing base (0079edf) to head (80e8ba7).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...nd/pages/hosts/ManageHostsPage/ManageHostsPage.tsx 8.33% 22 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #45020    +/-   ##
========================================
  Coverage   66.77%   66.77%            
========================================
  Files        2718     2718            
  Lines      218817   218816     -1     
  Branches    10748    10624   -124     
========================================
+ Hits       146123   146124     +1     
+ Misses      59532    59529     -3     
- Partials    13162    13163     +1     
Flag Coverage Δ
frontend 55.24% <8.33%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@RachelElysia
Copy link
Copy Markdown
Member Author

@claude review

@RachelElysia RachelElysia marked this pull request as ready for review May 8, 2026 17:15
@RachelElysia RachelElysia requested a review from a team as a code owner May 8, 2026 17:15
Copilot AI review requested due to automatic review settings May 8, 2026 17:15
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@RachelElysia
Copy link
Copy Markdown
Member Author

@claude review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a stale-closure bug on the Manage Hosts page where the “Export hosts” button could export using outdated sort/search/filter state by ensuring the export click handler is properly memoized and referenced.

Changes:

  • Memoized onExportHostsResults with useCallback and added the relevant dependency list so it always captures current table state.
  • Updated the count renderer callback (renderHostCountAndExport) to depend on onExportHostsResults, preventing stale export handlers.
  • Added a changes entry describing the user-visible fix.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.

File Description
frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx Memoizes export handler and updates callback dependencies so exports reflect current UI state.
changes/45018-export-host-bug Adds changelog entry for the export button fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

isOnlyObserver,
const columnIds = tableColumns
.map((column) => (column.id ? column.id : ""))
// "selection" colum does not include any relevent data for the CSV
renderFlash("error", "Could not export hosts. Please try again.");
}
};
queryParams.fleet_id,
@@ -0,0 +1 @@
- Fleet UI: Export hosts button now always reflects the current sort, search, and filter state instead of potentially using stale values.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 42cb8f89-4dfe-496a-8a06-1177677c27dd

📥 Commits

Reviewing files that changed from the base of the PR and between ee83b16 and 80e8ba7.

📒 Files selected for processing (1)
  • frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx

Walkthrough

The PR refactors the ManageHostsPage export flow: it memoizes the export handler into onExportHostsResults (computing visibleColumns, building a full hostsAPI.exportHosts options payload including queryParams.fleet_id handling), introduces renderHostCountAndExport to render the count plus the Export button wired to the memoized handler, and wires that callback into TableContainer via its renderCount prop so exports reflect current sort/search/filter state.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing the export button's dependency issues that caused stale state.
Description check ✅ Passed The PR description includes a related issue reference, addresses the bug fix with reviewer notes, evidence of manual testing, and confirms a changes file was added.
Linked Issues check ✅ Passed The code changes fully address the root cause: onExportHostsResults is now memoized with useCallback dependencies covering all filter/sort state, and renderHostCount's memoization includes this callback in its dependency array.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the export button dependencies and ensuring hidden columns are properly excluded, with no unrelated alterations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 45018-export-bug

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx (1)

1567-1685: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Export uses stale localStorage for hidden columns, ignoring server-persisted user settings

Lines 1571–1592 read hidden columns from localStorage.getItem("hostHiddenColumns"). The migration block at lines 641–662 removes that key after successfully syncing to the server (localStorage.removeItem("hostHiddenColumns")). For any user who has been migrated, this read returns null, so currentHiddenColumns stays [] and generateVisibleTableColumns is called with hiddenColumns: [] — treating every column as visible regardless of the user's actual preferences. The exported CSV will include all columns instead of only the ones the user has enabled.

The hiddenColumns state variable is already the correct source of truth (initialized from userSettings?.hidden_host_columns and kept in sync by onSaveColumns). It should be used directly, and added to the dependency array.

🐛 Proposed fix
-    const hiddenColumnsStorage = localStorage.getItem("hostHiddenColumns");
-    let currentHiddenColumns = [];
-    let visibleColumns;
-    if (hiddenColumnsStorage) {
-      currentHiddenColumns = JSON.parse(hiddenColumnsStorage);
-    }
+    let visibleColumns;

     if (config && currentUser) {
       const tableColumns = generateVisibleTableColumns({
-        hiddenColumns: currentHiddenColumns,
+        hiddenColumns,
         isFreeTier,
         isOnlyObserver,
         teamId: teamIdForApi,
       });

Add hiddenColumns to the dependency array:

   }, [
     config,
     currentUser,
+    hiddenColumns,
     isFreeTier,
     isOnlyObserver,
     teamIdForApi,
     // ... rest of deps unchanged
   ]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx` around lines 1567 -
1685, The export handler onExportHostsResults incorrectly reads hidden columns
from localStorage ("hostHiddenColumns") causing migrated users to get stale []
instead of their server-synced settings; instead, use the component state
hiddenColumns (which is initialized from userSettings?.hidden_host_columns and
updated by onSaveColumns) when calling generateVisibleTableColumns and remove
the localStorage.getItem fallback logic, and add hiddenColumns to the
useCallback dependency array so exports reflect current column visibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx`:
- Around line 1567-1685: The export handler onExportHostsResults incorrectly
reads hidden columns from localStorage ("hostHiddenColumns") causing migrated
users to get stale [] instead of their server-synced settings; instead, use the
component state hiddenColumns (which is initialized from
userSettings?.hidden_host_columns and updated by onSaveColumns) when calling
generateVisibleTableColumns and remove the localStorage.getItem fallback logic,
and add hiddenColumns to the useCallback dependency array so exports reflect
current column visibility.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: afb39255-e8bb-44d8-83cb-9153cbbeafc5

📥 Commits

Reviewing files that changed from the base of the PR and between 7fbb852 and ee83b16.

📒 Files selected for processing (2)
  • changes/45018-export-host-bug
  • frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx

Comment thread frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx Outdated
Comment thread frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx Outdated
@RachelElysia RachelElysia marked this pull request as draft May 8, 2026 17:43
@RachelElysia
Copy link
Copy Markdown
Member Author

@claude review

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

All three issues from my prior review have been addressed: hidden-columns now uses the in-memory state, the missing filter keys are included in the export options, and the unused dep was dropped.

Extended reasoning...

Overview

This PR fixes a stale-closure bug in the Hosts page Export button by wrapping onExportHostsResults in useCallback with a complete dependency list, and combining it with the host count renderer into renderHostCountAndExport. The two changed files are a one-line changelog entry and frontend/pages/hosts/ManageHostsPage/ManageHostsPage.tsx.

Security risks

None. This is a pure UI change. The export call already routed through hostsAPI.exportHosts with the same set of filter parameters used elsewhere on the page; the change just ensures those parameters reflect current state. No auth, crypto, permission, or data-boundary code is touched.

Level of scrutiny

Low-to-medium. Frontend bug fix scoped to a single page component, no API or backend changes. The author also incorporated additional findings from my earlier review (using the hiddenColumns state instead of the post-migration-empty localStorage value, and adding diskEncryptionStatus, depProfileError, depAssignProfileResponse to the export options) and produced a screenshot confirming the columns behavior is correct.

Other factors

Remaining nits are minor: pre-existing typos in a moved comment (colum/relevent), an unguarded queryParams.fleet_id access in the dep list (consistent with how the page already uses queryParams elsewhere), and bullet style in the changes file. None warrant blocking. QA was performed manually with a screen recording attached.

@RachelElysia RachelElysia marked this pull request as ready for review May 8, 2026 19:06
@RachelElysia RachelElysia merged commit d2033df into main May 8, 2026
25 checks passed
@RachelElysia RachelElysia deleted the 45018-export-bug branch May 8, 2026 19:32
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.

Fleet UI: Export hosts might not be always updated

3 participants