Skip to content

Commit

Permalink
display transverse criteria in report improvements tab
Browse files Browse the repository at this point in the history
  • Loading branch information
bellangerq committed Jul 12, 2024
1 parent eb76aa3 commit c3955ff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 88 deletions.
11 changes: 4 additions & 7 deletions confiture-web-app/src/components/report/ReportCriteria.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
import { useRoute } from "vue-router";
import { pluralize } from "../../utils";
import type { ReportErrors } from "./getReportErrors";
import {
ReportImprovement,
ReportTransverseImprovement
} from "./getReportImprovements";
import type { ReportError } from "./getReportErrors";
import { ReportImprovement } from "./getReportImprovements";
defineProps<{
count: number;
pagesData: ReportErrors[] | ReportImprovement[];
transverseData: ReportErrors[] | ReportTransverseImprovement[];
pagesData: ReportError[] | ReportImprovement[];
transverseData: ReportError[] | ReportImprovement[];
showFilters?: boolean;
}>();
Expand Down
20 changes: 8 additions & 12 deletions confiture-web-app/src/components/report/ReportErrors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { computed, ref } from "vue";
import { useReportStore } from "../../store";
import { CriterionResultUserImpact, CriteriumResultStatus } from "../../types";
import { getAllReportErrors } from "./getReportErrors";
import { getReportErrors } from "./getReportErrors";
import ReportCriteria from "./ReportCriteria.vue";
import ReportErrorCriterium from "./ReportErrorCriterium.vue";
Expand Down Expand Up @@ -64,11 +64,7 @@ const unknownUserImpactErrorCount = computed(
);
const errorsCount = computed(() => {
return getAllReportErrors(
report,
quickWinFilter.value,
userImpactFilters.value
)
return getReportErrors(report, quickWinFilter.value, userImpactFilters.value)
.map((page: any) => page.topics.map((topic: any) => topic.errors))
.flat(2).length;
});
Expand All @@ -86,10 +82,10 @@ function resetFilters() {
v-if="report.data"
:count="errorsCount"
:pages-data="
getAllReportErrors(report, quickWinFilter, userImpactFilters).slice(1)
getReportErrors(report, quickWinFilter, userImpactFilters).slice(1)
"
:transverse-data="
getAllReportErrors(report, quickWinFilter, userImpactFilters).slice(0, 1)
getReportErrors(report, quickWinFilter, userImpactFilters).slice(0, 1)
"
:show-filters="true"
>
Expand Down Expand Up @@ -191,8 +187,8 @@ function resetFilters() {
<template #transverse-data>
<section
v-if="
getAllReportErrors(report, quickWinFilter, userImpactFilters)[0]
.id === -1
getReportErrors(report, quickWinFilter, userImpactFilters)[0].id ===
-1
"
class="fr-mb-8w"
>
Expand All @@ -201,7 +197,7 @@ function resetFilters() {
</h2>

<div
v-for="(topic, i) in getAllReportErrors(
v-for="(topic, i) in getReportErrors(
report,
quickWinFilter,
userImpactFilters
Expand All @@ -225,7 +221,7 @@ function resetFilters() {

<template #pages-data>
<section
v-for="page in getAllReportErrors(
v-for="page in getReportErrors(
report,
quickWinFilter,
userImpactFilters
Expand Down
25 changes: 16 additions & 9 deletions confiture-web-app/src/components/report/ReportImprovements.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
<script setup lang="ts">
import { computed } from "vue";
import { useReportStore } from "../../store";
import {
getReportImprovements,
getReportTransverseImprovements
} from "./getReportImprovements";
import { getReportImprovements } from "./getReportImprovements";
import ReportCriteria from "./ReportCriteria.vue";
import ReportImprovementCriterium from "./ReportImprovementCriterium.vue";
const report = useReportStore();
const improvementsCount = computed(() => {
return getReportImprovements(report)
.map((page: any) => page.topics.map((topic: any) => topic.improvements))
.flat(2).length;
});
</script>

<template>
<ReportCriteria
v-if="report.data"
:pages-data="getReportImprovements(report)"
:transverse-data="getReportTransverseImprovements(report)"
:count="improvementsCount"
:pages-data="getReportImprovements(report).slice(1)"
:transverse-data="getReportImprovements(report).slice(0, 1)"
>
<template #transverse-data>
<section class="fr-mb-8w">
Expand All @@ -23,7 +29,8 @@ const report = useReportStore();
</h2>

<div
v-for="(topic, i) in getReportTransverseImprovements(report)"
v-for="(topic, i) in getReportImprovements(report).slice(0, 1)[0]
.topics"
:key="topic.number"
:class="{ 'fr-mt-9v': i !== 0 }"
>
Expand All @@ -35,7 +42,7 @@ const report = useReportStore();
v-for="(improvement, j) in topic.improvements"
:key="j"
:class="j === 0 ? null : 'fr-mt-9v'"
:topic="improvement.topic"
:topic="topic.number"
:criterium="improvement.criterium"
:comment="improvement.comment!"
:status="improvement.status"
Expand All @@ -46,7 +53,7 @@ const report = useReportStore();

<template #pages-data>
<section
v-for="page in getReportImprovements(report)"
v-for="page in getReportImprovements(report).slice(1)"
:key="page.id"
class="fr-mb-8w"
>
Expand Down
6 changes: 3 additions & 3 deletions confiture-web-app/src/components/report/getReportErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ReportCriteriumResult
} from "../../types";

export type ReportErrors = {
export type ReportError = {
id: number;
name?: string;
order: number;
Expand All @@ -21,11 +21,11 @@ export type ReportErrors = {
}[];
};

export function getAllReportErrors(
export function getReportErrors(
report: ReportStoreState,
quickWinFilter: boolean,
userImpactFilters: Array<CriterionResultUserImpact | null>
): ReportErrors[] {
): ReportError[] {
const resultsGroupedByPage = {
// include pages with no errors
...report.data?.context.samples.reduce<Record<string, []>>((acc, val) => {
Expand Down
60 changes: 3 additions & 57 deletions confiture-web-app/src/components/report/getReportImprovements.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { groupBy, mapValues, uniqWith } from "lodash-es";
import { groupBy } from "lodash-es";

import rgaa from "../../criteres.json";
import { ReportStoreState } from "../../store";
Expand Down Expand Up @@ -56,10 +56,8 @@ const hasOneOrMoreImprovements = (t: { improvements: unknown[] }) =>
t.improvements.length > 0;

const hasImprovement = (r: ReportCriteriumResult) =>
!r.transverse &&
((r.status === CriteriumResultStatus.COMPLIANT && r.compliantComment) ||
(r.status === CriteriumResultStatus.NOT_APPLICABLE &&
r.notApplicableComment));
(r.status === CriteriumResultStatus.COMPLIANT && r.compliantComment) ||
(r.status === CriteriumResultStatus.NOT_APPLICABLE && r.notApplicableComment);

const getImprovementObject = (r: ReportCriteriumResult) => {
return {
Expand All @@ -75,55 +73,3 @@ const resultIsFromPage = (pageId: number) => (result: ReportCriteriumResult) =>
function getTopicName(topicNumber: number) {
return rgaa.topics.find((t) => t.number === topicNumber)?.topic;
}

export type ReportTransverseImprovement = {
number: number;
name?: string;
improvements: {
topic: number;
criterium: number;
status: CriteriumResultStatus;
comment: string | null;
}[];
};

export function getReportTransverseImprovements(
reportData: ReportStoreState
): ReportTransverseImprovement[] {
return Object.values(
mapValues(
groupBy(
uniqWith(
reportData.data?.results.filter((r) => {
return (
r.transverse &&
[
CriteriumResultStatus.COMPLIANT,
CriteriumResultStatus.NOT_APPLICABLE
].includes(r.status)
);
}),
(a, b) => a.criterium === b.criterium && a.topic === b.topic
),
"topic"
),
(results, topicNumber) => {
return {
number: Number(topicNumber),
name: getTopicName(Number(topicNumber)),
improvements: results.map((r) => {
return {
topic: r.topic,
criterium: r.criterium,
status: r.status,
comment:
r.status === CriteriumResultStatus.COMPLIANT
? r.compliantComment
: r.notApplicableComment
};
})
};
}
)
);
}

0 comments on commit c3955ff

Please sign in to comment.