fleet/frontend/services/entities
Jacob Shandling 7ff4b77fb9
UI: Merge scheduling functionality into queries page (#12713)
## Addresses #12636 

### See issue for list work done
![Screenshot 2023-07-12 at 6 47 04
PM](https://github.com/fleetdm/fleet/assets/61553566/47e3e5b2-0195-4f54-a377-8e5c03313acf)


![Frame-12-07-2023-06-43-32](https://github.com/fleetdm/fleet/assets/61553566/f72f2d41-609f-4409-8595-5f3e4f06d9bb)


### Notes for review:
- Because other work is based on this branch, TODOs / fixes are noted
here until the team comes to a strategy for merging all of the work:
- Add missing space in the Performance impact column "Undetermined"
tooltip text
- I'm having trouble confirming that the inherited queries table is
working right with the mock hard-coded data, though I did see it working
correctly previously. There's an issue with the page reverting to "All
teams" when trying to show the inherited table, though it does show the
table before re-rendering.

- This work is organized clearly by commit, so that might be a
manageable way to go through this code.
- Since the updated API for this work is not yet complete, this work can
be manually tested by either:
    - Using mock API infrastructure, or
- in `ManageQueriesPage.tsx`, comment out the two `useQuery` calls and
add appropriate mock data. You can then modify any fields of interest to
test their related UI functionality. For example, lines 119 -242 might
read:
```
// const {
  //   data: curTeamEnhancedQueries,
  //   error: curTeamQueriesError,
  //   isFetching: isFetchingCurTeamQueries,
  //   refetch: refetchCurTeamQueries,
  // } = useQuery<IListQueriesResponse, Error, IEnhancedQuery[]>(
  //   [{ scope: "queries", teamId: teamIdForApi }],
  //   () => queriesAPI.loadAll(teamIdForApi),
  //   {
  //     refetchOnWindowFocus: false,
  //     enabled: isRouteOk,
  //     select: (data) => data.queries.map(enhanceQuery),
  //   }
  // );

  // // If a team is selected, fetch inherited global queries as well
  // const {
  //   data: globalEnhancedQueries,
  //   error: globalQueriesError,
  //   isFetching: isFetchingGlobalQueries,
  //   refetch: refetchGlobalQueries,
  // } = useQuery<IListQueriesResponse, Error, IEnhancedQuery[]>(
  //   [{ scope: "queries", teamId: -1 }],
  //   () => queriesAPI.loadAll(),
  //   {
  //     refetchOnWindowFocus: false,
  //     enabled: isRouteOk && isAnyTeamSelected,
  //     select: (data) => data.queries.map(enhanceQuery),
  //   }
  // );

  const [
    curTeamEnhancedQueries,
    curTeamQueriesError,
    isFetchingCurTeamQueries,
    refetchCurTeamQueries,
  ] = useMemo(() => {
    return [
      [
        {
          created_at: "2023-06-08T15:31:35Z",
          updated_at: "2023-06-08T15:31:35Z",
          id: 2,
          name: "test",
          description: "",
          query: "SELECT * FROM osquery_info;",
          team_id: 43,
          platform: "darwin",
          min_osquery_version: "",
          automations_enabled: true,
          logging: "snapshot",
          saved: true,
          // interval: 300,
          interval: 0,
          observer_can_run: false,
          author_id: 1,
          author_name: "Jacob",
          author_email: "jacob@fleetdm.com",
          packs: [],
          stats: {
            // system_time_p50: 1,
            // system_time_p95: null,
            // user_time_p50: 1,
            // user_time_p95: null,
            // total_executions: 1,
          },
          performance: "Undetermined",
          platforms: ["darwin"],
        },
      ] as IEnhancedQuery[],
      undefined,
      false,
      () => {
        console.log("got the new queries");
      },
    ];
  }, []);

  const [
    globalEnhancedQueries,
    globalQueriesError,
    isFetchingGlobalQueries,
    refetchGlobalQueries,
  ] = useMemo(() => {
    return [
      [
        {
          created_at: "2023-06-08T15:31:35Z",
          updated_at: "2023-06-08T15:31:35Z",
          id: 200,
          name: "test",
          description: "",
          query: "SELECT * FROM osquery_info;",
          team_id: null,
          platform: "darwin",
          min_osquery_version: "",
          automations_enabled: true,
          logging: "snapshot",
          saved: true,
          // interval: 300,
          interval: 0,
          observer_can_run: false,
          author_id: 1,
          author_name: "Jacob",
          author_email: "jacob@fleetdm.com",
          packs: [],
          stats: {
            // system_time_p50: 1,
            // system_time_p95: null,
            // user_time_p50: 1,
            // user_time_p95: null,
            // total_executions: 1,
          },
          performance: "Undetermined",
          platforms: ["darwin"],
        },
      ] as IEnhancedQuery[],
      undefined,
      false,
      () => {
        console.log("got the new inherited queries");
      },
    ];
  }, []);
```

- [x] Changes file added for user-visible changes in `changes/`
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-07-13 12:11:11 -07:00
..
activities.ts add attribute to GET /activities endpoint with pagination metadata (#9279) 2023-01-18 12:57:11 +00:00
config.ts Fleet UI: Consistency between global and team agent options forms (#8334) 2022-10-20 13:39:47 -04:00
device_user.ts Track host DEP assignments in new table (#11875) 2023-05-23 13:01:04 -05:00
enroll_secret.ts Update UI to handle "No team" filters (#10706) 2023-03-31 12:40:14 -05:00
global_policies.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
global_scheduled_queries.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
host_count.ts UI for bootstrap package flows (#11288) 2023-04-27 16:10:41 +01:00
host_summary.ts Fleet UI: Missing host and low disk space filters on dashboard and manage host page (#7728) 2022-10-14 15:21:30 -05:00
hosts.ts UI for bootstrap package flows (#11288) 2023-04-27 16:10:41 +01:00
installers.ts adjust installers endpoint to avoid AJAX downloads (#7226) 2022-08-16 12:54:41 -03:00
invites.ts Fleet UI: Bug fix user page pagination (#7584) 2022-09-06 11:40:20 -04:00
labels.ts UI: Add ChromeOS features to the Dashboard page (#12105) 2023-06-06 16:44:21 -04:00
macadmins.ts Fleet UI: macOS dashboard MDM solutions (#7014) 2022-08-15 17:47:07 -05:00
mdm_apple_bm.ts Wire up UI and server for correct ABM credentials download (#9660) 2023-02-03 11:02:50 -08:00
mdm_apple.ts Fleet UI: MDM Apple APN API (#9533) 2023-01-27 16:05:26 -05:00
mdm.ts add verified status to UI for profile statuses (#11886) 2023-06-06 15:52:10 +01:00
operating_systems.ts UI: Add ChromeOS features to the Dashboard page (#12105) 2023-06-06 16:44:21 -04:00
osquery_options.ts Update UI to handle "No team" filters (#10706) 2023-03-31 12:40:14 -05:00
packs.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
queries.ts UI: Merge scheduling functionality into queries page (#12713) 2023-07-13 12:11:11 -07:00
scheduled_queries.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
sessions.ts Fix unreleased UI bugs in login page, top nav, and default team (#10928) 2023-04-03 10:13:57 -05:00
software.ts Update UI to handle "No team" filters (#10706) 2023-03-31 12:40:14 -05:00
spec.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
status_labels.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
status.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00
targets.ts Improve live query UX (#5749) 2022-06-10 13:29:45 -05:00
team_policies.ts Update UI to handle "No team" filters (#10706) 2023-03-31 12:40:14 -05:00
team_scheduled_queries.ts Update UI to handle "No team" filters (#10706) 2023-03-31 12:40:14 -05:00
teams.ts Update UI to handle "No team" filters (#10706) 2023-03-31 12:40:14 -05:00
users.ts Fleet UI: Bug fix user page pagination (#7584) 2022-09-06 11:40:20 -04:00
version.ts Removed all traces of Redux from the app! (#5287) 2022-04-22 09:45:35 -07:00