fleet/frontend/components/TableContainer/TableContainer.tsx

544 lines
18 KiB
TypeScript
Raw Normal View History

import React, { useState, useCallback, useRef, useEffect } from "react";
2021-04-14 16:52:15 +00:00
import classnames from "classnames";
import { Row } from "react-table";
import ReactTooltip from "react-tooltip";
import useDeepEffect from "hooks/useDeepEffect";
import { noop } from "lodash";
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
2021-12-29 18:10:54 +00:00
import SearchField from "components/forms/fields/SearchField";
// @ts-ignore
2021-04-14 16:52:15 +00:00
import Pagination from "components/Pagination";
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
import Button from "components/buttons/Button";
import Icon from "components/Icon/Icon";
import { COLORS } from "styles/var/colors";
2021-04-14 16:52:15 +00:00
import DataTable from "./DataTable/DataTable";
import { IActionButtonProps } from "./DataTable/ActionButton/ActionButton";
export interface ITableQueryData {
pageIndex: number;
pageSize: number;
searchQuery: string;
sortHeader: string;
sortDirection: string;
}
interface IRowProps extends Row {
original: {
id?: number;
os_version_id?: string; // Required for onSelectSingleRow of SoftwareOSTable.tsx
cve?: string; // Required for onSelectSingleRow of SoftwareVulnerabilityTable.tsx
};
}
interface ITableContainerProps<T = any> {
columnConfigs: any; // TODO: Figure out type
data: any; // TODO: Figure out type
isLoading: boolean;
manualSortBy?: boolean;
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
defaultSortHeader?: string;
defaultSortDirection?: string;
defaultSearchQuery?: string;
defaultPageIndex?: number;
defaultSelectedRows?: Record<string, boolean>;
/** Button visible above the table container next to search bar */
actionButton?: IActionButtonProps;
2021-08-30 23:02:53 +00:00
inputPlaceHolder?: string;
implement user table with new table and hook up create and edit and delete users (#587) * hook up user and invite data together for data table * added client derived data to user table * hooked up action dropdown to table * hooked up edit modal and password reset * started adding editing user functiaonlity * add query params to /invite call * clean up editing teams * update select team from to handle existing users with teams * update closes modal now * reuse getUser to clean up code in userManagementpage * pass form data to updating user that is not the current User * add dynamic userform submit text and fix tests * fix lint error in table component * added empty state for user table * clean up unused data table props * added delete modal * add delete user functionality * add delete option for invite * Add styles for rows in user table and action dropdown cell * hook up user and invite data together for data table * added client derived data to user table * hooked up action dropdown to table * hooked up edit modal and password reset * started adding editing user functiaonlity * add query params to /invite call * clean up editing teams * update select team from to handle existing users with teams * update closes modal now * reuse getUser to clean up code in userManagementpage * pass form data to updating user that is not the current User * add dynamic userform submit text and fix tests * fix lint error in table component * added empty state for user table * clean up unused data table props * added delete modal * add delete user functionality * add delete option for invite * Merge in generateClassTag * Refactor table styles * Add newline to DropdownCell style sheet Co-authored-by: Gabriel Hernandez <ghernandez345@gmail.com> * update checking for admin through global_role in nav * added defaultGloablRole for creat user modal * remove unused comment * fix broken tests * reenabled search for users tests Co-authored-by: noahtalerman <47070608+noahtalerman@users.noreply.github.com>
2021-04-09 10:44:57 +00:00
disableActionButton?: boolean;
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
disableMultiRowSelect?: boolean;
/** resultsTitle used in DataTable for matching results text */
resultsTitle?: string;
additionalQueries?: string;
emptyComponent: React.ElementType;
className?: string;
showMarkAllPages: boolean;
isAllPagesSelected: boolean; // TODO: make dependent on showMarkAllPages
toggleAllPagesSelected?: any; // TODO: an event type and make it dependent on showMarkAllPages
searchable?: boolean;
wideSearch?: boolean;
disablePagination?: boolean;
disableNextPage?: boolean; // disableNextPage is a temporary workaround for the case
// where the number of items on the last page is equal to the page size.
// The old page controls for server-side pagination render a no results screen
// with a back button. This fix instead disables the next button in that case.
disableCount?: boolean;
/** Main button after selecting a row */
primarySelectAction?: IActionButtonProps;
/** Secondary button/s after selecting a row */
secondarySelectActions?: IActionButtonProps[]; // TODO: Combine with primarySelectAction as these are all rendered in the same spot
searchToolTipText?: string;
// TODO - consolidate this functionality within `filters`
searchQueryColumn?: string;
// TODO - consolidate this functionality within `filters`
selectedDropdownFilter?: string;
isClientSidePagination?: boolean;
/** Used to set URL to correct path and include page query param */
onClientSidePaginationChange?: (pageIndex: number) => void;
/** Sets the table to filter the data on the client */
isClientSideFilter?: boolean;
/** isMultiColumnFilter is used to preserve the table headers
in lieu of displaying the empty component when client-side filtering yields zero results */
isMultiColumnFilter?: boolean;
disableHighlightOnHover?: boolean;
pageSize?: number;
onQueryChange?:
| ((queryData: ITableQueryData) => void)
| ((queryData: ITableQueryData) => number);
customControl?: () => JSX.Element | null;
/** Filter button right of the search rendering alternative responsive design where search bar moves to new line but filter button remains inline with other table headers */
customFiltersButton?: () => JSX.Element;
stackControls?: boolean;
onSelectSingleRow?: (value: Row | IRowProps) => void;
/** This is called when you click on a row. This was added as `onSelectSingleRow`
* only work if `disableMultiRowSelect` is also set to `true`. TODO: figure out
* if we want to keep this
*/
onClickRow?: (row: T) => void;
/** Used if users can click the row and another child element does not have the same onClick functionality */
keyboardSelectableRows?: boolean;
/** Use for clientside filtering: Use key global for filtering on any column, or use column id as
* key */
filters?: Record<string, string | number | boolean>;
renderCount?: () => JSX.Element | null;
/** Optional help text to render on bottom-left of the table. Hidden when table is loading and no
* rows of data are present. */
renderTableHelpText?: () => JSX.Element | null;
setExportRows?: (rows: Row[]) => void;
/** Use for serverside filtering: Set to true when filters change in URL
* bar and API call so TableContainer will reset its page state to 0 */
resetPageIndex?: boolean;
disableTableHeader?: boolean;
/** Set to true to persist the row selections across table data filters */
persistSelectedRows?: boolean;
/** handler called when the `clear selection` button is called */
onClearSelection?: () => void;
}
2021-04-14 16:52:15 +00:00
const baseClass = "table-container";
const DEFAULT_PAGE_SIZE = 20;
const DEFAULT_PAGE_INDEX = 0;
const TableContainer = <T,>({
columnConfigs,
data,
filters,
isLoading,
manualSortBy = false,
defaultSearchQuery = "",
defaultPageIndex = DEFAULT_PAGE_INDEX,
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
defaultSortHeader = "name",
defaultSortDirection = "asc",
defaultSelectedRows,
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
inputPlaceHolder = "Search",
additionalQueries,
resultsTitle,
emptyComponent,
className,
disableActionButton,
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
disableMultiRowSelect = false,
actionButton,
showMarkAllPages,
isAllPagesSelected,
toggleAllPagesSelected,
searchable,
wideSearch,
disablePagination,
disableNextPage,
disableCount,
primarySelectAction,
secondarySelectActions,
searchToolTipText,
isClientSidePagination,
onClientSidePaginationChange,
isClientSideFilter,
isMultiColumnFilter,
disableHighlightOnHover,
pageSize = DEFAULT_PAGE_SIZE,
selectedDropdownFilter,
searchQueryColumn,
onQueryChange,
customControl,
customFiltersButton,
stackControls,
onSelectSingleRow,
onClickRow,
keyboardSelectableRows,
renderCount,
renderTableHelpText,
setExportRows,
resetPageIndex,
disableTableHeader,
persistSelectedRows,
onClearSelection = noop,
}: ITableContainerProps<T>) => {
const [searchQuery, setSearchQuery] = useState(defaultSearchQuery);
2021-04-14 16:52:15 +00:00
const [sortHeader, setSortHeader] = useState(defaultSortHeader || "");
const [sortDirection, setSortDirection] = useState(
defaultSortDirection || ""
);
const [pageIndex, setPageIndex] = useState<number>(defaultPageIndex);
const [clientFilterCount, setClientFilterCount] = useState<number>();
// Client side pagination is being overridden to previous page without this
useEffect(() => {
if (isClientSidePagination && pageIndex !== defaultPageIndex) {
setPageIndex(defaultPageIndex);
}
}, [defaultPageIndex, pageIndex, isClientSidePagination]);
2021-12-29 18:10:54 +00:00
const prevPageIndex = useRef(0);
const wrapperClasses = classnames(baseClass, className);
const EmptyComponent = emptyComponent;
2021-04-14 16:52:15 +00:00
const onSortChange = useCallback(
(id?: string, isDesc?: boolean) => {
if (id === undefined) {
setSortHeader(defaultSortHeader || "");
setSortDirection(defaultSortDirection || "");
2021-04-14 16:52:15 +00:00
} else {
setSortHeader(id);
const direction = isDesc ? "desc" : "asc";
setSortDirection(direction);
}
},
[defaultSortHeader, defaultSortDirection, setSortHeader, setSortDirection]
2021-04-14 16:52:15 +00:00
);
const onSearchQueryChange = (value: string) => {
Ignore leading/trailing whitespace when filtering entities; fix url param handling; test broad range of affected endpoints (#17455) ## Addresses #16615 and #18041 ### #16615: - Trim whitespace for backend filtered tables - Trim whitespace in UI for Queries table search string <img width="1271" alt="Screenshot 2024-03-06 at 11 46 56 AM" src="https://github.com/fleetdm/fleet/assets/61553566/b818591c-a977-4203-8adb-3a0d909fcfbb"> <img width="1271" alt="Screenshot 2024-03-06 at 11 47 21 AM" src="https://github.com/fleetdm/fleet/assets/61553566/3c95b992-31ed-4c12-9763-6f5fc7d78b1f"> <img width="1800" alt="Screenshot 2024-03-06 at 3 18 31 PM" src="https://github.com/fleetdm/fleet/assets/61553566/05c677a4-80e8-4f94-8abc-235cab4145b7"> <img width="1800" alt="Screenshot 2024-03-06 at 5 05 25 PM" src="https://github.com/fleetdm/fleet/assets/61553566/4a5529a4-dd5f-463c-97ae-6ceaaaff7f93"> _______________________ ### #18041: #### Global: ![Screenshot 2024-04-03 at 12 21 19 PM](https://github.com/fleetdm/fleet/assets/61553566/9a45a3a6-4136-4851-b887-bd176299d0c2) #### Team: ![Screenshot 2024-04-03 at 12 56 36 PM](https://github.com/fleetdm/fleet/assets/61553566/793c70e7-384b-4705-a373-7e30a5188b03) #### **Similar fix for `GET` ...`vulnerabilities`** - [x] Changes file added for user-visible changes in `changes/` - [x] Add integration tests for all affected endpoints - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-04-10 18:50:08 +00:00
setSearchQuery(value.trim());
};
const hasPageIndexChangedRef = useRef(false);
const onPaginationChange = useCallback(
(newPage: number) => {
if (!isClientSidePagination) {
setPageIndex(newPage);
hasPageIndexChangedRef.current = true;
}
},
[hasPageIndexChangedRef, isClientSidePagination]
);
// NOTE: used to reset page number to 0 when modifying filters
useEffect(() => {
if (pageIndex !== 0 && resetPageIndex && !isClientSidePagination) {
onPaginationChange(0);
}
}, [resetPageIndex, pageIndex, isClientSidePagination]);
useDeepEffect(() => {
2021-12-29 18:10:54 +00:00
if (!onQueryChange) {
return;
}
const queryData = {
searchQuery,
sortHeader,
sortDirection,
pageSize,
pageIndex,
};
2021-12-29 18:10:54 +00:00
if (prevPageIndex.current === pageIndex) {
setPageIndex(0);
1497 improved query experience (#1998) * Step 1 for improving query experience (#1591) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * will address dynamic save disabled in edit step * Step 2 for improving query experience (select targets) (#1732) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * Improving query experience - Step 3 (query results) (#1766) * fake change to create draft PR * temp routes to work and not modify old query page * created new API abstraction for query * refactored App.jsx to prepare react-query * fixed flow of redirects after page refresh; functional component added * setup for getting data on edit * implementing functions for query page * Old form showing on new setup * improving and breaking up query form * no need for the helpers anymore; clean up * added type for button component variant * step toward new save modal; have to switch gears to #1619 * creating new query works * clean up * linting cleanup * added default value for new query * split steps into separate files for readability * components laid out * new targets picker * function clean up * styling tables * fixing logic * fixed logic to keep getting related hosts * formatting targets for API * fixed default query * clean up * styled target selectors; fixed target input styles * began total count * forgot to remove debugging code * lint fixes * added target count from API * clean up * able to remove selected host targets from table * lint fixes * connected run query with modern React/JS; clean up * linting fixes * fixed logic to retrieve results from live query * linting fixes * created new, simpler query progress * populating results and errors tables as expected * syntax fixes * fixing styles for query results * more styling for query results * manual merge from main * Rename core->free and basic->premium * Fix lint js * Comment out portion of test that seems to timeout * Rename tier to premium if basic is still loaded * go sum * Query Experience Cleanup Tasks (#1807) * fixes to get merged main branch to build and work * moved screens for query pages; clean up * updated and typed react ace for query form; clean up * using console error instead * added real types instead of `any` except for errors * query side panel ts and functional. prep for close task. * ability to hide, show query table sidebar * improved live query status warning * added loading and error state for targets search * error screen for targets; improved loading display * now using API-created label for all linux * missed some files on previous commit * able to edit query * clean up * lint fixes * query results showing as they come * remove unused code * removed old query page. major file cleanup. * removed selectedTargets redux implementation * removed unused redux actions and reducers * removed unused keys in initial state * selectedOsqueryTable is now using context API * removed all querypages redux code * set up context for app and user * fixed auth with temp fix for wrapper * completed redux removal from query page * fixed var names coming from main branch * fixed var name changes coming from issue 1501 * fixed save popup bug; clean up * added permissions * fixed login redirect * removed unused props * linting fix * clean up * removed unused component, refactor, and clean up * fixed styles for step 1 as admin * fixed styles for step 1 as observer * fixed percentage of online hosts * added loading progress to query stop button * reset query status on run again * added download icon to export button text * fixed error reset on name input; fixed styles * fixed bug where query value wasn't saving * fixed query value when blank * fixed bug - default query was running every time * auto adding host from url to targets * fixed flows for repeating run and save steps * fleet ace is now TS and functional * fixed a couple of tests * fixed issues with query value text inconsistencies * fixed query side panel not showing * hiding error count if not > 0 * fixed showing editor for different roles * using integer for targets * go sum * fixed targets param * catching all errors while running query * fixed hover state for title and description * ignore unit test for now; lint fixes * locking react-ace version * ignoring tests breaking in github actions * brought tests back * fixing file name * fixing file name again * fixed e2e test * have to ignore tests for now * ignore certain premium tests for now * one last test to revamp * another test * fixed teamflow test * fixed observer query 403 * lint fixes * fixed maintainer test * added changes file Co-authored-by: Tomas Touceda <chiiph@gmail.com>
2021-09-10 19:06:37 +00:00
}
2021-12-29 18:10:54 +00:00
// NOTE: used to reset page number to 0 when modifying filters
const newPageIndex = onQueryChange(queryData);
if (newPageIndex === 0) {
setPageIndex(0);
}
2021-12-29 18:10:54 +00:00
prevPageIndex.current = pageIndex;
2021-04-14 16:52:15 +00:00
}, [
searchQuery,
sortHeader,
sortDirection,
pageSize,
pageIndex,
additionalQueries,
]);
const renderPagination = useCallback(() => {
if (disablePagination || isClientSidePagination) {
return null;
}
return (
<Pagination
resultsOnCurrentPage={data.length}
currentPage={pageIndex}
resultsPerPage={pageSize}
onPaginationChange={onPaginationChange}
disableNextPage={disableNextPage}
/>
);
}, [
data,
disablePagination,
isClientSidePagination,
disableNextPage,
pageIndex,
pageSize,
onPaginationChange,
]);
const renderFilters = useCallback(() => {
const opacity = isLoading ? { opacity: 0.4 } : { opacity: 1 };
// New preferred pattern uses grid container/box to allow for more dynamic responsiveness
// At low widths, right header stacks on top of left header
if (stackControls) {
return (
<div className="container">
<div className="stackable-header">
{renderCount && !disableCount && (
<div
className={`${baseClass}__results-count ${
stackControls ? "stack-table-controls" : ""
}`}
style={opacity}
>
{renderCount()}
</div>
)}
</div>
{actionButton && !actionButton.hideButton && (
<div className="stackable-header">
<Button
disabled={disableActionButton}
onClick={actionButton.onActionButtonClick}
variant={actionButton.variant || "brand"}
className={`${baseClass}__table-action-button`}
>
<>
{actionButton.buttonText}
{actionButton.iconSvg && <Icon name={actionButton.iconSvg} />}
</>
</Button>
</div>
)}
<div className="stackable-header top-shift-header">
{customControl && customControl()}
{searchable && !wideSearch && (
<div className={`${baseClass}__search`}>
<div
className={`${baseClass}__search-input`}
data-tip
data-for="search-tooltip"
data-tip-disable={!searchToolTipText}
>
<SearchField
placeholder={inputPlaceHolder}
defaultValue={searchQuery}
onChange={onSearchQueryChange}
/>
</div>
<ReactTooltip
effect="solid"
backgroundColor={COLORS["tooltip-bg"]}
id="search-tooltip"
data-html
>
<span className={`tooltip ${baseClass}__tooltip-text`}>
{searchToolTipText}
</span>
</ReactTooltip>
</div>
)}
{customFiltersButton && customFiltersButton()}
</div>
</div>
);
}
return (
<>
{wideSearch && searchable && (
<div className={`${baseClass}__search-input wide-search`}>
<SearchField
placeholder={inputPlaceHolder}
defaultValue={searchQuery}
onChange={onSearchQueryChange}
/>
</div>
)}
{!disableTableHeader && (
<div
className={`${baseClass}__header ${
stackControls ? "stack-table-controls" : ""
}`}
>
<div
className={`${baseClass}__header-left ${
stackControls ? "stack-table-controls" : ""
}`}
>
{renderCount && !disableCount && (
<div
className={`${baseClass}__results-count ${
stackControls ? "stack-table-controls" : ""
}`}
style={opacity}
>
{renderCount()}
</div>
)}
<span className="controls">
{actionButton && !actionButton.hideButton && (
<Button
disabled={disableActionButton}
onClick={actionButton.onActionButtonClick}
variant={actionButton.variant || "brand"}
className={`${baseClass}__table-action-button`}
>
<>
{actionButton.buttonText}
{actionButton.iconSvg && (
<Icon name={actionButton.iconSvg} />
)}
</>
</Button>
)}
{customControl && customControl()}
</span>
</div>
{/* Render search bar only if not empty component */}
{searchable && !wideSearch && (
<div className={`${baseClass}__search`}>
<div
className={`${baseClass}__search-input ${
stackControls ? "stack-table-controls" : ""
}`}
data-tip
data-for="search-tooltip"
data-tip-disable={!searchToolTipText}
>
<SearchField
placeholder={inputPlaceHolder}
defaultValue={searchQuery}
onChange={onSearchQueryChange}
/>
</div>
<ReactTooltip
effect="solid"
backgroundColor={COLORS["tooltip-bg"]}
id="search-tooltip"
data-html
>
<span className={`tooltip ${baseClass}__tooltip-text`}>
{searchToolTipText}
</span>
</ReactTooltip>
</div>
)}
</div>
)}
</>
);
}, [
actionButton,
customControl,
customFiltersButton,
disableActionButton,
disableCount,
disableTableHeader,
inputPlaceHolder,
isLoading,
renderCount,
searchQuery,
searchToolTipText,
searchable,
stackControls,
wideSearch,
]);
return (
<div className={wrapperClasses}>
{renderFilters()}
<div className={`${baseClass}__data-table-block`}>
{/* No entities for this result. */}
{(!isLoading && data.length === 0 && !isMultiColumnFilter) ||
(searchQuery.length &&
data.length === 0 &&
!isMultiColumnFilter &&
!isLoading) ? (
<>
<EmptyComponent pageIndex={pageIndex} />
{pageIndex !== 0 && (
<div className={`${baseClass}__empty-page`}>
<div className={`${baseClass}__previous`}>
<Pagination
resultsOnCurrentPage={data.length}
currentPage={pageIndex}
resultsPerPage={pageSize}
onPaginationChange={onPaginationChange}
/>
</div>
</div>
)}
</>
2021-04-14 16:52:15 +00:00
) : (
<>
{/* TODO: Fix this hacky solution to clientside search being 0 rendering emptycomponent but
no longer accesses rows.length because DataTable is not rendered */}
{!isLoading && clientFilterCount === 0 && !isMultiColumnFilter && (
<EmptyComponent pageIndex={pageIndex} />
)}
<div
className={
isClientSideFilter && !isMultiColumnFilter
? `client-result-count-${clientFilterCount}`
: ""
}
>
<DataTable
isLoading={isLoading}
columns={columnConfigs}
data={data}
filters={filters}
manualSortBy={manualSortBy}
sortHeader={sortHeader}
sortDirection={sortDirection}
onSort={onSortChange}
disableMultiRowSelect={disableMultiRowSelect}
showMarkAllPages={showMarkAllPages}
isAllPagesSelected={isAllPagesSelected}
toggleAllPagesSelected={toggleAllPagesSelected}
resultsTitle={resultsTitle}
defaultPageSize={pageSize}
defaultPageIndex={defaultPageIndex}
defaultSelectedRows={defaultSelectedRows}
primarySelectAction={primarySelectAction}
secondarySelectActions={secondarySelectActions}
onSelectSingleRow={onSelectSingleRow}
onClickRow={onClickRow}
keyboardSelectableRows={keyboardSelectableRows}
onResultsCountChange={setClientFilterCount}
isClientSidePagination={isClientSidePagination}
onClientSidePaginationChange={onClientSidePaginationChange}
isClientSideFilter={isClientSideFilter}
disableHighlightOnHover={disableHighlightOnHover}
searchQuery={searchQuery}
searchQueryColumn={searchQueryColumn}
selectedDropdownFilter={selectedDropdownFilter}
renderTableHelpText={renderTableHelpText}
Live query performance improvements (#11995) ## Addresses #11856 Improve performance of the rendering of live query results by: - rendering the table on a set interval instead of with each new result - preventing redundant rerenders of various sorts Partial run, with memory leak: <img width="2552" alt="partial run with memory leak, after smaller optimizations, before debouncing queryResults" src="https://github.com/fleetdm/fleet/assets/61553566/5288bffb-6940-43da-9083-59adb4a25916"> Full run after debounce, no memory leak (10x improvement of max JS heap size): <img width="2559" alt="full run after debounce, no memory leak" src="https://github.com/fleetdm/fleet/assets/61553566/be056610-e7a5-4289-a433-1070cf016e83"> **NOTE** - there are further optimizations to try on this page, and the debounce interval can potentially be shortened to improve UX. In experimenting with that, it's not immediately clear what a good balance of UX / performance is. Since the customer seems keen to solve this, I think we should merge as-is and send them a demo build to confirm this fixes their problem, then iterate once they've confirmed it does. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/` - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Lucas Rodriguez <lucas@fleetdm.com> Co-authored-by: Jacob Shandling <jacob@fleetdm.com> Co-authored-by: Sarah Gillespie <sarah@fleetdm.com>
2023-06-06 20:23:09 +00:00
renderPagination={
isClientSidePagination ? undefined : renderPagination
}
setExportRows={setExportRows}
onClearSelection={onClearSelection}
persistSelectedRows={persistSelectedRows}
/>
</div>
</>
2021-04-14 16:52:15 +00:00
)}
</div>
</div>
);
};
export default TableContainer;