Skip to content

Commit

Permalink
🐛 Add missing error for invalid questionnaire (#1630)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 18, 2023
1 parent a81c97c commit fa663da
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ const AssessmentSettings: React.FC = () => {

// TODO: Check RBAC access
const rbacWriteAccess = true; // checkAccess(userScopes, questionnaireWriteScopes);

return (
<>
<PageSection variant={PageSectionVariants.light}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
31 changes: 16 additions & 15 deletions client/src/app/queries/questionnaires.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [],
Expand Down Expand Up @@ -92,7 +93,7 @@ export const useFetchQuestionnaireById = (id: number | string) => {
queryKey: [QuestionnaireByIdQueryKey, id],
queryFn: () => getQuestionnaireById<Questionnaire>(id),
onError: (error: AxiosError) => console.log("error, ", error),
select: (q) => inPlaceSortByOrder(q),
// select: (q) => inPlaceSortByOrder(q),
});

return {
Expand Down

0 comments on commit fa663da

Please sign in to comment.