From 63628ebd6db8ef15a64a0082493b67fb25f0e7c9 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Tue, 19 Sep 2023 18:03:48 +0200 Subject: [PATCH 01/11] Reports: select Questionnaires Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/reports.tsx | 73 +++++++++++++++++++++++- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index 5b5aa4b2ea..6a5f6c0135 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -9,9 +9,15 @@ import { CardExpandableContent, CardHeader, CardTitle, + Flex, + FlexItem, + MenuToggle, + MenuToggleElement, PageSection, PageSectionVariants, Popover, + Select, + SelectOption, Split, SplitItem, Stack, @@ -31,11 +37,20 @@ import { Landscape } from "./components/landscape"; import { AdoptionPlan } from "./components/adoption-plan"; import { IdentifiedRisksTable } from "./components/identified-risks-table"; import { useFetchApplications } from "@app/queries/applications"; +import { useFetchQuestionnaires } from "@app/queries/questionnaires"; export const Reports: React.FC = () => { // i18 const { t } = useTranslation(); + const [isQuestionnaireSelectOpen, setIsQuestionnaireSelectOpen] = + React.useState(false); + + const [selectedQuestionnaire, setSelectedQuestionnaire] = + React.useState("All questionnaires"); + + const { questionnaires } = useFetchQuestionnaires(); + // Cards const [isAdoptionCandidateTable, setIsAdoptionCandidateTable] = useState(true); @@ -66,6 +81,27 @@ export const Reports: React.FC = () => { ); } + const toggle = (toggleRef: React.Ref) => ( + { + setIsQuestionnaireSelectOpen(!isQuestionnaireSelectOpen); + }} + isExpanded={isQuestionnaireSelectOpen} + > + {selectedQuestionnaire} + + ); + + const onSelectQuestionnaire = ( + _event: React.MouseEvent | undefined, + value: string | number | undefined + ) => { + setSelectedQuestionnaire(value as string); + setIsQuestionnaireSelectOpen(false); + }; + return ( <> {pageHeaderSection} @@ -78,9 +114,40 @@ export const Reports: React.FC = () => { - - {t("terms.currentLandscape")} - + + + + + {t("terms.currentLandscape")} + + + + + + + From 02998ab429e10c346ef1b65f2b77ee2abf83aa1c Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Tue, 19 Sep 2023 18:56:25 +0200 Subject: [PATCH 02/11] select from assessments; set donut colors Signed-off-by: Gilles Dubreuil --- client/public/locales/en/translation.json | 7 ++----- client/public/locales/es/translation.json | 7 ++----- client/src/app/api/rest.ts | 3 +++ .../pages/reports/components/landscape/donut.tsx | 3 --- .../reports/components/landscape/landscape.tsx | 16 ++++++---------- client/src/app/pages/reports/reports.tsx | 10 +++++----- client/src/app/queries/assessments.ts | 13 +++++++++++++ 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index c64b5bc8af..fc6872bb39 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -71,7 +71,8 @@ "orange": "Orange", "purple": "Purple", "red": "Red", - "teal": "Teal" + "teal": "Teal", + "yellow": "Yellow" }, "composed": { "add": "Add {{what}}", @@ -243,7 +244,6 @@ "businessServices": "Business services", "canceled": "Canceled", "category": "Category", - "cloudNativeReady": "Cloud-native ready", "color": "Color", "comments": "Comments", "completed": "Completed", @@ -311,7 +311,6 @@ "member(s)": "Member(s)", "memberCount": "Member count", "message": "Message", - "modernizable": "Modernizable", "migrationWave": "Migration wave", "migrationWaves": "Migration waves", "migrationWave(s)": "Migration wave(s)", @@ -322,7 +321,6 @@ "notConnected": "Not connected", "notReviewed": "Not reviewed", "notStarted": "Not started", - "notYetAssessed": "Not yet assessed", "notYetReviewed": "Not yet reviewed", "other": "Other", "owner": "Owner", @@ -384,7 +382,6 @@ "unassessed": "Unassessed", "unassigned": "Not yet assigned", "unknown": "Unknown", - "unsuitableForContainers": "Unsuitable for containers", "uploadApplicationFile": "Upload your application file", "uploadYamlFile": "Upload your YAML file", "url": "URL", diff --git a/client/public/locales/es/translation.json b/client/public/locales/es/translation.json index 5bfde9d167..12f96255f9 100644 --- a/client/public/locales/es/translation.json +++ b/client/public/locales/es/translation.json @@ -55,7 +55,8 @@ "green": "Verde", "orange": "Naranja", "purple": "Morado", - "red": "Rojo" + "red": "Rojo", + "yellow": "Amarillo" }, "composed": { "add": "Agregar {{what}}", @@ -194,7 +195,6 @@ "businessServices": "Servicios de negocio", "canceled": "Cancelado", "category": "Categoría", - "cloudNativeReady": "Listo para Cloud-native", "color": "Color", "comments": "Comentarios", "completed": "Completado", @@ -247,13 +247,11 @@ "member(s)": "Miembro(s)", "memberCount": "Número de miembros", "message": "Mensaje", - "modernizable": "Modernizable", "name": "Nombre", "northboundDependencies": "Dependencias del norte", "notAvailable": "No disponible", "notReviewed": "No revisado", "notStarted": "No empezado", - "notYetAssessed": "No evaluado todavía", "notYetReviewed": "No revisado todavía", "other": "Otro", "owner": "Propietario", @@ -304,7 +302,6 @@ "trivialButMigratable": "Trivial pero migrable", "unassessed": "No evaluado", "unknown": "Desconocido", - "unsuitableForContainers": "No apto para contenedores", "uploadApplicationFile": "Carga tu archivo con aplicaciones", "user": "Usuario", "version": "Versión", diff --git a/client/src/app/api/rest.ts b/client/src/app/api/rest.ts index 18e803352f..e9b06be9e9 100644 --- a/client/src/app/api/rest.ts +++ b/client/src/app/api/rest.ts @@ -205,6 +205,9 @@ export const getApplicationSummaryCSV = (id: string): AxiosPromise => { }); }; +export const getAssessments = (): Promise => + axios.get(ASSESSMENTS).then((response) => response.data); + export const getAssessmentsByItemId = ( isArchetype: boolean, itemId?: number | string diff --git a/client/src/app/pages/reports/components/landscape/donut.tsx b/client/src/app/pages/reports/components/landscape/donut.tsx index b3612229b1..5dbed9ad19 100644 --- a/client/src/app/pages/reports/components/landscape/donut.tsx +++ b/client/src/app/pages/reports/components/landscape/donut.tsx @@ -11,7 +11,6 @@ export interface IDonutProps { total: number; color: string; riskLabel: string; - riskDescription: string; } export const Donut: React.FC = ({ @@ -19,7 +18,6 @@ export const Donut: React.FC = ({ total, color, riskLabel, - riskDescription, }) => { const { t } = useTranslation(); @@ -44,7 +42,6 @@ export const Donut: React.FC = ({ {riskLabel} - {riskDescription} diff --git a/client/src/app/pages/reports/components/landscape/landscape.tsx b/client/src/app/pages/reports/components/landscape/landscape.tsx index c21b229fda..c70ad07dc9 100644 --- a/client/src/app/pages/reports/components/landscape/landscape.tsx +++ b/client/src/app/pages/reports/components/landscape/landscape.tsx @@ -91,9 +91,8 @@ export const Landscape: React.FC = () => { @@ -101,17 +100,15 @@ export const Landscape: React.FC = () => { value={landscapeData.medium} total={applications.length} color={RISK_LIST["yellow"].hexColor} - riskLabel={t("terms.mediumRisk")} - riskDescription={t("terms.modernizable")} + riskLabel={t("colors.yellow")} /> @@ -119,8 +116,7 @@ export const Landscape: React.FC = () => { value={landscapeData.unassessed} total={applications.length} color={RISK_LIST["unknown"].hexColor} - riskLabel={t("terms.unassessed")} - riskDescription={t("terms.notYetAssessed")} + riskLabel={`${t("terms.unassessed")}/${t("terms.unknown")}`} /> diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index 6a5f6c0135..02a2b5e6a4 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -37,7 +37,7 @@ import { Landscape } from "./components/landscape"; import { AdoptionPlan } from "./components/adoption-plan"; import { IdentifiedRisksTable } from "./components/identified-risks-table"; import { useFetchApplications } from "@app/queries/applications"; -import { useFetchQuestionnaires } from "@app/queries/questionnaires"; +import { useFetchAssessments } from "@app/queries/assessments"; export const Reports: React.FC = () => { // i18 @@ -49,7 +49,7 @@ export const Reports: React.FC = () => { const [selectedQuestionnaire, setSelectedQuestionnaire] = React.useState("All questionnaires"); - const { questionnaires } = useFetchQuestionnaires(); + const { assessments } = useFetchAssessments(); // Cards const [isAdoptionCandidateTable, setIsAdoptionCandidateTable] = @@ -137,12 +137,12 @@ export const Reports: React.FC = () => { All questionnaires - {questionnaires.map((questionnaire, index) => ( + {assessments.map((assessment, index) => ( - {questionnaire.name} + {assessment.questionnaire.name} ))} diff --git a/client/src/app/queries/assessments.ts b/client/src/app/queries/assessments.ts index a443d337f1..5fec63ace5 100644 --- a/client/src/app/queries/assessments.ts +++ b/client/src/app/queries/assessments.ts @@ -4,6 +4,7 @@ import { createAssessment, deleteAssessment, getAssessmentById, + getAssessments, getAssessmentsByItemId, updateAssessment, } from "@app/api/rest"; @@ -15,6 +16,18 @@ export const assessmentsQueryKey = "assessments"; export const assessmentQueryKey = "assessment"; export const assessmentsByItemIdQueryKey = "assessmentsByItemId"; +export const useFetchAssessments = () => { + const { isLoading, data, error } = useQuery({ + queryKey: [QuestionnairesQueryKey], + queryFn: getAssessments, + onError: (error: AxiosError) => console.log("error, ", error), + }); + return { + assessments: data || [], + isFetching: isLoading, + fetchError: error, + }; +}; export const useCreateAssessmentMutation = ( isArchetype: boolean, onSuccess: (name: string) => void, From a7ed5d048763b96670beeb65806651bc36b6bade Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Tue, 19 Sep 2023 22:10:35 +0200 Subject: [PATCH 03/11] Reduce assessment list to unique questionnaires Signed-off-by: Gilles Dubreuil --- client/src/app/api/models.ts | 5 ----- .../pages/reports/components/landscape/donut.tsx | 3 +++ .../reports/components/landscape/landscape.tsx | 4 ++++ client/src/app/pages/reports/reports.tsx | 16 ++++++++++------ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/client/src/app/api/models.ts b/client/src/app/api/models.ts index 804c807ee7..c8bebd8536 100644 --- a/client/src/app/api/models.ts +++ b/client/src/app/api/models.ts @@ -722,11 +722,6 @@ export interface AssessmentRisk { applicationId: number; risk: Risk; } -export interface AssessmentRisk { - assessmentId: number; - applicationId: number; - risk: Risk; -} export interface AssessmentQuestionRisk { category: string; diff --git a/client/src/app/pages/reports/components/landscape/donut.tsx b/client/src/app/pages/reports/components/landscape/donut.tsx index 5dbed9ad19..5c0f4bacce 100644 --- a/client/src/app/pages/reports/components/landscape/donut.tsx +++ b/client/src/app/pages/reports/components/landscape/donut.tsx @@ -11,6 +11,7 @@ export interface IDonutProps { total: number; color: string; riskLabel: string; + riskDescription?: string; } export const Donut: React.FC = ({ @@ -18,6 +19,7 @@ export const Donut: React.FC = ({ total, color, riskLabel, + riskDescription, }) => { const { t } = useTranslation(); @@ -42,6 +44,7 @@ export const Donut: React.FC = ({ {riskLabel} + {riskDescription} diff --git a/client/src/app/pages/reports/components/landscape/landscape.tsx b/client/src/app/pages/reports/components/landscape/landscape.tsx index c70ad07dc9..0f3a968036 100644 --- a/client/src/app/pages/reports/components/landscape/landscape.tsx +++ b/client/src/app/pages/reports/components/landscape/landscape.tsx @@ -93,6 +93,7 @@ export const Landscape: React.FC = () => { total={applications.length} color={RISK_LIST["red"].hexColor} riskLabel={t("colors.red")} + // riskDescription={} /> @@ -101,6 +102,7 @@ export const Landscape: React.FC = () => { total={applications.length} color={RISK_LIST["yellow"].hexColor} riskLabel={t("colors.yellow")} + // riskDescription={} /> @@ -109,6 +111,7 @@ export const Landscape: React.FC = () => { total={applications.length} color={RISK_LIST["green"].hexColor} riskLabel={t("colors.green")} + // riskDescription={} /> @@ -117,6 +120,7 @@ export const Landscape: React.FC = () => { total={applications.length} color={RISK_LIST["unknown"].hexColor} riskLabel={`${t("terms.unassessed")}/${t("terms.unknown")}`} + // riskDescription={} /> diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index 02a2b5e6a4..69781efd21 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -102,6 +102,13 @@ export const Reports: React.FC = () => { setIsQuestionnaireSelectOpen(false); }; + const questionnaires = assessments.reduce((result: string[], item) => { + if (!result.includes(item.questionnaire.name)) { + result.push(item.questionnaire.name); + } + return result; + }, []); + return ( <> {pageHeaderSection} @@ -137,12 +144,9 @@ export const Reports: React.FC = () => { All questionnaires - {assessments.map((assessment, index) => ( - - {assessment.questionnaire.name} + {questionnaires.map((questionnaire, index) => ( + + {questionnaire} ))} From 9b0a143ea581fe5a5da21d863f3f3f78989f559a Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Tue, 19 Sep 2023 23:08:13 +0200 Subject: [PATCH 04/11] Pass specific questionnaire to LandScape Signed-off-by: Gilles Dubreuil --- .../components/landscape/landscape.tsx | 8 ++++-- client/src/app/pages/reports/reports.tsx | 25 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/client/src/app/pages/reports/components/landscape/landscape.tsx b/client/src/app/pages/reports/components/landscape/landscape.tsx index 0f3a968036..d68fe80cf6 100644 --- a/client/src/app/pages/reports/components/landscape/landscape.tsx +++ b/client/src/app/pages/reports/components/landscape/landscape.tsx @@ -7,7 +7,7 @@ import { ConditionalRender } from "@app/components/ConditionalRender"; import { StateError } from "@app/components/StateError"; import { RISK_LIST } from "@app/Constants"; -import { AssessmentRisk } from "@app/api/models"; +import { AssessmentRisk, Ref } from "@app/api/models"; import { ApplicationSelectionContext } from "../../application-selection-context"; import { NoApplicationSelectedEmptyState } from "../no-application-selected-empty-state"; @@ -48,7 +48,11 @@ const extractLandscapeData = ( return { low, medium, high, unassessed }; }; -export const Landscape: React.FC = () => { +interface ILandscapeProps { + questionnaire?: Ref; +} + +export const Landscape: React.FC = ({ questionnaire }) => { const { t } = useTranslation(); // Context diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index 69781efd21..e3aaf83ccc 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -38,6 +38,7 @@ import { AdoptionPlan } from "./components/adoption-plan"; import { IdentifiedRisksTable } from "./components/identified-risks-table"; import { useFetchApplications } from "@app/queries/applications"; import { useFetchAssessments } from "@app/queries/assessments"; +import { Ref } from "@app/api/models"; export const Reports: React.FC = () => { // i18 @@ -102,9 +103,9 @@ export const Reports: React.FC = () => { setIsQuestionnaireSelectOpen(false); }; - const questionnaires = assessments.reduce((result: string[], item) => { - if (!result.includes(item.questionnaire.name)) { - result.push(item.questionnaire.name); + const questionnaires = assessments.reduce((result: Ref[], item) => { + if (!result.some((ref) => ref.id === item.questionnaire.id)) { + result.push(item.questionnaire); } return result; }, []); @@ -145,8 +146,11 @@ export const Reports: React.FC = () => { All questionnaires {questionnaires.map((questionnaire, index) => ( - - {questionnaire} + + {questionnaire.name} ))} @@ -155,7 +159,16 @@ export const Reports: React.FC = () => { - + + questionnaire.name === selectedQuestionnaire + ) + : undefined + } + /> From 57485c0b6cc2bbd3640c802471b9c0d607644b07 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Tue, 19 Sep 2023 23:20:58 +0200 Subject: [PATCH 05/11] LandScape gets assessments from selection Signed-off-by: Gilles Dubreuil --- .../reports/components/landscape/landscape.tsx | 6 +++--- client/src/app/pages/reports/reports.tsx | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/src/app/pages/reports/components/landscape/landscape.tsx b/client/src/app/pages/reports/components/landscape/landscape.tsx index d68fe80cf6..9714330057 100644 --- a/client/src/app/pages/reports/components/landscape/landscape.tsx +++ b/client/src/app/pages/reports/components/landscape/landscape.tsx @@ -7,7 +7,7 @@ import { ConditionalRender } from "@app/components/ConditionalRender"; import { StateError } from "@app/components/StateError"; import { RISK_LIST } from "@app/Constants"; -import { AssessmentRisk, Ref } from "@app/api/models"; +import { Assessment, AssessmentRisk } from "@app/api/models"; import { ApplicationSelectionContext } from "../../application-selection-context"; import { NoApplicationSelectedEmptyState } from "../no-application-selected-empty-state"; @@ -49,10 +49,10 @@ const extractLandscapeData = ( }; interface ILandscapeProps { - questionnaire?: Ref; + assessments: Assessment[]; } -export const Landscape: React.FC = ({ questionnaire }) => { +export const Landscape: React.FC = ({ assessments }) => { const { t } = useTranslation(); // Context diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index e3aaf83ccc..f0910f1a98 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -160,13 +160,14 @@ export const Reports: React.FC = () => { - questionnaire.name === selectedQuestionnaire + assessments={ + selectedQuestionnaire === "All questionnaires" + ? assessments + : assessments.filter( + (assessment) => + assessment.questionnaire.name === + selectedQuestionnaire ) - : undefined } /> From f17b04a0ec4690d20f0fac9a6d5ffdfab51e44d6 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Wed, 20 Sep 2023 10:20:08 +0200 Subject: [PATCH 06/11] Use isAssessmentsFetching Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/reports.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index f0910f1a98..d6a3c0b83a 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -50,7 +50,8 @@ export const Reports: React.FC = () => { const [selectedQuestionnaire, setSelectedQuestionnaire] = React.useState("All questionnaires"); - const { assessments } = useFetchAssessments(); + const { assessments, isFetching: isAssessmentsFetching } = + useFetchAssessments(); // Cards const [isAdoptionCandidateTable, setIsAdoptionCandidateTable] = @@ -103,12 +104,14 @@ export const Reports: React.FC = () => { setIsQuestionnaireSelectOpen(false); }; - const questionnaires = assessments.reduce((result: Ref[], item) => { - if (!result.some((ref) => ref.id === item.questionnaire.id)) { - result.push(item.questionnaire); - } - return result; - }, []); + const questionnaires: Ref[] = isAssessmentsFetching + ? [] + : assessments.reduce((result: Ref[], item) => { + if (!result.some((ref) => ref.id === item.questionnaire.id)) { + result.push(item.questionnaire); + } + return result; + }, []); return ( <> From 89c578ebf52b1b7ddcb2d6e338f9778480a04355 Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Wed, 20 Sep 2023 11:21:15 +0200 Subject: [PATCH 07/11] check assessments fetchError Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/reports.tsx | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index d6a3c0b83a..c5f2f0a032 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -50,8 +50,11 @@ export const Reports: React.FC = () => { const [selectedQuestionnaire, setSelectedQuestionnaire] = React.useState("All questionnaires"); - const { assessments, isFetching: isAssessmentsFetching } = - useFetchAssessments(); + const { + assessments, + isFetching: isAssessmentsFetching, + fetchError: assessmentsFetchError, + } = useFetchAssessments(); // Cards const [isAdoptionCandidateTable, setIsAdoptionCandidateTable] = @@ -83,7 +86,7 @@ export const Reports: React.FC = () => { ); } - const toggle = (toggleRef: React.Ref) => ( + const toggleQuestionnaire = (toggleRef: React.Ref) => ( { setIsQuestionnaireSelectOpen(false); }; - const questionnaires: Ref[] = isAssessmentsFetching - ? [] - : assessments.reduce((result: Ref[], item) => { - if (!result.some((ref) => ref.id === item.questionnaire.id)) { - result.push(item.questionnaire); - } - return result; - }, []); + const questionnaires: Ref[] = + isAssessmentsFetching || assessmentsFetchError + ? [] + : assessments.reduce((result: Ref[], item) => { + if (!result.some((ref) => ref.id === item.questionnaire.id)) { + result.push(item.questionnaire); + } + return result; + }, []); return ( <> @@ -142,7 +146,7 @@ export const Reports: React.FC = () => { onOpenChange={(_isOpen) => setIsQuestionnaireSelectOpen(false) } - toggle={toggle} + toggle={toggleQuestionnaire} shouldFocusToggleOnSelect > From 981feadbf178f3801f716c58c48f1dbbdc695bae Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Thu, 21 Sep 2023 11:01:19 +0200 Subject: [PATCH 08/11] Adjust landscapeData Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/components/landscape/landscape.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/app/pages/reports/components/landscape/landscape.tsx b/client/src/app/pages/reports/components/landscape/landscape.tsx index 9714330057..7c500cd922 100644 --- a/client/src/app/pages/reports/components/landscape/landscape.tsx +++ b/client/src/app/pages/reports/components/landscape/landscape.tsx @@ -93,7 +93,7 @@ export const Landscape: React.FC = ({ assessments }) => { Date: Thu, 21 Sep 2023 11:21:42 +0200 Subject: [PATCH 09/11] Rename and default select value is constant Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/reports.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index c5f2f0a032..cfffea0187 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -40,6 +40,8 @@ import { useFetchApplications } from "@app/queries/applications"; import { useFetchAssessments } from "@app/queries/assessments"; import { Ref } from "@app/api/models"; +const ALL_QUESTIONNAIRES = "All questionnaires"; + export const Reports: React.FC = () => { // i18 const { t } = useTranslation(); @@ -107,7 +109,7 @@ export const Reports: React.FC = () => { setIsQuestionnaireSelectOpen(false); }; - const questionnaires: Ref[] = + const answeredQuestionnaires: Ref[] = isAssessmentsFetching || assessmentsFetchError ? [] : assessments.reduce((result: Ref[], item) => { @@ -149,17 +151,19 @@ export const Reports: React.FC = () => { toggle={toggleQuestionnaire} shouldFocusToggleOnSelect > - + All questionnaires - {questionnaires.map((questionnaire, index) => ( - - {questionnaire.name} - - ))} + {answeredQuestionnaires.map( + (answeredQuestionnaire, index) => ( + + {answeredQuestionnaire.name} + + ) + )} From 228bdedf830473496403e1301c83f3ffd1836c3a Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Thu, 21 Sep 2023 11:59:53 +0200 Subject: [PATCH 10/11] Handle empty assessment questionnaire case and sort list Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/reports.tsx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index cfffea0187..c24c20bde9 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -112,12 +112,23 @@ export const Reports: React.FC = () => { const answeredQuestionnaires: Ref[] = isAssessmentsFetching || assessmentsFetchError ? [] - : assessments.reduce((result: Ref[], item) => { - if (!result.some((ref) => ref.id === item.questionnaire.id)) { - result.push(item.questionnaire); - } - return result; - }, []); + : assessments + .reduce((questionnaires: Ref[], assessment) => { + if ( + !questionnaires.some( + (ref) => ref.id === assessment.questionnaire.id + ) + ) { + assessment.questionnaire && + questionnaires.push(assessment.questionnaire); + } + return questionnaires; + }, []) + .sort((a, b) => { + if (a.name > b.name) return 1; + if (b.name > a.name) return -1; + return 0; + }); return ( <> From d13e44660e6d34d086a6d6dbd4bb654a559482ec Mon Sep 17 00:00:00 2001 From: Gilles Dubreuil Date: Thu, 21 Sep 2023 14:00:31 +0200 Subject: [PATCH 11/11] Refactor answeredQuestionnaires Signed-off-by: Gilles Dubreuil --- client/src/app/pages/reports/reports.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/app/pages/reports/reports.tsx b/client/src/app/pages/reports/reports.tsx index c24c20bde9..3a085a639d 100644 --- a/client/src/app/pages/reports/reports.tsx +++ b/client/src/app/pages/reports/reports.tsx @@ -115,9 +115,9 @@ export const Reports: React.FC = () => { : assessments .reduce((questionnaires: Ref[], assessment) => { if ( - !questionnaires.some( - (ref) => ref.id === assessment.questionnaire.id - ) + !questionnaires + .map((ref) => ref.id) + .includes(assessment.questionnaire.id) ) { assessment.questionnaire && questionnaires.push(assessment.questionnaire);