|
|
|
@@ -40,6 +40,9 @@ interface IQueriesTableProps {
|
|
|
|
|
order_key?: string;
|
|
|
|
|
order_direction?: "asc" | "desc";
|
|
|
|
|
team_id?: string;
|
|
|
|
|
inherited_order_key?: string;
|
|
|
|
|
inherited_order_direction?: "asc" | "desc";
|
|
|
|
|
inherited_page?: string;
|
|
|
|
|
};
|
|
|
|
|
isInherited?: boolean;
|
|
|
|
|
}
|
|
|
|
@@ -99,21 +102,37 @@ const QueriesTable = ({
|
|
|
|
|
// Functions to avoid race conditions
|
|
|
|
|
const initialSearchQuery = (() => queryParams?.query ?? "")();
|
|
|
|
|
const initialSortHeader = (() =>
|
|
|
|
|
(queryParams?.order_key as "name" | "updated_at" | "author") ?? "name")();
|
|
|
|
|
(queryParams?.order_key as "name" | "updated_at" | "author") ??
|
|
|
|
|
DEFAULT_SORT_HEADER)();
|
|
|
|
|
const initialSortDirection = (() =>
|
|
|
|
|
(queryParams?.order_direction as "asc" | "desc") ?? "asc")();
|
|
|
|
|
(queryParams?.order_direction as "asc" | "desc") ??
|
|
|
|
|
DEFAULT_SORT_DIRECTION)();
|
|
|
|
|
const initialPlatform = (() =>
|
|
|
|
|
(queryParams?.platform as "all" | "windows" | "linux" | "darwin") ??
|
|
|
|
|
"all")();
|
|
|
|
|
DEFAULT_PLATFORM)();
|
|
|
|
|
const initialPage = (() =>
|
|
|
|
|
queryParams && queryParams.page ? parseInt(queryParams?.page, 10) : 0)();
|
|
|
|
|
const initialInheritedSortHeader = (() =>
|
|
|
|
|
(queryParams?.inherited_order_key as "name" | "failing_host_count") ??
|
|
|
|
|
DEFAULT_SORT_HEADER)();
|
|
|
|
|
const initialInheritedSortDirection = (() =>
|
|
|
|
|
(queryParams?.inherited_order_direction as "asc" | "desc") ??
|
|
|
|
|
DEFAULT_SORT_DIRECTION)();
|
|
|
|
|
const initialInheritedPage = (() =>
|
|
|
|
|
queryParams && queryParams.inherited_page
|
|
|
|
|
? parseInt(queryParams?.inherited_page, 10)
|
|
|
|
|
: 0)();
|
|
|
|
|
|
|
|
|
|
// Never set as state as URL is source of truth
|
|
|
|
|
const searchQuery = initialSearchQuery;
|
|
|
|
|
const platform = initialPlatform;
|
|
|
|
|
const page = initialPage;
|
|
|
|
|
const sortDirection = initialSortDirection;
|
|
|
|
|
const sortHeader = initialSortHeader;
|
|
|
|
|
const page = isInherited ? initialInheritedPage : initialPage;
|
|
|
|
|
const sortDirection = isInherited
|
|
|
|
|
? initialInheritedSortDirection
|
|
|
|
|
: initialSortDirection;
|
|
|
|
|
const sortHeader = isInherited
|
|
|
|
|
? initialInheritedSortHeader
|
|
|
|
|
: initialSortHeader;
|
|
|
|
|
|
|
|
|
|
// TODO: Look into useDebounceCallback with dependencies
|
|
|
|
|
const onQueryChange = useCallback(
|
|
|
|
@@ -128,27 +147,43 @@ const QueriesTable = ({
|
|
|
|
|
// Rebuild queryParams to dispatch new browser location to react-router
|
|
|
|
|
const newQueryParams: { [key: string]: string | number | undefined } = {};
|
|
|
|
|
|
|
|
|
|
if (!isEmpty(newSearchQuery)) {
|
|
|
|
|
// Updates main query table URL params
|
|
|
|
|
// No change to inherited query table URL params
|
|
|
|
|
if (!isInherited) {
|
|
|
|
|
newQueryParams.order_key = newSortHeader;
|
|
|
|
|
newQueryParams.order_direction = newSortDirection;
|
|
|
|
|
newQueryParams.platform = platform; // must set from URL
|
|
|
|
|
newQueryParams.page = newPageIndex;
|
|
|
|
|
newQueryParams.query = newSearchQuery;
|
|
|
|
|
// Reset page number to 0 for new filters
|
|
|
|
|
if (
|
|
|
|
|
newSortDirection !== sortDirection ||
|
|
|
|
|
newSortHeader !== sortHeader ||
|
|
|
|
|
newSearchQuery !== searchQuery
|
|
|
|
|
) {
|
|
|
|
|
newQueryParams.page = "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newQueryParams.order_key = newSortHeader || DEFAULT_SORT_HEADER;
|
|
|
|
|
newQueryParams.order_direction =
|
|
|
|
|
newSortDirection || DEFAULT_SORT_DIRECTION;
|
|
|
|
|
newQueryParams.platform = platform || DEFAULT_PLATFORM; // must set from URL
|
|
|
|
|
newQueryParams.page = newPageIndex;
|
|
|
|
|
// Reset page number to 0 for new filters
|
|
|
|
|
if (
|
|
|
|
|
newSortDirection !== sortDirection ||
|
|
|
|
|
newSortHeader !== sortHeader ||
|
|
|
|
|
newSearchQuery !== searchQuery
|
|
|
|
|
) {
|
|
|
|
|
newQueryParams.page = 0;
|
|
|
|
|
// Updates inherited query table URL params
|
|
|
|
|
// No change to main query table URL params
|
|
|
|
|
if (isInherited) {
|
|
|
|
|
newQueryParams.inherited_order_key = newSortHeader;
|
|
|
|
|
newQueryParams.inherited_order_direction = newSortDirection;
|
|
|
|
|
newQueryParams.inherited_page = newPageIndex;
|
|
|
|
|
// Reset page number to 0 for new filters
|
|
|
|
|
if (
|
|
|
|
|
newSortDirection !== initialInheritedSortDirection ||
|
|
|
|
|
newSortHeader !== initialInheritedSortHeader
|
|
|
|
|
) {
|
|
|
|
|
newQueryParams.inherited_page = "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
newQueryParams.team_id = queryParams?.team_id;
|
|
|
|
|
const locationPath = getNextLocationPath({
|
|
|
|
|
pathPrefix: PATHS.MANAGE_QUERIES,
|
|
|
|
|
queryParams: newQueryParams,
|
|
|
|
|
queryParams: { ...queryParams, ...newQueryParams },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
router?.replace(locationPath);
|
|
|
|
@@ -158,16 +193,21 @@ const QueriesTable = ({
|
|
|
|
|
|
|
|
|
|
const onClientSidePaginationChange = useCallback(
|
|
|
|
|
(pageIndex: number) => {
|
|
|
|
|
const newQueryParams = isInherited
|
|
|
|
|
? {
|
|
|
|
|
...queryParams,
|
|
|
|
|
inherited_page: pageIndex, // update inherited page index
|
|
|
|
|
query: searchQuery,
|
|
|
|
|
}
|
|
|
|
|
: {
|
|
|
|
|
...queryParams,
|
|
|
|
|
page: pageIndex, // update main table index
|
|
|
|
|
query: searchQuery,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const locationPath = getNextLocationPath({
|
|
|
|
|
pathPrefix: PATHS.MANAGE_QUERIES,
|
|
|
|
|
queryParams: {
|
|
|
|
|
...queryParams,
|
|
|
|
|
page: pageIndex,
|
|
|
|
|
platform,
|
|
|
|
|
query: searchQuery,
|
|
|
|
|
order_direction: sortDirection,
|
|
|
|
|
order_key: sortHeader,
|
|
|
|
|
},
|
|
|
|
|
queryParams: newQueryParams,
|
|
|
|
|
});
|
|
|
|
|
router?.replace(locationPath);
|
|
|
|
|
},
|
|
|
|
@@ -251,11 +291,11 @@ const QueriesTable = ({
|
|
|
|
|
resultsTitle="queries"
|
|
|
|
|
columns={tableHeaders}
|
|
|
|
|
data={queriesList}
|
|
|
|
|
filters={{ global: isInherited ? "" : searchQuery }}
|
|
|
|
|
filters={{ name: isInherited ? "" : searchQuery }}
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
defaultSortHeader={sortHeader || DEFAULT_SORT_HEADER}
|
|
|
|
|
defaultSortDirection={sortDirection || DEFAULT_SORT_DIRECTION}
|
|
|
|
|
defaultSearchQuery={searchQuery}
|
|
|
|
|
defaultSearchQuery={isInherited ? "" : searchQuery}
|
|
|
|
|
defaultPageIndex={page}
|
|
|
|
|
pageSize={DEFAULT_PAGE_SIZE}
|
|
|
|
|
inputPlaceHolder="Search by name"
|
|
|
|
|