From fa663da8140a9aee3adbc7a0506496216b7d8299 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 18 Dec 2023 13:03:14 -0500 Subject: [PATCH] :bug: Add missing error for invalid questionnaire (#1630) https://issues.redhat.com/browse/MTA-1908 Signed-off-by: ibolton336 --- .../assessment-settings-page.tsx | 1 - .../import-questionnaire-form.tsx | 6 ++++ client/src/app/queries/questionnaires.ts | 31 ++++++++++--------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx b/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx index 51b5000b8..fbf1384b7 100644 --- a/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx +++ b/client/src/app/pages/assessment-management/assessment-settings/assessment-settings-page.tsx @@ -153,7 +153,6 @@ const AssessmentSettings: React.FC = () => { // TODO: Check RBAC access const rbacWriteAccess = true; // checkAccess(userScopes, questionnaireWriteScopes); - return ( <> diff --git a/client/src/app/pages/assessment-management/import-questionnaire-form/import-questionnaire-form.tsx b/client/src/app/pages/assessment-management/import-questionnaire-form/import-questionnaire-form.tsx index 24656ada9..50d2e8105 100644 --- a/client/src/app/pages/assessment-management/import-questionnaire-form/import-questionnaire-form.tsx +++ b/client/src/app/pages/assessment-management/import-questionnaire-form/import-questionnaire-form.tsx @@ -116,6 +116,12 @@ export const ImportQuestionnaireForm: React.FC< createQuestionnaire(questionnaireData); } else { console.error("Invalid JSON data."); + pushNotification({ + title: "Failed", + message: "Invalid JSON data.", + variant: "danger", + timeout: 30000, + }); } } catch (error) { pushNotification({ diff --git a/client/src/app/queries/questionnaires.ts b/client/src/app/queries/questionnaires.ts index 544a7975d..668e5c12a 100644 --- a/client/src/app/queries/questionnaires.ts +++ b/client/src/app/queries/questionnaires.ts @@ -21,26 +21,27 @@ export const QuestionnaireByIdQueryKey = "questionnaireById"; * in that list have an order. Hub stores things in the document order not logical * order. UI needs to have things in logical order. */ -function inPlaceSortByOrder(q: Questionnaire) { - q.sections.sort((a, b) => a.order - b.order); - q.sections.forEach((s) => { - s.questions.sort((a, b) => a.order - b.order); - s.questions.forEach((q) => { - q.answers.sort((a, b) => a.order - b.order); - }); - }); - return q; -} +//TODO: this is not working, need to figure out why https://issues.redhat.com/browse/MTA-1907 +// function inPlaceSortByOrder(q: Questionnaire) { +// q.sections.sort((a, b) => a.order - b.order); +// q.sections.forEach((s) => { +// s.questions.sort((a, b) => a.order - b.order); +// s.questions.forEach((q) => { +// q.answers.sort((a, b) => a.order - b.order); +// }); +// }); +// return q; +// } export const useFetchQuestionnaires = () => { const { isLoading, data, error } = useQuery({ queryKey: [QuestionnairesQueryKey], queryFn: getQuestionnaires, onError: (error: AxiosError) => console.log("error, ", error), - select: (questionnaires) => { - questionnaires.forEach((q) => inPlaceSortByOrder(q)); - return questionnaires; - }, + // select: (questionnaires) => { + // questionnaires.forEach((q) => inPlaceSortByOrder(q)); + // return questionnaires; + // }, }); return { questionnaires: data || [], @@ -92,7 +93,7 @@ export const useFetchQuestionnaireById = (id: number | string) => { queryKey: [QuestionnaireByIdQueryKey, id], queryFn: () => getQuestionnaireById(id), onError: (error: AxiosError) => console.log("error, ", error), - select: (q) => inPlaceSortByOrder(q), + // select: (q) => inPlaceSortByOrder(q), }); return {