Skip to content

Commit

Permalink
NETOBSERV-1294 fix features check
Browse files Browse the repository at this point in the history
  • Loading branch information
jpinsonneau committed Sep 12, 2023
1 parent 83c6b3d commit 754ad9a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 22 deletions.
47 changes: 29 additions & 18 deletions web/src/components/dropdowns/metric-type-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@ import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { MetricType } from '../../model/flow-query';

const metricTypeOptions: MetricType[] = ['bytes', 'packets', 'dnsLatencies', 'flowRtt'];

export const MetricTypeDropdown: React.FC<{
selected?: string;
setMetricType: (v: MetricType) => void;
isTopology?: boolean;
allowDNSMetric?: boolean;
allowRTTMetric?: boolean;
id?: string;
}> = ({ selected, setMetricType, id, isTopology }) => {
}> = ({ selected, setMetricType, id, isTopology, allowDNSMetric, allowRTTMetric }) => {
const { t } = useTranslation('plugin__netobserv-plugin');
const [metricDropdownOpen, setMetricDropdownOpen] = React.useState(false);

const getMetricTypeOptions = React.useCallback(() => {
const options: MetricType[] = ['bytes', 'packets'];
if (isTopology) {
if (allowDNSMetric) {
options.push('dnsLatencies');
}
if (allowRTTMetric) {
options.push('flowRtt');
}
}
return options;
}, [allowDNSMetric, allowRTTMetric, isTopology]);

const getMetricDisplay = React.useCallback(
(metricType: MetricType): string => {
switch (metricType) {
Expand Down Expand Up @@ -47,21 +60,19 @@ export const MetricTypeDropdown: React.FC<{
</DropdownToggle>
}
isOpen={metricDropdownOpen}
dropdownItems={metricTypeOptions
.filter(v => isTopology || !['dnsLatencies', 'flowRtt'].includes(v))
.map(v => (
<DropdownItem
data-test={v}
id={v}
key={v}
onClick={() => {
setMetricDropdownOpen(false);
setMetricType(v);
}}
>
{getMetricDisplay(v)}
</DropdownItem>
))}
dropdownItems={getMetricTypeOptions().map(v => (
<DropdownItem
data-test={v}
id={v}
key={v}
onClick={() => {
setMetricDropdownOpen(false);
setMetricType(v);
}}
>
{getMetricDisplay(v)}
</DropdownItem>
))}
/>
);
};
Expand Down
16 changes: 14 additions & 2 deletions web/src/components/dropdowns/topology-display-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export const TopologyDisplayOptions: React.FC<{
setMetricScope: (s: FlowScope) => void;
topologyOptions: TopologyOptions;
setTopologyOptions: (o: TopologyOptions) => void;
allowDNSMetric: boolean;
allowRTTMetric: boolean;
}> = ({
metricFunction,
setMetricFunction,
Expand All @@ -33,7 +35,9 @@ export const TopologyDisplayOptions: React.FC<{
metricScope,
setMetricScope,
topologyOptions,
setTopologyOptions
setTopologyOptions,
allowDNSMetric,
allowRTTMetric
}) => {
const { t } = useTranslation('plugin__netobserv-plugin');

Expand Down Expand Up @@ -86,6 +90,8 @@ export const TopologyDisplayOptions: React.FC<{
isTopology
selected={metricType}
setMetricType={setMetricType}
allowDNSMetric={allowDNSMetric}
allowRTTMetric={allowRTTMetric}
/>
</FlexItem>
</Flex>
Expand Down Expand Up @@ -225,6 +231,8 @@ export const TopologyDisplayDropdown: React.FC<{
setMetricScope: (s: FlowScope) => void;
topologyOptions: TopologyOptions;
setTopologyOptions: (o: TopologyOptions) => void;
allowDNSMetric: boolean;
allowRTTMetric: boolean;
}> = ({
metricFunction,
setMetricFunction,
Expand All @@ -233,7 +241,9 @@ export const TopologyDisplayDropdown: React.FC<{
metricScope,
setMetricScope,
topologyOptions,
setTopologyOptions
setTopologyOptions,
allowDNSMetric,
allowRTTMetric
}) => {
const { t } = useTranslation('plugin__netobserv-plugin');
const [isOpen, setOpen] = React.useState<boolean>(false);
Expand All @@ -255,6 +265,8 @@ export const TopologyDisplayDropdown: React.FC<{
setMetricScope={setMetricScope}
topologyOptions={topologyOptions}
setTopologyOptions={setTopologyOptions}
allowDNSMetric={allowDNSMetric}
allowRTTMetric={allowRTTMetric}
/>
}
/>
Expand Down
12 changes: 10 additions & 2 deletions web/src/components/netflow-traffic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,10 @@ export const NetflowTraffic: React.FC<{
panels={panels.filter(
panel =>
panel.isSelected &&
(isPktDrop() || (!panel.id.includes('dropped') && (isDNSTracking() || !panel.id.includes('dns'))))
(isPktDrop() ||
(!panel.id.includes('dropped') &&
(isDNSTracking() || !panel.id.includes('dns')) &&
(isFlowRTT() || !panel.id.includes('rtt'))))
)}
recordType={recordType}
metricType={metricType}
Expand Down Expand Up @@ -1490,6 +1493,8 @@ export const NetflowTraffic: React.FC<{
setMetricScope={setMetricScope}
topologyOptions={topologyOptions}
setTopologyOptions={setTopologyOptions}
allowDNSMetric={isDNSTracking()}
allowRTTMetric={isFlowRTT()}
/>
)}
</OverflowMenuItem>
Expand Down Expand Up @@ -1533,7 +1538,10 @@ export const NetflowTraffic: React.FC<{
setModalOpen={setOverviewModalOpen}
recordType={recordType}
panels={panels.filter(
panel => (isPktDrop() || !panel.id.includes('dropped')) && (isDNSTracking() || !panel.id.includes('dns'))
panel =>
(isPktDrop() || !panel.id.includes('dropped')) &&
(isDNSTracking() || !panel.id.includes('dns')) &&
(isFlowRTT() || !panel.id.includes('rtt'))
)}
setPanels={setSelectedPanels}
/>
Expand Down

0 comments on commit 754ad9a

Please sign in to comment.