Skip to content

Show Manage Automations disabled button with tooltip on Queries page#39302

Merged
nulmete merged 6 commits intomainfrom
nulmete/queries-manage-automations-not-visible
Feb 9, 2026
Merged

Show Manage Automations disabled button with tooltip on Queries page#39302
nulmete merged 6 commits intomainfrom
nulmete/queries-manage-automations-not-visible

Conversation

@nulmete
Copy link
Copy Markdown
Member

@nulmete nulmete commented Feb 4, 2026

Related issue: Resolves #39303 (child of #25080).

  • Added inherited_query_count to ListQueriesResponse (thought of adding a brand new endpoint just for counting, but felt like extending the current one was good enough). In the parent task, it was suggested to "Depend on team list entity endpoint's count field / team entity count endpoint for whether or not to disable the manage automations button", which Rachael approved, so I went for this approach.
  • The ManageQueryAutomationsModal now fetches its own data with merge_inherited = false (meaning it only fetches non-inherited queries only). Previously, queries were passed down as props to it, which would not show the queries available to automate if the first page of queries were all inherited and the second page contained queries for that team (the user would have to navigate to the second page for the button to be enabled).

^ The fact that the modal fetches its own data is similar behavior to what is currently done in Policies. For queries, I noticed that we would need to add pagination within the Manage Automations modal, but that can be a follow-up.

Screenshot 2026-02-04 at 11 48 42 AM

Checklist for submitter

  • 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
Screen.Recording.2026-02-04.at.11.56.55.AM.mov

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 35.71429% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.37%. Comparing base (0d6d1cb) to head (33d10e4).
⚠️ Report is 54 commits behind head on main.

Files with missing lines Patch % Lines
...ryAutomationsModal/ManageQueryAutomationsModal.tsx 0.00% 24 Missing ⚠️
...es/queries/ManageQueriesPage/ManageQueriesPage.tsx 0.00% 20 Missing ⚠️
server/datastore/mysql/queries.go 66.66% 4 Missing and 4 partials ⚠️
server/service/queries.go 84.61% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #39302   +/-   ##
=======================================
  Coverage   64.37%   64.37%           
=======================================
  Files        2398     2398           
  Lines      187405   187471   +66     
  Branches     8464     8486   +22     
=======================================
+ Hits       120639   120683   +44     
- Misses      55852    55877   +25     
+ Partials    10914    10911    -3     
Flag Coverage Δ
backend 65.93% <75.00%> (+0.01%) ⬆️
frontend 54.25% <0.00%> (-0.05%) ⬇️

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.

@@ -0,0 +1 @@
- The "Manage automations" button on the queries page is now always visible, and disabled only when the current team has no queries of its own. No newline at end of file
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

will modify it to also reference Policies page on the follow-up PR that will tackle the same changes for Policies

Suggested change
- The "Manage automations" button on the queries page is now always visible, and disabled only when the current team has no queries of its own.
- The "Manage automations" button on the queries and policies pages is now always visible, and disabled only when the current team has no queries of its own.

Copy link
Copy Markdown
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

LGTM!

Worth adding a few integration tests that check the new inherited count being returned.

Comment thread server/datastore/mysql/queries.go Outdated
// determined by passed in fleet.ListOptions, count of total queries returned without limits, and
// pagination metadata
func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions) ([]*fleet.Query, int, *fleet.PaginationMetadata, error) {
func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions) ([]*fleet.Query, int, int, *fleet.PaginationMetadata, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: To improve readability you can use named returns

Suggested change
func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions) ([]*fleet.Query, int, int, *fleet.PaginationMetadata, error) {
func (ds *Datastore) ListQueries(ctx context.Context, opt fleet.ListQueryOptions) (queries []*fleet.Query, total int, inherited int, metdata *fleet.PaginationMetadata, err error) {

Comment on lines +1488 to +1497
assert.Equal(t, 1, listQueriesResp.Count)
assert.Equal(t, 0, listQueriesResp.InheritedQueryCount)

// list merged team queries
s.DoJSON("GET", "/api/latest/fleet/queries", nil, http.StatusOK, &listQueriesResp, "team_id", fmt.Sprint(team1.ID), "merge_inherited", "true", "order_key", "team_id", "order_direction", "desc")
require.Len(t, listQueriesResp.Queries, 2)
assert.Equal(t, "team1", listQueriesResp.Queries[0].Name)
assert.Equal(t, "global1", listQueriesResp.Queries[1].Name)
assert.Equal(t, 2, listQueriesResp.Count)
assert.Equal(t, 1, listQueriesResp.InheritedQueryCount)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lucasmrod added assertions for InheritedQueryCount in these existing tests instead of adding new tests.

@nulmete nulmete requested a review from lucasmrod February 6, 2026 14:25
lucasmrod
lucasmrod previously approved these changes Feb 6, 2026
};

return { queryItems, updateQueryItems };
return { queryItems, setQueryItems, updateQueryItems };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It seems like we should be able to handle all the queryItems state inside of the custom hook rather than exposing setQueryItems for an external effect. What if you instead made sortedAvailableQueries an input to this custom hook?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Makes sense, I'll address

Copy link
Copy Markdown
Member Author

@nulmete nulmete Feb 6, 2026

Choose a reason for hiding this comment

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

@gillespi314 addressed.

I removed the useCheckboxStateManagement hook - I think it only added unnecessary indirection (and cognitive load) and everything could be handled within the component.

@nulmete nulmete merged commit e5849ee into main Feb 9, 2026
49 of 52 checks passed
@nulmete nulmete deleted the nulmete/queries-manage-automations-not-visible branch February 9, 2026 18:16
nulmete added a commit that referenced this pull request Feb 9, 2026
…#39392)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #39304 (part of #25080)

Implemented similar approach to
#39302, with the difference that
the list policies endpoint does not include a count, and there is a
separate endpoint. I extended the count policies endpoint to include an
`inherited_policy_count`.

# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

## Testing

- [x] Added/updated automated tests

- [x] QA'd all new/changed functionality manually
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.

Queries page: "Manage Automations" button not visible

4 participants