-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathuseFeatures.ts
More file actions
69 lines (60 loc) · 1.97 KB
/
Copy pathuseFeatures.ts
File metadata and controls
69 lines (60 loc) · 1.97 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
import { consoleFetchJSON } from '@openshift-console/dynamic-plugin-sdk';
import { useQuery } from '@tanstack/react-query';
type Features = {
alerting: boolean;
'acm-alerting': boolean;
'perses-dashboards': boolean;
'legacy-dashboards': boolean;
metrics: boolean;
targets: boolean;
'cluster-health-analyzer': boolean;
};
type FeaturesResponse = Partial<Features>;
const defaultMonitoringConsolePluginFeatures: Features = {
alerting: false,
'acm-alerting': false,
'perses-dashboards': false,
'legacy-dashboards': false,
metrics: false,
targets: false,
'cluster-health-analyzer': false,
};
const defaultMonitoringPluginFeatures: Features = {
alerting: true,
'acm-alerting': false,
'perses-dashboards': false,
'legacy-dashboards': true,
metrics: true,
targets: true,
'cluster-health-analyzer': false,
};
const MP_PROXY_PATH = '/api/plugins/monitoring-plugin';
const MCP_PROXY_PATH = '/api/plugins/monitoring-console-plugin';
const fetchFeatures = async (proxyPath: string, defaults: Features): Promise<Features> => {
try {
const response: FeaturesResponse = await consoleFetchJSON(`${proxyPath}/features`);
return { ...defaults, ...response };
} catch {
return defaults;
}
};
export const useFeatures = () => {
const { data: monitoringPluginFeatures } = useQuery({
queryKey: ['features', 'monitoring-plugin'],
queryFn: () => fetchFeatures(MP_PROXY_PATH, defaultMonitoringPluginFeatures),
placeholderData: defaultMonitoringPluginFeatures,
staleTime: Infinity,
});
const { data: monitoringConsolePluginFeatures } = useQuery({
queryKey: ['features', 'monitoring-console-plugin'],
queryFn: () => fetchFeatures(MCP_PROXY_PATH, defaultMonitoringConsolePluginFeatures),
placeholderData: defaultMonitoringConsolePluginFeatures,
staleTime: Infinity,
});
return {
features: {
'monitoring-plugin': monitoringPluginFeatures,
'monitoring-console-plugin': monitoringConsolePluginFeatures,
},
};
};