Skip to content

Commit

Permalink
fix: Use get observation to count observations instead of widget
Browse files Browse the repository at this point in the history
  • Loading branch information
d-beezee committed Oct 31, 2024
1 parent b6ea5f9 commit 641b297
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
27 changes: 11 additions & 16 deletions src/pages/Insights/Widgets/ProgressMonitoringWidget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,35 @@ import { appTheme } from 'src/app/theme';
import { BasicWidget } from 'src/pages/Campaign/widgetCards/BasicWidget';

import { CapitalizeFirstLetter } from 'src/pages/Campaign/widgetCards/common/CapitalizeFirstLetter';
import { getSeverityColor } from '../../utils/getSeverityColor';
import { useSeveritiesDistributionData } from '../hooks/useSeveritiesDistributionData';
import { getMaxSeverity } from '../utils/getMaxSeverity';
import { getSeverityColor } from '../../utils/getSeverityColor';

export const ProgressMonitoringWidget = ({
campaignId,
}: {
campaignId: string;
}) => {
const { t } = useTranslation();
const {
countObservationSeverity,
countPositiveFindings,
countMajorIssue,
countMinorIssue,
countObservations,
} = useSeveritiesDistributionData(campaignId);
const { countObservations, countByType } =
useSeveritiesDistributionData(campaignId);

const graphData = [
{
label: '',
keys: {
Observation: countObservationSeverity,
Positive: countPositiveFindings,
Minor: countMinorIssue,
Major: countMajorIssue,
Observation: countByType.observation,
Positive: countByType.positive,
Minor: countByType.minor,
Major: countByType.major,
},
},
];
const maxSeverity = getMaxSeverity(
countMajorIssue,
countMinorIssue,
countPositiveFindings,
countObservationSeverity
countByType.major,
countByType.minor,
countByType.positive,
countByType.observation
);
return (
<BasicWidget className="progress-monitoring-widget">
Expand Down
59 changes: 31 additions & 28 deletions src/pages/Insights/Widgets/hooks/useSeveritiesDistributionData.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
import { useGetCampaignsByCidWidgetsQuery } from 'src/features/api';
import { useGetCampaignsByCidObservationsQuery } from 'src/features/api';

export const useSeveritiesDistributionData = (campaignId: string) => {
const { data, isLoading, isFetching, isError } =
useGetCampaignsByCidWidgetsQuery({
useGetCampaignsByCidObservationsQuery({
cid: campaignId,
s: 'ux-severities-distribution',
});
const { data: results, kind } = data || {};
if (results && kind === 'uxSeveritiesDistribution') {
if (results.severitiesDistribution) {
const {
countPositiveFindings,
countMinorIssue,
countMajorIssue,
countObservationSeverity,
} = results.severitiesDistribution;

return {
countObservations: results.countObservations,
countPositiveFindings,
countMinorIssue,
countMajorIssue,
countObservationSeverity,
isLoading,
isFetching,
isError,
};
}
const countByType = {
positive: 0,
minor: 0,
major: 0,
observation: 0,
};

if (data && data.kind === 'ungrouped') {
countByType.minor = data.results.filter((o) => {
const severity = o.tags.find((t) => t.group.name === 'severity');
return severity && severity.tag.name === 'Minor issue';
}).length;
countByType.major = data.results.filter((o) => {
const severity = o.tags.find((t) => t.group.name === 'severity');
return severity && severity.tag.name === 'Major issue';
}).length;
countByType.positive = data.results.filter((o) => {
const severity = o.tags.find((t) => t.group.name === 'severity');
return severity && severity.tag.name === 'Positive Finding';
}).length;
countByType.observation = data.results.filter((o) => {
const severity = o.tags.find((t) => t.group.name === 'severity');
return severity && severity.tag.name === 'Observation';
}).length;
}

const total = Object.values(countByType).reduce((a, v) => a + v, 0);
return {
countPositiveFindings: 0,
countMinorIssue: 0,
countMajorIssue: 0,
countObservations: 0,
countObservationSeverity: 0,
countObservations: total,
countByType,
byType: countByType,
isLoading,
isFetching,
isError,
Expand Down

0 comments on commit 641b297

Please sign in to comment.