Skip to content

Commit 5b5edcd

Browse files
jpinsonneaujotak
authored andcommitted
improve array display (#869)
1 parent 0329ee5 commit 5b5edcd

File tree

4 files changed

+59
-20
lines changed

4 files changed

+59
-20
lines changed

mocks/loki/flow_records.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"values": [
1717
[
1818
"1708011867120999936",
19-
"{\"SrcK8S_Name\":\"ip-10-0-1-7.ec2.internal\",\"Bytes\":66,\"TimeFlowRttNs\":10000,\"Packets\":1,\"Interfaces\":[\"br-ex\",\"test\"],\"SrcMac\":\"02:27:A1:A8:84:B9\",\"Proto\":1,\"SrcK8S_HostIP\":\"10.0.1.7\",\"SrcK8S_HostName\":\"ip-10-0-1-7.ec2.internal\",\"Flags\":16,\"DnsErrno\":0,\"TimeFlowStartMs\":1708011867121,\"TimeReceived\":1708011867,\"DstAddr\":\"10.0.1.140\",\"Etype\":2048,\"SrcPort\":50104,\"AgentIP\":\"10.0.1.7\",\"SrcK8S_OwnerType\":\"Node\",\"Dscp\":0,\"TimeFlowEndMs\":1708011867121,\"IfDirections\":[\"1\",\"0\"],\"SrcAddr\":\"10.0.1.7\",\"DstMac\":\"02:7B:32:68:BE:65\",\"DstPort\":443,\"IcmpType\":3,\"IcmpCode\":0}"
19+
"{\"SrcK8S_Name\":\"ip-10-0-1-7.ec2.internal\",\"Bytes\":66,\"TimeFlowRttNs\":10000,\"Packets\":1,\"Interfaces\":[\"br-ex\",\"test1\",\"test2\",\"test3\",\"test4\",\"test5\"],\"SrcMac\":\"02:27:A1:A8:84:B9\",\"Proto\":1,\"SrcK8S_HostIP\":\"10.0.1.7\",\"SrcK8S_HostName\":\"ip-10-0-1-7.ec2.internal\",\"Flags\":16,\"DnsErrno\":0,\"TimeFlowStartMs\":1708011867121,\"TimeReceived\":1708011867,\"DstAddr\":\"10.0.1.140\",\"Etype\":2048,\"SrcPort\":50104,\"AgentIP\":\"10.0.1.7\",\"SrcK8S_OwnerType\":\"Node\",\"Dscp\":0,\"TimeFlowEndMs\":1708011867121,\"IfDirections\":[\"1\",\"0\",\"0\",\"0\",\"0\",\"0\"],\"SrcAddr\":\"10.0.1.7\",\"DstMac\":\"02:7B:32:68:BE:65\",\"DstPort\":443,\"IcmpType\":3,\"IcmpCode\":0}"
2020
],
2121
[
2222
"1708011867120999936",

web/locales/en/plugin__netobserv-plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"Add Namespace, Owner or Resource filters (which use indexed fields), or decrease limit / range, to improve the query performance": "Add Namespace, Owner or Resource filters (which use indexed fields), or decrease limit / range, to improve the query performance",
3535
"Add more filters or decrease limit / range to improve the query performance": "Add more filters or decrease limit / range to improve the query performance",
3636
"Unable to get {{item}}": "Unable to get {{item}}",
37+
"more": "more",
3738
"DNS Error": "DNS Error",
3839
"Namespace": "Namespace",
3940
"Show related documentation": "Show related documentation",

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@
3232
gap: .3rem;
3333
}
3434

35+
.record-field-flex-container .flowdirints {
36+
flex-direction: column !important;
37+
}
38+
39+
.record-field-flex-container .flowdirints > div {
40+
width: 100%;
41+
}
42+
43+
.side-by-side {
44+
padding: 0 !important;
45+
margin: 0 !important;
46+
}
47+
3548
.record-field-flex {
3649
align-self: center;
3750
}
@@ -58,7 +71,6 @@
5871
.record-field-flex-container.s,
5972
.record-field-flex-container.m,
6073
.record-field-flex-container.l {
61-
flex-direction: column;
6274
}
6375

6476
.record-field-flex-container.s {

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

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export type RecordFieldFilter = {
2424
isDelete: boolean;
2525
};
2626

27+
export const MAX_ARRAY_INDEX = 2;
28+
2729
export type FlexValue = 'flexDefault' | 'flexNone' | 'flex_1' | 'flex_2' | 'flex_3' | 'flex_4';
2830
export type FlexWrapValue = 'wrap' | 'wrapReverse' | 'nowrap';
2931

@@ -80,6 +82,10 @@ export const RecordField: React.FC<RecordFieldProps> = ({
8082
return <Text className="record-field-flex text-muted record-field-value">{t('n/a')}</Text>;
8183
};
8284

85+
const moreText = (count: number) => {
86+
return <Text className="record-field-flex record-field-value">{`${count} ${t('more')}...`}</Text>;
87+
};
88+
8389
const emptyDnsErrorText = () => {
8490
return emptyText(
8591
flow.fields.DnsErrno
@@ -215,21 +221,31 @@ export const RecordField: React.FC<RecordFieldProps> = ({
215221
);
216222
};
217223

218-
const nthContainer = (children: (JSX.Element | undefined)[], asChild = true, childIcon = true, forcedSize?: Size) => {
224+
const nthContainer = (
225+
children: (JSX.Element | undefined)[],
226+
asChild = true,
227+
childIcon = true,
228+
truncate?: boolean,
229+
forcedSize?: Size,
230+
className = ''
231+
) => {
219232
return (
220-
<Flex className={`record-field-flex-container ${forcedSize || size}`} flex={{ default: 'flex_1' }}>
233+
<Flex className={`record-field-flex-container ${forcedSize || size} ${className}`} flex={{ default: 'flex_1' }}>
221234
{children.length > 0 ? (
222-
children.map((c, i) => {
223-
const child = c ? c : emptyText();
224-
if (i > 0 && asChild && childIcon) {
225-
const arrow = <span className="child-arrow">{'↪'}</span>;
226-
return sideBySideContainer(arrow, child, 'flexNone', 'flex_1', 'nowrap');
227-
}
228-
return child;
229-
})
235+
children
236+
.filter((_c, i) => !truncate || i < MAX_ARRAY_INDEX)
237+
.map((c, i) => {
238+
const child = c ? c : emptyText();
239+
if (i > 0 && asChild && childIcon) {
240+
const arrow = <span className="child-arrow">{'↪'}</span>;
241+
return sideBySideContainer(arrow, child, 'flexNone', 'flex_1', 'nowrap');
242+
}
243+
return child;
244+
})
230245
) : (
231246
<Text className="text-muted record-field-value">{t('n/a')}</Text>
232247
)}
248+
{truncate && children.length > MAX_ARRAY_INDEX && moreText(children.length - MAX_ARRAY_INDEX)}
233249
</Flex>
234250
);
235251
};
@@ -241,7 +257,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
241257
childIcon = true,
242258
forcedSize?: Size
243259
) => {
244-
return nthContainer([child1, child2], asChild, childIcon, forcedSize);
260+
return nthContainer([child1, child2], asChild, childIcon, false, forcedSize);
245261
};
246262

247263
const sideBySideContainer = (
@@ -253,8 +269,12 @@ export const RecordField: React.FC<RecordFieldProps> = ({
253269
) => {
254270
return (
255271
<Flex direction={{ default: 'row' }} flex={{ default: 'flex_1' }} flexWrap={{ default: wrap }}>
256-
<FlexItem flex={{ default: leftFlex }}>{leftElement || emptyText()}</FlexItem>
257-
<FlexItem flex={{ default: rightFlex }}>{rightElement || emptyText()}</FlexItem>
272+
<FlexItem className="side-by-side" flex={{ default: leftFlex }}>
273+
{leftElement || emptyText()}
274+
</FlexItem>
275+
<FlexItem className="side-by-side" flex={{ default: rightFlex }}>
276+
{rightElement || emptyText()}
277+
</FlexItem>
258278
</Flex>
259279
);
260280
};
@@ -288,7 +308,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
288308
);
289309
};
290310

291-
const content = (c: Column) => {
311+
const content = (c: Column, isTable: boolean) => {
292312
if (!c.value) {
293313
// Value function not configured
294314
return emptyText();
@@ -420,6 +440,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
420440
value.map(dir => simpleTextWithTooltip(getDirectionDisplayString(String(dir) as FlowDirection, t))),
421441
true,
422442
false,
443+
isTable,
423444
multiLineSize
424445
);
425446
}
@@ -431,6 +452,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
431452
value.map(iName => simpleTextWithTooltip(String(iName))),
432453
true,
433454
false,
455+
isTable,
434456
multiLineSize
435457
);
436458
}
@@ -444,7 +466,8 @@ export const RecordField: React.FC<RecordFieldProps> = ({
444466
.filter(iName => iName !== '')
445467
.map(iName => simpleTextWithTooltip(iName)),
446468
true,
447-
false
469+
false,
470+
isTable
448471
);
449472
}
450473
return singleContainer(simpleTextWithTooltip(String(value)));
@@ -470,7 +493,10 @@ export const RecordField: React.FC<RecordFieldProps> = ({
470493
)
471494
),
472495
true,
473-
false
496+
false,
497+
isTable,
498+
undefined,
499+
'flowdirints'
474500
);
475501
} else {
476502
return singleContainer(emptyText(t('Invalid data provided. Check JSON for details.')));
@@ -594,7 +620,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
594620
return filter ? (
595621
<Flex className={`record-field-flex-container`} flex={{ default: 'flex_1' }}>
596622
<FlexItem className={'record-field-flex'} flex={{ default: 'flex_1' }}>
597-
{content(column)}
623+
{content(column, false)}
598624
</FlexItem>
599625
<FlexItem>
600626
<Tooltip
@@ -623,7 +649,7 @@ export const RecordField: React.FC<RecordFieldProps> = ({
623649
</FlexItem>
624650
</Flex>
625651
) : (
626-
content(column)
652+
content(column, true)
627653
);
628654
};
629655

0 commit comments

Comments
 (0)