-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathConfigChangesPage.tsx
More file actions
115 lines (106 loc) · 3.8 KB
/
ConfigChangesPage.tsx
File metadata and controls
115 lines (106 loc) · 3.8 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
import { useGetAllConfigsChangesQuery } from "@flanksource-ui/api/query-hooks/useConfigChangesHooks";
import { ConfigChangeTable } from "@flanksource-ui/components/Configs/Changes/ConfigChangeTable";
import { ConfigChangeFilters } from "@flanksource-ui/components/Configs/Changes/ConfigChangesFilters/ConfigChangesFilters";
import ConfigPageTabs from "@flanksource-ui/components/Configs/ConfigPageTabs";
import ConfigsTypeIcon from "@flanksource-ui/components/Configs/ConfigsTypeIcon";
import { InfoMessage } from "@flanksource-ui/components/InfoMessage";
import {
BreadcrumbChild,
BreadcrumbNav,
BreadcrumbRoot
} from "@flanksource-ui/ui/BreadcrumbNav";
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 { useSearchParams } from "react-router-dom";
export function ConfigChangesPage() {
const [, setRefreshButtonClickedTrigger] = useAtom(
refreshButtonClickedTrigger
);
const [params] = useSearchParams({});
const configTypes = params.get("configTypes") ?? undefined;
const configType =
// we want to show breadcrumb only if there is only one config type selected
// in the filter dropdown and not multiple
configTypes?.split(",").length === 1
? configTypes.split(",")[0]?.split(":")?.[0].split("__").join("::")
: undefined;
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 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>,
...(configType
? [
<BreadcrumbChild
link={`/catalog?configType=${configType}`}
key={configType}
>
<ConfigsTypeIcon
config={{ type: configType }}
showSecondaryIcon
showLabel
/>
</BreadcrumbChild>
]
: [])
]}
/>
}
onRefresh={() => {
setRefreshButtonClickedTrigger((prev) => prev + 1);
refetch();
}}
loading={isLoading || isRefetching}
contentClass="p-0 h-full flex flex-col flex-1"
>
<ConfigPageTabs activeTab="Changes" configType={configType}>
{error ? (
<InfoMessage message={errorMessage} />
) : (
<>
<ConfigChangeFilters paramsToReset={["page"]} />
<ConfigChangeTable
data={changes}
isLoading={isLoading || isRefetching}
totalRecords={totalChanges}
numberOfPages={totalChangesPages}
/>
</>
)}
</ConfigPageTabs>
</SearchLayout>
</>
);
}