Skip to content

Commit 956d7a2

Browse files
authored
Merge pull request #170 from jpinsonneau/317
NETOBSERV-317 fix rendering performances issue
2 parents b730fc7 + a9f0d12 commit 956d7a2

File tree

6 files changed

+48
-56
lines changed

6 files changed

+48
-56
lines changed

web/moduleMapper/dummy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export const ResourceLink: React.FC<ResourceLinkProps> = ({
4747
return (
4848
//TODO: add icon here
4949
<span className={className}>
50-
<span
50+
{k8sModels[kind!] && <span
5151
className="co-m-resource-icon"
5252
style={{ backgroundColor: k8sModels[kind!].color }}
5353
title={kind}>
5454
{k8sModels[kind!].abbr}
55-
</span>
55+
</span>}
5656
<span className="co-resource-item__resource-name" data-test-id={value} data-test={dataTest}>
5757
{value}
5858
</span>

web/src/components/netflow-table/__tests__/netflow-table-row.spec.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ describe('<NetflowTableRow />', () => {
1313
const mocks = {
1414
size: 'm' as Size,
1515
onSelect: jest.fn(),
16-
tableWidth: 100
16+
tableWidth: 100,
17+
showContent: true
1718
};
1819
it('should render component', async () => {
1920
flows = FlowsSample;

web/src/components/netflow-table/netflow-table-row.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* table stripping from pf-color-black-150 value */
2-
.light-stripped:nth-child(even) {
2+
:not(.newflow-appear).light-stripped:nth-child(even) {
33
background-color: #f5f5f5;
44
}
55

6-
.dark-stripped:nth-child(even) {
6+
:not(.newflow-appear).dark-stripped:nth-child(even) {
77
background-color: #050505;
88
}
99

web/src/components/netflow-table/netflow-table-row.tsx

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,34 @@ const NetflowTableRow: React.FC<{
1616
onSelect: (record?: Record) => void;
1717
highlight: boolean;
1818
height?: number;
19+
showContent?: boolean;
1920
tableWidth: number;
20-
}> = ({ flow, selectedRecord, columns, size, onSelect, highlight, height, tableWidth }) => {
21+
}> = ({ flow, selectedRecord, columns, size, onSelect, highlight, height, showContent, tableWidth }) => {
2122
const onRowClick = () => {
2223
onSelect(flow);
2324
};
2425

25-
const shouldHighlight = React.useRef(highlight);
26-
2726
return (
28-
<Tr
29-
data-test={`tr-${flow.key}`}
30-
isRowSelected={flow.key === selectedRecord?.key}
31-
onRowClick={onRowClick}
32-
className={`${isDark() ? 'dark' : 'light'}-stripped`}
33-
>
34-
{columns.map(c => (
35-
<CSSTransition
36-
key={c.id}
37-
in={shouldHighlight.current}
38-
appear={shouldHighlight.current}
39-
timeout={100}
40-
classNames="newflow"
41-
>
42-
<Td
43-
data-test={`td-${flow.key}`}
44-
key={c.id}
45-
style={{ height, width: `${Math.floor((100 * c.width) / tableWidth)}%` }}
46-
>
47-
{<RecordField flow={flow} column={c} size={size}></RecordField>}
48-
</Td>
49-
</CSSTransition>
50-
))}
51-
</Tr>
27+
<CSSTransition in={highlight} appear={highlight} timeout={100} classNames="newflow">
28+
<Tr
29+
data-test={`tr-${flow.key}`}
30+
isRowSelected={flow.key === selectedRecord?.key}
31+
onRowClick={onRowClick}
32+
className={`${isDark() ? 'dark' : 'light'}-stripped`}
33+
style={{ height }}
34+
>
35+
{showContent &&
36+
columns.map(c => (
37+
<Td
38+
data-test={`td-${flow.key}`}
39+
key={c.id}
40+
style={{ height: '100%', width: `${Math.floor((100 * c.width) / tableWidth)}%` }}
41+
>
42+
{<RecordField flow={flow} column={c} size={size}></RecordField>}
43+
</Td>
44+
))}
45+
</Tr>
46+
</CSSTransition>
5247
);
5348
};
5449

web/src/components/netflow-table/netflow-table.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,29 +148,26 @@ const NetflowTable: React.FC<{
148148

149149
const getBody = React.useCallback(() => {
150150
const rowHeight = getRowHeight();
151-
return getSortedFlows().map((f, i) =>
152-
scrollPosition <= i * rowHeight && scrollPosition + containerHeight > i * rowHeight ? (
153-
<NetflowTableRow
154-
key={f.key}
155-
flow={f}
156-
columns={columns}
157-
size={size}
158-
selectedRecord={selectedRecord}
159-
onSelect={onSelect}
160-
highlight={
161-
previousContainerHeight === containerHeight &&
162-
previousScrollPosition === scrollPosition &&
163-
previousActiveSortDirection === activeSortDirection &&
164-
previousActiveSortIndex === activeSortId &&
165-
!firstRender.current
166-
}
167-
height={rowHeight}
168-
tableWidth={width}
169-
/>
170-
) : (
171-
<tr className={`empty-row`} style={{ height: rowHeight }} key={f.key} />
172-
)
173-
);
151+
return getSortedFlows().map((f, i) => (
152+
<NetflowTableRow
153+
key={f.key}
154+
flow={f}
155+
columns={columns}
156+
size={size}
157+
selectedRecord={selectedRecord}
158+
onSelect={onSelect}
159+
highlight={
160+
previousContainerHeight === containerHeight &&
161+
previousScrollPosition === scrollPosition &&
162+
previousActiveSortDirection === activeSortDirection &&
163+
previousActiveSortIndex === activeSortId &&
164+
!firstRender.current
165+
}
166+
height={rowHeight}
167+
showContent={scrollPosition <= i * rowHeight && scrollPosition + containerHeight > i * rowHeight}
168+
tableWidth={width}
169+
/>
170+
));
174171
}, [
175172
activeSortDirection,
176173
activeSortId,

web/src/utils/k8s-models-hook.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,5 @@ export function useK8sModelsWithColors() {
7575
setColor('Ingress', '#1F0066');
7676
}
7777

78-
console.log(k8sModels);
7978
return k8sModels;
8079
}

0 commit comments

Comments
 (0)