Skip to content

Commit 7c4897f

Browse files
Merge pull request #179 from OlivierCazade/lastRefresh
NETOBSERV-299 : Added last refresh date in query summary
2 parents e6253c6 + 7290c5d commit 7c4897f

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

web/locales/en/plugin__network-observability-plugin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
"{{count}} packets": "{{count}} packets",
168168
"{{count}} packets_plural": "{{count}} packets",
169169
"Filtered average speed": "Filtered average speed",
170+
"Last refresh: {{time}}": "Last refresh: {{time}}",
170171
"{{count}} IP(s)": "{{count}} IP(s)",
171172
"{{count}} IP(s)_plural": "{{count}} IP(s)",
172173
"{{count}} Port(s)": "{{count}} Port(s)",

web/src/components/netflow-traffic.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export const NetflowTraffic: React.FC<{
142142
const [metrics, setMetrics] = React.useState<TopologyMetrics[]>([]);
143143
const [isShowTopologyOptions, setShowTopologyOptions] = React.useState<boolean>(false);
144144
const [isShowQuerySummary, setShowQuerySummary] = React.useState<boolean>(false);
145+
const [lastRefresh, setLastRefresh] = React.useState<Date | undefined>(undefined);
145146
const [error, setError] = React.useState<string | undefined>();
146147
const [size, setSize] = useLocalStorage<Size>(LOCAL_STORAGE_SIZE_KEY, 'm');
147148
const [isTRModalOpen, setTRModalOpen] = React.useState(false);
@@ -278,10 +279,12 @@ export const NetflowTraffic: React.FC<{
278279
.then(result => {
279280
setFlows(result.records);
280281
setStats(result.stats);
282+
setLastRefresh(new Date());
281283
})
282284
.catch(err => {
283285
setFlows([]);
284286
setError(getHTTPErrorDetails(err));
287+
setLastRefresh(new Date());
285288
setWarningMessage(undefined);
286289
})
287290
.finally(() => {
@@ -601,6 +604,7 @@ export const NetflowTraffic: React.FC<{
601604
id="summaryPanel"
602605
flows={flows}
603606
stats={stats}
607+
lastRefresh={lastRefresh}
604608
range={range}
605609
onClose={() => setShowQuerySummary(false)}
606610
/>
@@ -743,6 +747,7 @@ export const NetflowTraffic: React.FC<{
743747
flows={flows}
744748
range={range}
745749
stats={stats}
750+
lastRefresh={lastRefresh}
746751
toggleQuerySummary={() => onToggleQuerySummary(!isShowQuerySummary)}
747752
/>
748753
<TimeRangeModal

web/src/components/query-summary/__tests__/query-summary.spec.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import { FlowsSample } from '../../../components/__tests-data__/flows';
44
import { QuerySummary, QuerySummaryContent } from '../query-summary';
55

66
describe('<QuerySummary />', () => {
7+
const now = new Date();
8+
79
const mocks = {
810
toggleQuerySummary: jest.fn(),
911
flows: FlowsSample,
1012
range: 300,
1113
stats: {
1214
limitReached: false,
1315
numQueries: 1
14-
}
16+
},
17+
lastRefresh: now
1518
};
1619

1720
it('should shallow component', async () => {
@@ -26,6 +29,7 @@ describe('<QuerySummary />', () => {
2629
expect(wrapper.find('#bytesCount').last().text()).toBe('161 kB');
2730
expect(wrapper.find('#packetsCount').last().text()).toBe('1100 packets');
2831
expect(wrapper.find('#bpsCount').last().text()).toBe('538 Bps');
32+
expect(wrapper.find('#lastRefresh').last().text()).toBe(now.toLocaleTimeString());
2933
});
3034

3135
it('should toggle panel', async () => {

web/src/components/query-summary/__tests__/summary-panel.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('<SummaryPanel />', () => {
1313
limitReached: false,
1414
numQueries: 1
1515
},
16+
lastRefresh: new Date(),
1617
id: 'summary-panel'
1718
};
1819

web/src/components/query-summary/query-summary.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ export const QuerySummaryContent: React.FC<{
1212
flows: Record[];
1313
limitReached: boolean;
1414
range: number | TimeRange;
15+
lastRefresh: Date | undefined;
1516
direction: 'row' | 'column';
1617
className?: string;
17-
}> = ({ flows, limitReached, range, direction, className }) => {
18+
}> = ({ flows, limitReached, range, lastRefresh, direction, className }) => {
1819
const { t } = useTranslation('plugin__network-observability-plugin');
1920

2021
let rangeInSeconds: number;
@@ -69,6 +70,21 @@ export const QuerySummaryContent: React.FC<{
6970
</Text>
7071
</Tooltip>
7172
</FlexItem>
73+
<FlexItem>
74+
<Tooltip
75+
content={
76+
<Text component={TextVariants.p}>
77+
{t('Last refresh: {{time}}', {
78+
time: lastRefresh ? lastRefresh.toLocaleString() : ''
79+
})}
80+
</Text>
81+
}
82+
>
83+
<Text id="lastRefresh" component={TextVariants.p}>
84+
{lastRefresh ? lastRefresh.toLocaleTimeString() : ''}
85+
</Text>
86+
</Tooltip>
87+
</FlexItem>
7288
</Flex>
7389
);
7490
};
@@ -77,12 +93,19 @@ export const QuerySummary: React.FC<{
7793
flows: Record[] | undefined;
7894
stats: Stats | undefined;
7995
range: number | TimeRange;
96+
lastRefresh: Date | undefined;
8097
toggleQuerySummary: () => void;
81-
}> = ({ flows, stats, range, toggleQuerySummary }) => {
82-
if (flows && flows.length && stats) {
98+
}> = ({ flows, stats, range, lastRefresh, toggleQuerySummary }) => {
99+
if (flows && flows.length && stats && lastRefresh) {
83100
return (
84101
<Card id="query-summary" isSelectable onClick={toggleQuerySummary}>
85-
<QuerySummaryContent direction="row" flows={flows} limitReached={stats.limitReached} range={range} />
102+
<QuerySummaryContent
103+
direction="row"
104+
flows={flows}
105+
limitReached={stats.limitReached}
106+
range={range}
107+
lastRefresh={lastRefresh}
108+
/>
86109
</Card>
87110
);
88111
}

web/src/components/query-summary/summary-panel.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export const SummaryPanelContent: React.FC<{
4242
flows: Record[] | undefined;
4343
stats: Stats | undefined;
4444
range: number | TimeRange;
45-
}> = ({ flows, stats, range }) => {
45+
lastRefresh: Date | undefined;
46+
}> = ({ flows, stats, range, lastRefresh }) => {
4647
const { t } = useTranslation('plugin__network-observability-plugin');
4748
const [expanded, setExpanded] = React.useState<string>('');
4849

@@ -227,6 +228,7 @@ export const SummaryPanelContent: React.FC<{
227228
flows={flows || []}
228229
limitReached={stats?.limitReached || false}
229230
range={range}
231+
lastRefresh={lastRefresh}
230232
/>
231233
</TextContent>
232234
<TextContent className="summary-text-container">
@@ -243,8 +245,9 @@ export const SummaryPanel: React.FC<{
243245
flows: Record[] | undefined;
244246
stats: Stats | undefined;
245247
range: number | TimeRange;
248+
lastRefresh: Date | undefined;
246249
id?: string;
247-
}> = ({ flows, stats, range, id, onClose }) => {
250+
}> = ({ flows, stats, range, lastRefresh, id, onClose }) => {
248251
const { t } = useTranslation('plugin__network-observability-plugin');
249252

250253
return (
@@ -263,7 +266,7 @@ export const SummaryPanel: React.FC<{
263266
</DrawerActions>
264267
</DrawerHead>
265268
<DrawerPanelBody>
266-
<SummaryPanelContent flows={flows} stats={stats} range={range} />
269+
<SummaryPanelContent flows={flows} stats={stats} range={range} lastRefresh={lastRefresh} />
267270
</DrawerPanelBody>
268271
</DrawerPanelContent>
269272
);

0 commit comments

Comments
 (0)