-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathConfigChangesPage.tsx
More file actions
128 lines (118 loc) · 4.17 KB
/
ConfigChangesPage.tsx
File metadata and controls
128 lines (118 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { useGetAllConfigsChangesQuery } from "@flanksource-ui/api/query-hooks/useConfigChangesHooks";
import { ConfigChangeTable } from "@flanksource-ui/components/Configs/Changes/ConfigChangeTable";
import { configChangesDefaultDateFilter } from "@flanksource-ui/components/Configs/Changes/ConfigChangesFilters/ConfigChangesDateRangeFIlter";
import { ConfigChangeFilters } from "@flanksource-ui/components/Configs/Changes/ConfigChangesFilters/ConfigChangesFilters";
import ConfigPageTabs from "@flanksource-ui/components/Configs/ConfigPageTabs";
import { InfoMessage } from "@flanksource-ui/components/InfoMessage";
import {
BreadcrumbChild,
BreadcrumbNav,
BreadcrumbRoot
} from "@flanksource-ui/ui/BreadcrumbNav";
import { PaginationOptions } from "@flanksource-ui/ui/DataTable";
import useTimeRangeParams from "@flanksource-ui/ui/Dates/TimeRangePicker/useTimeRangeParams";
import { Head } from "@flanksource-ui/ui/Head";
import { SearchLayout } from "@flanksource-ui/ui/Layout/SearchLayout";
import { refreshButtonClickedTrigger } from "@flanksource-ui/ui/SlidingSideBar/SlidingSideBar";
import { useAtom } from "jotai";
import { useMemo } from "react";
import { useSearchParams } from "react-router-dom";
export function ConfigChangesPage() {
const [, setRefreshButtonClickedTrigger] = useAtom(
refreshButtonClickedTrigger
);
const [params, setParams] = useSearchParams({
sortBy: "created_at",
sortDirection: "desc"
});
const { getTimeRangeFromUrl } = useTimeRangeParams(
configChangesDefaultDateFilter
);
const timeRangeValue = getTimeRangeFromUrl();
const page = params.get("page") ?? "1";
const pageSize = params.get("pageSize") ?? "200";
const { data, isLoading, error, isRefetching, refetch } =
useGetAllConfigsChangesQuery({
keepPreviousData: true
});
const changes = (data?.changes ?? []).map((changes) => ({
...changes,
config: {
id: changes.config_id!,
type: changes.type!,
name: changes.name!
}
}));
const totalChanges = data?.total ?? 0;
const totalChangesPages = Math.ceil(totalChanges / parseInt(pageSize));
const pagination = useMemo(() => {
const pagination: PaginationOptions = {
setPagination: (updater) => {
const newParams =
typeof updater === "function"
? updater({
pageIndex: parseInt(page) - 1,
pageSize: parseInt(pageSize)
})
: updater;
params.set("page", (newParams.pageIndex + 1).toString());
params.set("pageSize", newParams.pageSize.toString());
setParams(params);
},
pageIndex: parseInt(page) - 1,
pageSize: parseInt(pageSize),
pageCount: totalChangesPages,
remote: true,
enable: true,
loading: isLoading
};
return pagination;
}, [page, pageSize, totalChangesPages, isLoading, params, setParams]);
const errorMessage =
typeof error === "string"
? error
: ((error as Record<string, string>)?.message ?? "Something went wrong");
return (
<>
<Head prefix="Catalog Changes" />
<SearchLayout
title={
<BreadcrumbNav
list={[
<BreadcrumbRoot link="/catalog" key="config-catalog-changes-root">
Catalog
</BreadcrumbRoot>,
<BreadcrumbChild
link="/catalog/changes"
key="config-catalog-changes"
>
Changes
</BreadcrumbChild>
]}
/>
}
onRefresh={() => {
setRefreshButtonClickedTrigger((prev) => prev + 1);
refetch();
}}
loading={isLoading || isRefetching}
contentClass="p-0 h-full"
>
<ConfigPageTabs activeTab="Changes" daysLabel={timeRangeValue?.display}>
{error ? (
<InfoMessage message={errorMessage} />
) : (
<>
<ConfigChangeFilters paramsToReset={["page"]} />
<ConfigChangeTable
data={changes}
isLoading={isLoading}
pagination={pagination}
/>
</>
)}
</ConfigPageTabs>
</SearchLayout>
</>
);
}