Repository navigation
Expand file tree
/
Copy pathObjectsCountStats.tsx
More file actions
138 lines (123 loc) · 3.75 KB
/
Copy pathObjectsCountStats.tsx
File metadata and controls
138 lines (123 loc) · 3.75 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
129
130
131
132
133
134
135
136
137
138
import React from "react";
import {
EuiFlexGroup,
EuiFlexItem,
EuiStat,
EuiHorizontalRule,
EuiSpacer,
} from "@elastic/eui";
import { useNavigate, useParams } from "react-router-dom";
import useResourceQuery, {
entityListPath,
featureViewListPath,
featureServiceListPath,
dataSourceListPath,
labelViewListPath,
featuresListPath,
restFeatureViewsToMergedList,
restLabelViewsFromResponse,
} from "../queries/useResourceQuery";
import type { genericFVType } from "../parsers/mergedFVTypes";
const statStyle = { cursor: "pointer" };
const ObjectsCountStats = () => {
const { projectName } = useParams();
const navigate = useNavigate();
const fsQuery = useResourceQuery<any[]>({
resourceType: "stats-fs",
project: projectName,
restPath: featureServiceListPath(projectName),
restSelect: (d) => d.featureServices,
});
const fvQuery = useResourceQuery<genericFVType[]>({
resourceType: "stats-fvs",
project: projectName,
restPath: featureViewListPath(projectName),
restSelect: restFeatureViewsToMergedList,
});
const entQuery = useResourceQuery<any[]>({
resourceType: "stats-ent",
project: projectName,
restPath: entityListPath(projectName),
restSelect: (d) => d.entities,
});
const dsQuery = useResourceQuery<any[]>({
resourceType: "stats-ds",
project: projectName,
restPath: dataSourceListPath(projectName),
restSelect: (d) => d.dataSources,
});
const featQuery = useResourceQuery<any[]>({
resourceType: "stats-feat",
project: projectName,
restPath: featuresListPath(projectName),
restSelect: (d) => d.features || [],
});
const lvQuery = useResourceQuery<any[]>({
resourceType: "stats-lv",
project: projectName,
restPath: labelViewListPath(projectName),
restSelect: restLabelViewsFromResponse,
});
const settled = (q: { isSuccess: boolean; isError: boolean }) =>
q.isSuccess || q.isError;
const allSettled =
settled(fsQuery) &&
settled(fvQuery) &&
settled(entQuery) &&
settled(dsQuery) &&
settled(featQuery) &&
settled(lvQuery);
const stat = (
q: { data?: any[]; isPermissionDenied: boolean },
label: string,
path: string,
) => {
if (q.isPermissionDenied) return null;
return (
<EuiFlexItem>
<EuiStat
style={statStyle}
onClick={() => navigate(`/p/${projectName}/${path}`)}
description={`${label}→`}
title={q.data?.length || 0}
reverse
/>
</EuiFlexItem>
);
};
const hasLabelViews =
!lvQuery.isPermissionDenied && (lvQuery.data?.length || 0) > 0;
const queries = [fsQuery, fvQuery, featQuery, entQuery, dsQuery, lvQuery];
const hasAnyAccessible = queries.some((q) => !q.isPermissionDenied);
if (allSettled && !hasAnyAccessible) return null;
return (
<React.Fragment>
<EuiSpacer size="l" />
<EuiHorizontalRule margin="xs" />
{!allSettled && <p>Loading</p>}
{allSettled && (
<React.Fragment>
<EuiFlexGroup>
{stat(fsQuery, "Feature Services", "feature-service")}
{stat(fvQuery, "Feature Views", "feature-view")}
{stat(featQuery, "Features", "features")}
{stat(entQuery, "Entities", "entity")}
{stat(dsQuery, "Data Sources", "data-source")}
</EuiFlexGroup>
{hasLabelViews && (
<React.Fragment>
<EuiSpacer size="m" />
<EuiFlexGroup>
{stat(lvQuery, "Label Views", "label-view")}
<EuiFlexItem />
<EuiFlexItem />
<EuiFlexItem />
</EuiFlexGroup>
</React.Fragment>
)}
</React.Fragment>
)}
</React.Fragment>
);
};
export default ObjectsCountStats;