Skip to content

Commit c6f1c9c

Browse files
feat: switch to mantine table with paging
* feat: add support for pagination for configs list * feat: enable grouping and fix issue around expanded fix: fix expand initial state issues * fix: improve mrt by disabling dragging and dropping columns and hiding the column menu button fix: prevent mrt from dragging and drop columns chore: improve table * refactor: switch to MRT for Config Insights Table Fixes #2285 * refactor: use mantime react table for config changes Fixes #2285 fix: fix issue with config changes table * refactor: for playbooks, use mantime react table Fixes #2285 fix: fix props issue for playbooks fix: fix issues with playbook runs * refactor: use MRT for config relationships Fixes #2285 fix: typescript error refactor: move to MRT for tables for configs Fixes #2285 fix: fix empty text for default grouping value * fix: fix issue affecting sorting in MRT tables * fix: fix issue with config tables --------- Co-authored-by: Moshe Immerman <moshe@flanksource.com>
1 parent 8bfce8d commit c6f1c9c

35 files changed

+774
-732
lines changed

src/api/query-hooks/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { getHypothesisResponse } from "../services/hypothesis";
2020
import { getIncident } from "../services/incident";
2121
import { LogsResponse, SearchLogsPayload, searchLogs } from "../services/logs";
22+
import { getPagingParams } from "../services/notifications";
2223
import {
2324
getComponentTeams,
2425
getHealthCheckSpecByID,
@@ -160,6 +161,8 @@ type ConfigListFilterQueryOptions = {
160161
labels?: string;
161162
health?: string;
162163
status?: string;
164+
pageIndex?: number;
165+
pageSize?: number;
163166
};
164167

165168
export function prepareConfigListQuery({
@@ -172,7 +175,9 @@ export function prepareConfigListQuery({
172175
includeAgents = false,
173176
labels,
174177
health,
175-
status
178+
status,
179+
pageIndex,
180+
pageSize
176181
}: ConfigListFilterQueryOptions) {
177182
let query =
178183
"select=id,type,config_class,status,health,labels,name,tags,created_at,updated_at,deleted_at,cost_per_minute,cost_total_1d,cost_total_7d,cost_total_30d,changes,analysis";
@@ -219,6 +224,12 @@ export function prepareConfigListQuery({
219224
if (hideDeletedConfigs) {
220225
query = `${query}&deleted_at=is.null`;
221226
}
227+
const pagingParams = getPagingParams({ pageIndex, pageSize });
228+
229+
if (pagingParams) {
230+
query = `${query}${pagingParams}`;
231+
}
232+
222233
return query;
223234
}
224235

src/api/query-hooks/settingsResourcesHooks.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import useReactTableSortState from "@flanksource-ui/ui/DataTable/Hooks/useReactTableSortState";
12
import { useQuery } from "@tanstack/react-query";
23
import { SchemaApi } from "../../components/SchemaResourcePage/resourceTypes";
34
import {
@@ -7,10 +8,12 @@ import {
78
} from "../schemaResources";
89

910
export function useGetSettingsAllQuery(resourceInfo: SchemaApi) {
11+
const [sortState] = useReactTableSortState();
12+
1013
return useQuery<SchemaResourceWithJobStatus[], Error>(
11-
["settings", "all", resourceInfo],
14+
["settings", "all", resourceInfo, sortState],
1215
async () => {
13-
const res = await getAll(resourceInfo);
16+
const res = await getAll(resourceInfo, sortState);
1417
if (res.data.length === 0) {
1518
return [];
1619
}

src/api/query-hooks/useAllConfigsQuery.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useHideDeletedConfigs } from "@flanksource-ui/components/Configs/ConfigListToggledDeletedItems/ConfigListToggledDeletedItems";
2+
import useReactTablePaginationState from "@flanksource-ui/ui/DataTable/Hooks/useReactTablePaginationState";
23
import { useQuery } from "@tanstack/react-query";
34
import { useMemo } from "react";
45
import { useSearchParams } from "react-router-dom";
@@ -24,6 +25,7 @@ export const useAllConfigsQuery = ({
2425
const labels = searchParams.get("labels") ?? undefined;
2526
const status = searchParams.get("status") ?? undefined;
2627
const health = searchParams.get("health") ?? undefined;
28+
const { pageIndex, pageSize } = useReactTablePaginationState();
2729

2830
const query = useMemo(
2931
() =>
@@ -36,7 +38,9 @@ export const useAllConfigsQuery = ({
3638
includeAgents: true,
3739
labels: labels,
3840
health,
39-
status
41+
status,
42+
pageIndex,
43+
pageSize
4044
}),
4145
[
4246
search,
@@ -46,7 +50,9 @@ export const useAllConfigsQuery = ({
4650
hideDeletedConfigs,
4751
labels,
4852
health,
49-
status
53+
status,
54+
pageIndex,
55+
pageSize
5056
]
5157
);
5258

@@ -61,7 +67,9 @@ export const useAllConfigsQuery = ({
6167
true,
6268
labels,
6369
health,
64-
status
70+
status,
71+
pageIndex,
72+
pageSize
6573
],
6674
() => {
6775
return getAllConfigsMatchingQuery(query);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useSearchParams } from "react-router-dom";
2+
import { useConfigInsightsQuery } from "./useConfigAnalysisQuery";
3+
4+
export default function useFetchConfigInsights(
5+
setIsLoading: (isLoading: boolean) => void,
6+
configId?: string
7+
) {
8+
const [params] = useSearchParams();
9+
10+
const status = params.get("status") ?? undefined;
11+
const severity = params.get("severity") ?? undefined;
12+
const type = params.get("type") ?? undefined;
13+
const configType = params.get("configType") ?? undefined;
14+
const analyzer = params.get("analyzer") ?? undefined;
15+
const component = params.get("component") ?? undefined;
16+
const pageSize = +(params.get("pageSize") ?? 50);
17+
const pageIndex = +(params.get("pageIndex") ?? 0);
18+
19+
return useConfigInsightsQuery(
20+
{
21+
status,
22+
severity: severity?.toLowerCase(),
23+
type,
24+
analyzer,
25+
component,
26+
configId,
27+
configType
28+
},
29+
{
30+
sortBy: params.get("sortBy") ?? undefined,
31+
sortOrder: params.get("sortOrder") as "asc" | "desc" | undefined
32+
},
33+
{
34+
pageIndex,
35+
pageSize
36+
},
37+
{
38+
keepPreviousData: true,
39+
onSuccess: () => setIsLoading(false)
40+
}
41+
);
42+
}

src/api/schemaResources.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SchemaApi,
1010
SchemaBackends
1111
} from "@flanksource-ui/components/SchemaResourcePage/resourceTypes";
12+
import { SortingState } from "@tanstack/react-table";
1213
import { AxiosResponse } from "axios";
1314
import { AVATAR_INFO } from "../constants";
1415
import { CanaryCheckerDB, ConfigDB, IncidentCommander } from "./axios";
@@ -85,10 +86,10 @@ const getTableName = (table: string) => {
8586
}
8687
};
8788

88-
export const getAll = ({
89-
table,
90-
api
91-
}: SchemaApi): Promise<AxiosResponse<SchemaResourceWithJobStatus[]>> => {
89+
export const getAll = (
90+
{ table, api }: SchemaApi,
91+
sort?: SortingState
92+
): Promise<AxiosResponse<SchemaResourceWithJobStatus[]>> => {
9293
const endpoint = getBackend(api);
9394
if (endpoint) {
9495
const tableName = getTableName(table);
@@ -100,8 +101,14 @@ export const getAll = ({
100101
table === "topologies" ? `,agent:agent_id(id,name,description)` : ""
101102
}`
102103
);
104+
105+
if (sort && sort?.length > 0) {
106+
url.set("order", `${sort[0].id}.${sort[0].desc ? "desc" : "asc"}`);
107+
} else {
108+
url.set("order", "created_at.desc");
109+
}
110+
103111
url.set("deleted_at", "is.null");
104-
url.set("order", "created_at.desc");
105112
url.set("limit", "100");
106113
return endpoint.get<SchemaResourceWithJobStatus[]>(
107114
`/${tableName}?${url.toString()}`
@@ -174,14 +181,20 @@ export async function getEventQueueStatus() {
174181

175182
export async function getIntegrationsWithJobStatus(
176183
pageIndex: number,
177-
pageSize: number
184+
pageSize: number,
185+
sortBy?: SortingState
178186
) {
179187
const pagingParams = `&limit=${pageSize}&offset=${pageIndex * pageSize}`;
180188

189+
const sortParams =
190+
sortBy && sortBy.length > 0
191+
? `&order=${sortBy[0].id}.${sortBy[0].desc ? "desc" : "asc"}`
192+
: "";
193+
181194
const res = await resolvePostGrestRequestWithPagination(
182195
CanaryCheckerDB.get<SchemaResourceWithJobStatus[] | null>(
183196
// todo: add back created_by
184-
`integrations_with_status?order=created_at.desc&select=*&deleted_at=is.null${pagingParams}`,
197+
`integrations_with_status?order=created_at.desc&select=*&deleted_at=is.null${pagingParams}${sortParams}`,
185198
{
186199
headers: {
187200
Prefer: "count=exact"

src/api/services/configs.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ export const getAllConfigsMatchingQuery = (query: string) => {
2929
if (query) {
3030
url = `${url}&${query}`;
3131
}
32-
return resolvePostGrestRequestWithPagination<ConfigItem[]>(ConfigDB.get(url));
32+
return resolvePostGrestRequestWithPagination<ConfigItem[]>(
33+
ConfigDB.get(url, {
34+
headers: {
35+
Prefer: "count=exact"
36+
}
37+
})
38+
);
3339
};
3440

3541
export const getAllConfigsForSearchPurpose = async () => {

src/api/services/playbooks.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SubmitPlaybookRunFormValues } from "@flanksource-ui/components/Playbooks/Runs/Submit/SubmitPlaybookRunForm";
22
import { AVATAR_INFO } from "@flanksource-ui/constants";
3+
import { SortingState } from "@tanstack/react-table";
34
import { ConfigDB, IncidentCommander, PlaybookAPI } from "../axios";
45
import { GetPlaybooksToRunParams } from "../query-hooks/playbooks";
56
import { resolvePostGrestRequestWithPagination } from "../resolve";
@@ -150,7 +151,8 @@ export async function getPlaybookRuns({
150151
playbookId,
151152
status,
152153
starts,
153-
ends
154+
ends,
155+
sort
154156
}: {
155157
componentId?: string;
156158
configId?: string;
@@ -160,6 +162,7 @@ export async function getPlaybookRuns({
160162
status?: string;
161163
starts?: string;
162164
ends?: string;
165+
sort?: SortingState;
163166
}) {
164167
const searchParams = new URLSearchParams();
165168

@@ -202,6 +205,11 @@ export async function getPlaybookRuns({
202205

203206
const queryString = searchParams.toString();
204207

208+
const sortParams =
209+
sort && sort.length > 0
210+
? `&order=${sort[0].id}.${sort[0].desc ? "desc" : "asc"}`
211+
: "";
212+
205213
const res = await resolvePostGrestRequestWithPagination(
206214
ConfigDB.get<PlaybookRun[] | null>(`/playbook_runs?${queryString}`, {
207215
headers: {

0 commit comments

Comments
 (0)