fleet/frontend/components/TableContainer/DataTable/DataTable.tsx

607 lines
19 KiB
TypeScript
Raw Normal View History

/* eslint-disable react/prop-types */
// disable this rule as it was throwing an error in Header and Cell component
// definitions for the selection row for some reason when we dont really need it.
import React, { useMemo, useEffect, useCallback, useContext } from "react";
import { TableContext } from "context/table";
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 classnames from "classnames";
import {
Column,
HeaderGroup,
Row,
useFilters,
useGlobalFilter,
usePagination,
useRowSelect,
useSortBy,
useTable,
} from "react-table";
import { kebabCase, noop, omit, pick } from "lodash";
import { useDebouncedCallback } from "use-debounce";
import useDeepEffect from "hooks/useDeepEffect";
import sort from "utilities/sort";
import { AppContext } from "context/app";
import Button from "components/buttons/Button";
// @ts-ignore
import FleetIcon from "components/icons/FleetIcon";
import Spinner from "components/Spinner";
import ActionButton from "./ActionButton";
import { IActionButtonProps } from "./ActionButton/ActionButton";
const baseClass = "data-table-block";
interface IDataTableProps {
columns: Column[];
data: any;
filters?: Record<string, string | number | boolean>;
isLoading: boolean;
manualSortBy?: boolean;
sortHeader: any;
sortDirection: any;
onSort: any; // TODO: an event type
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;
showMarkAllPages: boolean;
isAllPagesSelected: boolean; // TODO: make dependent on showMarkAllPages
toggleAllPagesSelected?: any; // TODO: an event type and make it dependent on showMarkAllPages
resultsTitle: string;
defaultPageSize: number;
defaultPageIndex?: number;
primarySelectAction?: IActionButtonProps;
secondarySelectActions?: IActionButtonProps[];
isClientSidePagination?: boolean;
onClientSidePaginationChange?: (pageIndex: number) => void; // Used to set URL to correct path and include page query param
isClientSideFilter?: boolean;
disableHighlightOnHover?: boolean;
searchQuery?: string;
searchQueryColumn?: string;
selectedDropdownFilter?: string;
onSelectSingleRow?: (value: Row) => void;
onResultsCountChange?: (value: number) => void;
renderFooter?: () => JSX.Element | null;
renderPagination?: () => JSX.Element | null;
setExportRows?: (rows: Row[]) => void;
}
interface IHeaderGroup extends HeaderGroup {
title?: string;
}
const CLIENT_SIDE_DEFAULT_PAGE_SIZE = 20;
// This data table uses react-table for implementation. The relevant documentation of the library
// can be found here https://react-table.tanstack.com/docs/api/useTable
const DataTable = ({
columns: tableColumns,
data: tableData,
filters: tableFilters,
isLoading,
manualSortBy = false,
sortHeader,
sortDirection,
onSort,
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,
showMarkAllPages,
isAllPagesSelected,
toggleAllPagesSelected,
resultsTitle,
defaultPageSize,
defaultPageIndex,
primarySelectAction,
secondarySelectActions,
isClientSidePagination,
onClientSidePaginationChange,
isClientSideFilter,
disableHighlightOnHover,
searchQuery,
searchQueryColumn,
selectedDropdownFilter,
onSelectSingleRow,
onResultsCountChange,
renderFooter,
renderPagination,
setExportRows,
}: IDataTableProps): JSX.Element => {
const { resetSelectedRows } = useContext(TableContext);
const { isOnlyObserver } = useContext(AppContext);
const columns = useMemo(() => {
return tableColumns;
}, [tableColumns]);
// The table data needs to be ordered by the order we received from the API.
const data = useMemo(() => {
return tableData;
}, [tableData]);
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
const initialSortBy = useMemo(() => {
return [{ id: sortHeader, desc: sortDirection === "desc" }];
}, [sortHeader, sortDirection]);
const {
headerGroups,
rows,
prepareRow,
selectedFlatRows,
toggleAllRowsSelected,
isAllRowsSelected,
state: tableState,
page, // Instead of using 'rows', we'll use page,
// which has only the rows for the active page
// The rest of these things are super handy, too ;)
canPreviousPage,
canNextPage,
// pageOptions,
// pageCount,
gotoPage,
nextPage,
previousPage,
setPageSize,
setFilter, // sets a specific column-level filter
setAllFilters, // sets all of the column-level filters; rows are included in filtered results only if each column filter return true
setGlobalFilter, // sets the global filter; this serves as a global free text search across all columns (excluding only those where `disableGlobalFilter: true`)
} = useTable(
{
columns,
data,
initialState: {
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
sortBy: initialSortBy,
pageIndex: defaultPageIndex,
},
disableMultiSort: true,
disableSortRemove: true,
manualSortBy,
// Initializes as false, but changes briefly to true on successful notification
autoResetSelectedRows: resetSelectedRows,
// Expands the enumerated `filterTypes` for react-table
// (see https://github.com/TanStack/react-table/blob/alpha/packages/react-table/src/filterTypes.ts)
// with custom `filterTypes` defined for this `useTable` instance
filterTypes: React.useMemo(
() => ({
hasLength: (
// eslint-disable-next-line @typescript-eslint/no-shadow
rows: Row[],
columnIds: string[],
filterValue: boolean
) => {
return !filterValue
? rows
: rows?.filter((row) => {
return columnIds?.some((id) => row?.values?.[id]?.length);
});
},
}),
[]
),
autoResetFilters: false,
// Expands the enumerated `sortTypes` for react-table
// (see https://github.com/tannerlinsley/react-table/blob/master/src/sortTypes.js)
// with custom `sortTypes` defined for this `useTable` instance
2021-08-18 14:00:02 +00:00
sortTypes: React.useMemo(
() => ({
2022-06-08 19:01:38 +00:00
boolean: (
a: { values: Record<string, unknown> },
b: { values: Record<string, unknown> },
id: string
) => sort.booleanAsc(a.values[id], b.values[id]),
caseInsensitive: (
a: { values: Record<string, unknown> },
b: { values: Record<string, unknown> },
id: string
) => sort.caseInsensitiveAsc(a.values[id], b.values[id]),
2021-08-18 14:00:02 +00:00
dateStrings: (
a: { values: Record<string, string> },
b: { values: Record<string, string> },
id: string
) => sort.dateStringsAsc(a.values[id], b.values[id]),
2021-08-18 14:00:02 +00:00
hasLength: (
a: { values: Record<string, unknown[]> },
b: { values: Record<string, unknown[]> },
id: string
) => {
return sort.hasLength(a.values[id], b.values[id]);
2021-08-18 14:00:02 +00:00
},
}),
[]
),
},
useGlobalFilter, // order of these hooks matters; here we first apply the global filter (if any); this could be reversed depending on where we want to target performance
useFilters, // react-table applies column-level filters after first applying the global filter (if any)
useSortBy,
usePagination,
useRowSelect
);
const { sortBy, selectedRowIds, pageIndex } = tableState;
useEffect(() => {
if (tableFilters) {
const filtersToSet = tableFilters;
const global = filtersToSet.global;
setGlobalFilter(global);
delete filtersToSet.global;
const allFilters = Object.entries(filtersToSet).map(([id, value]) => ({
id,
value,
}));
!!allFilters.length && setAllFilters(allFilters);
setExportRows && setExportRows(rows);
}
}, [tableFilters]);
useEffect(() => {
setExportRows && setExportRows(rows);
2022-07-14 16:21:26 +00:00
}, [tableState.filters, rows.length]);
// Listen for changes to filters if clientSideFilter is enabled
const setDebouncedClientFilter = useDebouncedCallback(
(column: string, query: string) => {
setFilter(column, query);
},
300
);
useEffect(() => {
if (isClientSideFilter && onResultsCountChange) {
onResultsCountChange(rows.length);
}
}, [isClientSideFilter, onResultsCountChange, rows.length]);
useEffect(() => {
if (isClientSideFilter && searchQueryColumn) {
setDebouncedClientFilter(searchQueryColumn, searchQuery || "");
}
}, [searchQuery, searchQueryColumn]);
useEffect(() => {
if (isClientSideFilter && selectedDropdownFilter) {
selectedDropdownFilter === "all"
? setDebouncedClientFilter("platforms", "")
: setDebouncedClientFilter("platforms", selectedDropdownFilter);
}
}, [selectedDropdownFilter]);
// This is used to listen for changes to sort. If there is a change
// Then the sortHandler change is fired.
useEffect(() => {
const column = sortBy[0];
if (column !== undefined) {
2021-04-14 16:52:15 +00:00
if (
column.id !== sortHeader ||
column.desc !== (sortDirection === "desc")
) {
onSort(column.id, column.desc);
}
} else {
onSort(undefined);
}
if (isClientSidePagination) {
gotoPage(0); // Return to page 0 after changing sort clientside
}
}, [sortBy, sortHeader, onSort, sortDirection]);
useEffect(() => {
if (isAllPagesSelected) {
toggleAllRowsSelected(true);
}
}, [isAllPagesSelected, toggleAllRowsSelected]);
useEffect(() => {
setPageSize(defaultPageSize || CLIENT_SIDE_DEFAULT_PAGE_SIZE);
}, [setPageSize]);
useDeepEffect(() => {
if (
Object.keys(selectedRowIds).length < rows.length &&
toggleAllPagesSelected
) {
toggleAllPagesSelected(false);
}
}, [tableState.selectedRowIds, toggleAllPagesSelected]);
const onToggleAllPagesClick = useCallback(() => {
toggleAllPagesSelected();
}, [toggleAllPagesSelected]);
const onClearSelectionClick = useCallback(() => {
toggleAllRowsSelected(false);
toggleAllPagesSelected(false);
}, [toggleAllPagesSelected, toggleAllRowsSelected]);
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
const onSingleRowClick = useCallback(
(row) => {
if (disableMultiRowSelect) {
row.toggleRowSelected();
onSelectSingleRow && onSelectSingleRow(row);
toggleAllRowsSelected(false);
}
},
[disableMultiRowSelect, onSelectSingleRow, toggleAllRowsSelected]
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
);
const renderColumnHeader = (column: IHeaderGroup) => {
// if there is a column filter, we want the `onClick` event listener attached
// just to the child title span so that clicking into the column filter input
// doesn't also sort the column
const spanProps = column.Filter
? pick(column.getSortByToggleProps(), "onClick")
: {};
return (
<div className="column-header">
<span {...spanProps}>{column.render("Header")}</span>
{column.Filter && column.render("Filter")}
</div>
);
};
const renderSelectedCount = (): JSX.Element => {
return (
<p>
<span>
{selectedFlatRows.length}
{isAllPagesSelected && "+"}
</span>{" "}
selected
</p>
);
};
const renderAreAllSelected = (): JSX.Element | null => {
if (isAllPagesSelected) {
return <p>All matching {resultsTitle} are selected</p>;
}
if (isAllRowsSelected) {
return <p>All {resultsTitle} on this page are selected</p>;
}
return null;
};
const renderActionButton = (
actionButtonProps: IActionButtonProps
): JSX.Element => {
const {
name,
onActionButtonClick,
buttonText,
targetIds,
variant,
hideButton,
iconSvg,
iconPosition,
indicatePremiumFeature,
} = actionButtonProps;
return (
<div className={`${baseClass}__${kebabCase(name)}`}>
<ActionButton
key={kebabCase(name)}
name={name}
buttonText={buttonText}
onActionButtonClick={onActionButtonClick || noop}
targetIds={targetIds}
variant={variant}
hideButton={hideButton}
indicatePremiumFeature={indicatePremiumFeature}
iconSvg={iconSvg}
iconPosition={iconPosition}
/>
</div>
);
};
const renderPrimarySelectAction = (): JSX.Element | null => {
const targetIds = selectedFlatRows.map((row: any) => row.original.id);
const buttonText =
typeof primarySelectAction?.buttonText === "function"
? primarySelectAction?.buttonText(targetIds)
: primarySelectAction?.buttonText;
const name = buttonText ? kebabCase(buttonText) : "primary-select-action";
const actionProps = {
name,
buttonText: buttonText || "",
onActionButtonClick: primarySelectAction?.onActionButtonClick || noop,
targetIds,
variant: primarySelectAction?.variant,
iconSvg: primarySelectAction?.iconSvg,
};
return !buttonText ? null : renderActionButton(actionProps);
};
const renderSecondarySelectActions = (): JSX.Element[] | null => {
if (secondarySelectActions) {
const targetIds = selectedFlatRows.map((row: any) => row.original.id);
const buttons = secondarySelectActions.map((actionProps) => {
actionProps = { ...actionProps, targetIds };
return renderActionButton(actionProps);
});
return buttons;
}
return null;
};
const shouldRenderToggleAllPages =
Object.keys(selectedRowIds).length >= defaultPageSize &&
showMarkAllPages &&
!isAllPagesSelected;
const pageOrRows = isClientSidePagination ? page : rows;
const previousButton = (
<>
<FleetIcon name="chevronleft" /> Previous
</>
);
const nextButton = (
<>
Next <FleetIcon name="chevronright" />
</>
);
const tableStyles = classnames({
"data-table__table": true,
"is-observer": isOnlyObserver,
});
return (
<div className={baseClass}>
2021-10-18 17:42:54 +00:00
{isLoading && (
<div className={"loading-overlay"}>
<Spinner />
</div>
)}
2021-04-14 16:52:15 +00:00
<div className={"data-table data-table__wrapper"}>
<table className={tableStyles}>
{Object.keys(selectedRowIds).length !== 0 && (
<thead className={"active-selection"}>
<tr {...headerGroups[0].getHeaderGroupProps()}>
<th
className={"active-selection__checkbox"}
{...headerGroups[0].headers[0].getHeaderProps(
headerGroups[0].headers[0].getSortByToggleProps()
)}
>
{headerGroups[0].headers[0].render("Header")}
</th>
<th className={"active-selection__container"}>
<div className={"active-selection__inner"}>
{renderSelectedCount()}
<div className={"active-selection__inner-left"}>
{secondarySelectActions && renderSecondarySelectActions()}
</div>
<div className={"active-selection__inner-right"}>
{primarySelectAction && renderPrimarySelectAction()}
</div>
{toggleAllPagesSelected && renderAreAllSelected()}
{shouldRenderToggleAllPages && (
<Button
onClick={onToggleAllPagesClick}
variant={"text-link"}
className={"light-text"}
>
<>Select all matching {resultsTitle}</>
</Button>
)}
<Button
onClick={onClearSelectionClick}
variant={"text-link"}
>
Clear selection
</Button>
</div>
</th>
</tr>
</thead>
)}
<thead>
2021-04-14 16:52:15 +00:00
{headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column) => {
let thProps = column.getSortByToggleProps({
title: undefined,
});
if (column.Filter) {
// if there is a column filter, we want the `onClick` event listener attached
// just to the child title span so that clicking into the column filter input
// doesn't also sort the column
thProps = omit(thProps, "onClick");
}
return (
<th
key={column.id}
className={column.id ? `${column.id}__header` : ""}
{...thProps}
>
{renderColumnHeader(column)}
</th>
);
})}
</tr>
))}
</thead>
<tbody>
{pageOrRows.map((row: Row) => {
prepareRow(row);
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
const rowStyles = classnames({
"single-row": disableMultiRowSelect,
"disable-highlight": disableHighlightOnHover,
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
});
return (
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
<tr
className={rowStyles}
{...row.getRowProps({
// @ts-ignore // TS complains about prop not existing
onClick: () => {
2022-06-10 18:29:45 +00:00
onSingleRowClick &&
disableMultiRowSelect &&
onSingleRowClick(row);
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
},
})}
>
{row.cells.map((cell: any) => {
return (
<td
key={cell.column.id}
className={
cell.column.id ? `${cell.column.id}__cell` : ""
}
{...cell.getCellProps()}
>
{cell.render("Cell")}
</td>
);
})}
</tr>
);
2021-04-14 16:52:15 +00:00
})}
</tbody>
</table>
</div>
<div className={`${baseClass}__footer`}>
{renderFooter && (
<div className={`${baseClass}__footer-text`}>{renderFooter()}</div>
)}
{isClientSidePagination ? (
<div className={`${baseClass}__pagination`}>
<Button
variant="unstyled"
onClick={() => {
onClientSidePaginationChange &&
onClientSidePaginationChange(pageIndex - 1);
previousPage();
}}
disabled={!canPreviousPage}
>
{previousButton}
</Button>
<Button
variant="unstyled"
onClick={() => {
onClientSidePaginationChange &&
onClientSidePaginationChange(pageIndex + 1);
nextPage();
}}
disabled={!canNextPage}
>
{nextButton}
</Button>
</div>
) : (
renderPagination && renderPagination()
)}
</div>
</div>
);
};
export default DataTable;