Skip to content

Commit 11578b6

Browse files
committed
dev
1 parent ff0630c commit 11578b6

39 files changed

+599
-439
lines changed

web/moduleMapper/dummy.tsx

Lines changed: 71 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import {
44
K8sGroupVersionKind,
55
K8sModel,
6-
K8sResourceKind,
76
K8sResourceKindReference,
87
NamespaceBarProps,
98
PrometheusPollProps,
@@ -15,11 +14,12 @@ import {
1514
import { CodeEditor, Language } from '@patternfly/react-code-editor';
1615
import _ from 'lodash';
1716
import * as React from 'react';
18-
import { GetFlowCollectorJS } from '../src/components/forms/config/templates';
1917
import { useK8sModelsWithColors } from '../src/utils/k8s-models-hook';
2018
import { useTheme } from '../src/utils/theme-hook';
2119
import { safeJSToYAML } from '../src/utils/yaml';
2220
import { k8sModels } from './k8s-models';
21+
import { FlowCollectorSchema, FlowMetricSchema } from './schemas';
22+
import { GetFlowCollectorJS, GetFlowMetricJS } from './templates';
2323

2424
// This dummy file is used to resolve @Console imports from @openshift-console for JEST / Standalone
2525
// You can add any exports needed here
@@ -92,13 +92,65 @@ export function useK8sWatchResource(req: any) {
9292
console.log("useK8sWatchResource", req);
9393

9494
const [loaded, setLoaded] = React.useState(false);
95-
const [resource, setResource] = React.useState<K8sResourceKind | null>(null);
95+
const [resource, setResource] = React.useState<any | null>(null);
9696

9797
React.useEffect(() => {
98+
const kind = req.kind || req.groupVersionKind.kind;
9899
// simulate a loading
99100
if (resource == null) {
100101
setTimeout(() => {
101-
switch (req.groupVersionKind.kind) {
102+
switch (kind) {
103+
case 'CustomResourceDefinition':
104+
if (req.name === 'flowcollectors.flows.netobserv.io') {
105+
setResource({
106+
apiVersion: 'apiextensions.k8s.io/v1',
107+
kind: 'CustomResourceDefinition',
108+
metadata: {
109+
name: req.name
110+
},
111+
spec: {
112+
group: 'flows.netobserv.io',
113+
names: {
114+
kind: 'FlowCollector',
115+
plural: 'flowcollectors'
116+
},
117+
scope: 'Cluster',
118+
versions: [{
119+
name: 'v1beta2',
120+
served: true,
121+
storage: true,
122+
schema: {
123+
openAPIV3Schema: FlowCollectorSchema,
124+
}
125+
}]
126+
}
127+
});
128+
} else {
129+
setResource({
130+
apiVersion: 'apiextensions.k8s.io/v1',
131+
kind: 'CustomResourceDefinition',
132+
metadata: {
133+
name: req.name
134+
},
135+
spec: {
136+
group: 'flows.netobserv.io',
137+
names: {
138+
kind: 'FlowMetric',
139+
plural: 'flowmetrics'
140+
},
141+
scope: 'Namespaced',
142+
versions: [{
143+
name: 'v1alpha1',
144+
served: true,
145+
storage: true,
146+
schema: {
147+
openAPIV3Schema: FlowMetricSchema
148+
}
149+
}]
150+
}
151+
});
152+
}
153+
break;
102154
case 'FlowCollector':
103155
const fc = _.cloneDeep(GetFlowCollectorJS());
104156
fc.spec!.loki.enable = false;
@@ -170,19 +222,26 @@ export function useK8sWatchResource(req: any) {
170222
}
171223
]
172224
}
173-
setResource(fc);
225+
setResource([fc]);
226+
break;
227+
case 'FlowMetric':
228+
if (req.name === 'flowmetric-sample') {
229+
const fm = _.cloneDeep(GetFlowMetricJS());
230+
fm.spec!.metricName = 'test_metric';
231+
setResource([fm]);
232+
}
174233
break;
175234
}
176235
setLoaded(true);
177236
}, 1000);
178237
}
179-
}, [req.groupVersionKind.kind, req.kind, resource]);
238+
}, [req, resource]);
180239

181240
return React.useMemo(() => {
182241
if (!resource) {
183242
return [null, loaded, null];
184243
} else {
185-
return [[resource], loaded, null];
244+
return [resource, loaded, null];
186245
}
187246
}, [loaded, resource]);
188247
}
@@ -272,11 +331,11 @@ export enum K8sResourceConditionStatus {
272331
}
273332

274333
export enum PrometheusEndpoint {
275-
LABEL = "api/v1/label",
276-
QUERY = "api/v1/query",
277-
QUERY_RANGE = "api/v1/query_range",
278-
RULES = "api/v1/rules",
279-
TARGETS = "api/v1/targets"
334+
label = "api/v1/label",
335+
query = "api/v1/query",
336+
queryRange = "api/v1/query_range",
337+
rules = "api/v1/rules",
338+
targets = "api/v1/targets"
280339
}
281340

282341
export function usePrometheusPoll(props: PrometheusPollProps) {

web/src/components/forms/config/schema.ts renamed to web/moduleMapper/schemas.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/* eslint-disable max-len */
33
import { RJSFSchema } from '@rjsf/utils';
44

5-
// Keep the schemas ordered for YAML display
6-
75
export const FlowCollectorSchema: RJSFSchema | any = {
86
title: 'FlowCollector',
97
description:
@@ -6129,4 +6127,4 @@ export const FlowMetricSchema: RJSFSchema | any = {
61296127
}
61306128
}
61316129
}
6132-
};
6130+
};

web/src/components/forms/config/templates.ts renamed to web/moduleMapper/templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { K8sResourceKind } from '@openshift-console/dynamic-plugin-sdk';
2-
import { safeYAMLToJS } from '../../../utils/yaml';
2+
import { safeYAMLToJS } from '../src/utils/yaml';
33

44
export const FlowCollector = `
55
apiVersion: flows.netobserv.io/v1beta2

web/src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { BarsIcon } from '@patternfly/react-icons';
2727
import React from 'react';
2828
import { BrowserRouter, Link } from 'react-router-dom';
29-
import { GetFlowCollectorJS } from './components/forms/config/templates';
29+
import { GetFlowCollectorJS } from '../moduleMapper/templates';
3030
import Consumption from './components/forms/consumption';
3131
import FlowCollectorForm from './components/forms/flowCollector';
3232
import FlowCollectorStatus from './components/forms/flowCollector-status';

web/src/components/drawer/record/record-field.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import { dateFormatter, getFormattedDate, timeMSFormatter, utcDateTimeFormatter
1010
import { dnsCodesNames, dnsErrorsValues, getDNSErrorDescription, getDNSRcodeDescription } from '../../../utils/dns';
1111
import { getDSCPDocUrl, getDSCPServiceClassDescription, getDSCPServiceClassName } from '../../../utils/dscp';
1212
import { formatDurationAboveMillisecond, formatDurationAboveNanosecond } from '../../../utils/duration';
13-
import { getICMPCode, getICMPDocUrl, getICMPType, icmpAllTypesValues, isValidICMPProto } from '../../../utils/icmp';
14-
import { dropCausesNames, getDropCauseDescription, getDropCauseDocUrl } from '../../../utils/pkt-drop';
13+
import { getICMPCode, getICMPDocUrl, getICMPType, ICMPAllTypesValues, isValidICMPProto } from '../../../utils/icmp';
14+
import { DropCausesNames, getDropCauseDescription, getDropCauseDocUrl } from '../../../utils/pkt-drop';
1515
import { formatPort } from '../../../utils/port';
1616
import { formatProtocol, getProtocolDocUrl } from '../../../utils/protocol';
1717
import { getFlagsList, getTCPFlagsDocUrl } from '../../../utils/tcp-flags';
@@ -24,7 +24,7 @@ export type RecordFieldFilter = {
2424
isDelete: boolean;
2525
};
2626

27-
export const MAX_ARRAY_INDEX = 2;
27+
export const maxArrayIndex = 2;
2828

2929
export type FlexValue = 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
3030
export type FlexWrapValue = 'wrap' | 'wrapReverse' | 'nowrap';
@@ -233,7 +233,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
233233
<Flex className={`record-field-flex-container ${forcedSize || size} ${className}`} flex={{ default: 'flex_1' }}>
234234
{children.length > 0 ? (
235235
children
236-
.filter((_c, i) => !truncate || i < MAX_ARRAY_INDEX)
236+
.filter((_c, i) => !truncate || i < maxArrayIndex)
237237
.map((c, i) => {
238238
const child = c ? c : emptyText();
239239
if (i > 0 && asChild && childIcon) {
@@ -245,7 +245,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
245245
) : (
246246
<Text className="text-muted record-field-value">{t('n/a')}</Text>
247247
)}
248-
{truncate && children.length > MAX_ARRAY_INDEX && moreText(children.length - MAX_ARRAY_INDEX)}
248+
{truncate && children.length > maxArrayIndex && moreText(children.length - maxArrayIndex)}
249249
</Flex>
250250
);
251251
};
@@ -397,7 +397,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
397397
if (typeof value === 'number' && !isNaN(value)) {
398398
const proto = Number(flow.fields.Proto);
399399
if (isValidICMPProto(proto)) {
400-
const type = getICMPType(proto, value as icmpAllTypesValues);
400+
const type = getICMPType(proto, value as ICMPAllTypesValues);
401401
if (type && detailed) {
402402
child = clickableContent(type.name, type.description || '', getICMPDocUrl(proto));
403403
} else {
@@ -416,7 +416,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
416416
let child = emptyText();
417417
if (typeof value === 'number' && !isNaN(value)) {
418418
const proto = Number(flow.fields.Proto);
419-
const typez = Number(flow.fields.IcmpType) as icmpAllTypesValues;
419+
const typez = Number(flow.fields.IcmpType) as ICMPAllTypesValues;
420420
if (isValidICMPProto(proto)) {
421421
const code = getICMPCode(proto, typez, value);
422422
if (code && detailed) {
@@ -512,8 +512,8 @@ export const RecordField: React.FC<RecordFieldProps> = ({
512512
droppedText = t('dropped by');
513513
child = clickableContent(
514514
flow.fields.PktDropLatestDropCause,
515-
getDropCauseDescription(flow.fields.PktDropLatestDropCause as dropCausesNames),
516-
getDropCauseDocUrl(flow.fields.PktDropLatestDropCause as dropCausesNames)
515+
getDropCauseDescription(flow.fields.PktDropLatestDropCause as DropCausesNames),
516+
getDropCauseDocUrl(flow.fields.PktDropLatestDropCause as DropCausesNames)
517517
);
518518
}
519519

0 commit comments

Comments
 (0)