From d8095c0ff952e42057ac499f7cfc649539859b3c Mon Sep 17 00:00:00 2001 From: Donal Stewart Date: Sun, 7 Mar 2021 20:52:43 +0000 Subject: [PATCH] More Sonar warning cleanup --- adminclient/package-lock.json | 4 +-- adminclient/src/App.js | 7 +++-- adminclient/src/PhotoGallery.js | 1 - adminclient/src/SurveysAsCsv.js | 6 ++--- adminclient/src/SurveysAsDoc.js | 27 ++++++++++++------- adminclient/src/model/SurveyModel.js | 10 +++---- .../resources/confirmSurveyLambda/index.js | 3 +-- .../components/auth/ConfirmRegistration.jsx | 2 +- .../src/components/auth/ConfirmSignIn.jsx | 3 +-- sharedcode/src/components/auth/TOTPSetup.jsx | 9 ++----- sharedcode/src/model/AuthStore.js | 3 +-- surveyclient/package-lock.json | 4 +-- surveyclient/src/App.test.js | 4 ++- .../auth/AuthSignOutWithConfirm.jsx | 2 +- surveyclient/src/model/TestUtils.js | 3 +-- 15 files changed, 45 insertions(+), 43 deletions(-) diff --git a/adminclient/package-lock.json b/adminclient/package-lock.json index b4a9c55..6235276 100644 --- a/adminclient/package-lock.json +++ b/adminclient/package-lock.json @@ -15882,7 +15882,7 @@ "node_modules/learning-play-audit-shared": { "version": "0.1.0", "resolved": "file:../sharedcode/learning-play-audit-shared-0.1.0.tgz", - "integrity": "sha512-Bx2GyyNqRdAERYN593M9hxR7pGpC7OCS/fUAsPsCR8ABT7rPeXjWsdrHjz3j4fLjpzJ+SdCt2brecYeii3h+gQ==", + "integrity": "sha512-ZXaT8PeDLhD3qeDZlKYBbhPmCn29c/9nnFwciRcrIeVR+6LTKnFivjXEF8HhCNLtTMjNchoqdA4LIQi8AxbO0Q==", "dependencies": { "qrcode": "^1.4.4" }, @@ -38958,7 +38958,7 @@ }, "learning-play-audit-shared": { "version": "file:../sharedcode/learning-play-audit-shared-0.1.0.tgz", - "integrity": "sha512-Bx2GyyNqRdAERYN593M9hxR7pGpC7OCS/fUAsPsCR8ABT7rPeXjWsdrHjz3j4fLjpzJ+SdCt2brecYeii3h+gQ==", + "integrity": "sha512-ZXaT8PeDLhD3qeDZlKYBbhPmCn29c/9nnFwciRcrIeVR+6LTKnFivjXEF8HhCNLtTMjNchoqdA4LIQi8AxbO0Q==", "requires": { "qrcode": "^1.4.4" } diff --git a/adminclient/src/App.js b/adminclient/src/App.js index 79fbb57..cb50347 100644 --- a/adminclient/src/App.js +++ b/adminclient/src/App.js @@ -4,7 +4,11 @@ import "./App.css"; import AppBar from "@material-ui/core/AppBar"; import Toolbar from "@material-ui/core/Toolbar"; import Typography from "@material-ui/core/Typography"; -import { makeStyles } from "@material-ui/core/styles"; +import { + makeStyles, + createMuiTheme, + ThemeProvider, +} from "@material-ui/core/styles"; import SurveyResultsTable from "./SurveyResultsTable"; import { Amplify } from "@aws-amplify/core"; import SurveyResponsesDialog from "./SurveyResponsesDialog"; @@ -15,7 +19,6 @@ import { isAuthenticating, signOut, } from "learning-play-audit-shared"; -import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles"; import { getSummaryResponses, getFullResponses, diff --git a/adminclient/src/PhotoGallery.js b/adminclient/src/PhotoGallery.js index d9f2dda..1484c25 100644 --- a/adminclient/src/PhotoGallery.js +++ b/adminclient/src/PhotoGallery.js @@ -24,7 +24,6 @@ const useStyles = makeStyles((theme) => ({ function GalleryPhoto({ photo }) { const classes = useStyles(); - // TODO default to downloading image ? const [imgSrc, setImgSrc] = useState(null); useEffect(() => { diff --git a/adminclient/src/SurveysAsCsv.js b/adminclient/src/SurveysAsCsv.js index 5ad18e2..fe385c3 100644 --- a/adminclient/src/SurveysAsCsv.js +++ b/adminclient/src/SurveysAsCsv.js @@ -18,16 +18,16 @@ export function exportSurveysAsCsv(surveys = []) { // Clone the header rows const data = headerRows.map((row) => [...row]); - sectionsContent.forEach((section, i) => { + sectionsContent.forEach((section) => { renderSectionHeader(data, section); }); - surveys.forEach((survey, i) => { + surveys.forEach((survey) => { const response = survey.surveyResponse; console.debug(survey); const rowData = [survey.id]; - sectionsContent.forEach((section, i) => { + sectionsContent.forEach((section) => { renderSectionAnswers(rowData, section, response[section.id]); }); diff --git a/adminclient/src/SurveysAsDoc.js b/adminclient/src/SurveysAsDoc.js index d5f1377..91b1f3d 100644 --- a/adminclient/src/SurveysAsDoc.js +++ b/adminclient/src/SurveysAsDoc.js @@ -23,8 +23,7 @@ import { const IMAGE_NOT_FOUND = "[Image not found]"; - -export function exportSurveysAsDocx(surveys = [], photos) { +export function exportSurveysAsDocx(surveys, photos) { if (surveys.length === 0) { console.log("No surveys to export"); } @@ -149,7 +148,11 @@ function tableCell(content) { }); } -function questionSelectWithComment(question, questionNumber, responses) { +function renderQuestionTypeSelectWithComment( + question, + questionNumber, + responses +) { function getAnswer(response) { switch (response.answer) { case "a": @@ -181,7 +184,7 @@ function questionSelectWithComment(question, questionNumber, responses) { ]; } -function questionUserSelect(question, questionNumber, responses) { +function renderQuestionTypeUserSelect(question, questionNumber, responses) { function getAnswer(response) { switch (response.answer) { case "a": @@ -229,7 +232,7 @@ function questionUserSelect(question, questionNumber, responses) { ]; } -function questionText(question, questionNumber, responses) { +function renderQuestionTypeText(question, questionNumber, responses) { return [ renderQuestionText(questionNumber, question.text), new Table({ @@ -246,7 +249,7 @@ function questionText(question, questionNumber, responses) { ]; } -function questionTextWithYear(question, questionNumber, responses) { +function renderQuestionTypeTextWithYear(question, questionNumber, responses) { function yearAnswerRow(response, answerKey, yearKey, index) { const answer = response[answerKey] != null ? response[answerKey] : ""; const year = response[yearKey] != null ? response[yearKey] : ""; @@ -315,25 +318,29 @@ function renderSection(section, sectionResponses) { docQuestions.splice( docQuestions.length, 0, - ...questionSelectWithComment(question, questionIndex, responses) + ...renderQuestionTypeSelectWithComment( + question, + questionIndex, + responses + ) ); } else if (USER_TYPE_WITH_COMMENT === type) { docQuestions.splice( docQuestions.length, 0, - ...questionUserSelect(question, questionIndex, responses) + ...renderQuestionTypeUserSelect(question, questionIndex, responses) ); } else if (TEXT_AREA === type || TEXT_FIELD === type) { docQuestions.splice( docQuestions.length, 0, - ...questionText(question, questionIndex, responses) + ...renderQuestionTypeText(question, questionIndex, responses) ); } else if (TEXT_WITH_YEAR === type) { docQuestions.splice( docQuestions.length, 0, - ...questionTextWithYear(question, questionIndex, responses) + ...renderQuestionTypeTextWithYear(question, questionIndex, responses) ); } else { throw new Error("unknown question type: " + type); diff --git a/adminclient/src/model/SurveyModel.js b/adminclient/src/model/SurveyModel.js index a513d63..39269d6 100644 --- a/adminclient/src/model/SurveyModel.js +++ b/adminclient/src/model/SurveyModel.js @@ -242,13 +242,13 @@ function getPhoto(s3, photoKey) { export function objectResponseToUint8Array(responseBody) { if (typeof Blob === "function" && responseBody instanceof Blob) { return new Promise(function (resolve) { - var reader = new FileReader(); + var fileReader = new FileReader(); - reader.onloadend = function () { - resolve(reader.result); + fileReader.onloadend = function () { + resolve(fileReader.result); }; - reader.readAsArrayBuffer(responseBody); + fileReader.readAsArrayBuffer(responseBody); }).then((arrayBuffer) => Promise.resolve(new Uint8Array(arrayBuffer))); } @@ -301,7 +301,7 @@ export function allSurveysRetrieved(selectedSurveyIds, fullSurveyResponses) { } // Exported for unit tests -export function surveyReducer(state = initialState(), action) { +export function surveyReducer(state = initialState(), action = undefined) { return surveyAnswersReducer(authReducer(state, action), action); } diff --git a/cdk-stacks/resources/confirmSurveyLambda/index.js b/cdk-stacks/resources/confirmSurveyLambda/index.js index f398daf..9b70433 100644 --- a/cdk-stacks/resources/confirmSurveyLambda/index.js +++ b/cdk-stacks/resources/confirmSurveyLambda/index.js @@ -115,7 +115,7 @@ exports.handler = async (event) => { console.log("Update result", updateResult); - const response = { + return { statusCode: 200, headers: { "Access-Control-Allow-Origin": "*", @@ -124,5 +124,4 @@ exports.handler = async (event) => { }, body: JSON.stringify({ result: "Submission complete" }), }; - return response; }; diff --git a/sharedcode/src/components/auth/ConfirmRegistration.jsx b/sharedcode/src/components/auth/ConfirmRegistration.jsx index c5f6b59..c2423a1 100644 --- a/sharedcode/src/components/auth/ConfirmRegistration.jsx +++ b/sharedcode/src/components/auth/ConfirmRegistration.jsx @@ -1,8 +1,8 @@ import React, { useEffect, useState } from "react"; -import { setAuthState } from "../../model/AuthActions"; import { useDispatch, useSelector } from "react-redux"; import { SIGN_IN } from "../../model/AuthStates"; import { + setAuthState, resendConfirmCode, confirmRegistration, } from "../../model/AuthActions"; diff --git a/sharedcode/src/components/auth/ConfirmSignIn.jsx b/sharedcode/src/components/auth/ConfirmSignIn.jsx index b333901..3fa3025 100644 --- a/sharedcode/src/components/auth/ConfirmSignIn.jsx +++ b/sharedcode/src/components/auth/ConfirmSignIn.jsx @@ -1,5 +1,4 @@ import React, { useEffect, useState } from "react"; -import { setAuthState } from "../../model/AuthActions"; import { useDispatch, useSelector } from "react-redux"; import { SIGN_IN, @@ -7,7 +6,7 @@ import { MFA_OPTION_SMS, SOFTWARE_TOKEN_MFA, } from "../../model/AuthStates"; -import { confirmSignIn } from "../../model/AuthActions"; +import { setAuthState, confirmSignIn } from "../../model/AuthActions"; const CODE_ID = "codeInput"; diff --git a/sharedcode/src/components/auth/TOTPSetup.jsx b/sharedcode/src/components/auth/TOTPSetup.jsx index 172e4e8..d304484 100644 --- a/sharedcode/src/components/auth/TOTPSetup.jsx +++ b/sharedcode/src/components/auth/TOTPSetup.jsx @@ -1,13 +1,8 @@ import React, { useEffect, useState } from "react"; -import { setAuthState } from "../../model/AuthActions"; import { useDispatch, useSelector } from "react-redux"; +import { SIGN_IN } from "../../model/AuthStates"; import { - SIGN_IN, - MFA_OPTION_TOTP, - MFA_OPTION_SMS, - SOFTWARE_TOKEN_MFA, -} from "../../model/AuthStates"; -import { + setAuthState, getTOTPSetupQrCode, verifyTOTPSetup, setAuthError, diff --git a/sharedcode/src/model/AuthStore.js b/sharedcode/src/model/AuthStore.js index e2e9a29..92a232b 100644 --- a/sharedcode/src/model/AuthStore.js +++ b/sharedcode/src/model/AuthStore.js @@ -43,13 +43,12 @@ function setAuthState(state, { authState, user }) { console.error("authState cannot be undefined"); return state; } - const result = { + return { ...state, authentication: { state: authState, user: user, errorMessage: "" }, // Show welcome screen on every login hasSeenSplashPage: state.hasSeenSplashPage && authState !== SIGNED_IN, }; - return result; } function setAuthError(state, { message }) { diff --git a/surveyclient/package-lock.json b/surveyclient/package-lock.json index da9a176..779752b 100644 --- a/surveyclient/package-lock.json +++ b/surveyclient/package-lock.json @@ -16915,7 +16915,7 @@ "node_modules/learning-play-audit-shared": { "version": "0.1.0", "resolved": "file:../sharedcode/learning-play-audit-shared-0.1.0.tgz", - "integrity": "sha512-Bx2GyyNqRdAERYN593M9hxR7pGpC7OCS/fUAsPsCR8ABT7rPeXjWsdrHjz3j4fLjpzJ+SdCt2brecYeii3h+gQ==", + "integrity": "sha512-ZXaT8PeDLhD3qeDZlKYBbhPmCn29c/9nnFwciRcrIeVR+6LTKnFivjXEF8HhCNLtTMjNchoqdA4LIQi8AxbO0Q==", "dependencies": { "qrcode": "^1.4.4" }, @@ -41837,7 +41837,7 @@ }, "learning-play-audit-shared": { "version": "file:../sharedcode/learning-play-audit-shared-0.1.0.tgz", - "integrity": "sha512-Bx2GyyNqRdAERYN593M9hxR7pGpC7OCS/fUAsPsCR8ABT7rPeXjWsdrHjz3j4fLjpzJ+SdCt2brecYeii3h+gQ==", + "integrity": "sha512-ZXaT8PeDLhD3qeDZlKYBbhPmCn29c/9nnFwciRcrIeVR+6LTKnFivjXEF8HhCNLtTMjNchoqdA4LIQi8AxbO0Q==", "requires": { "qrcode": "^1.4.4" } diff --git a/surveyclient/src/App.test.js b/surveyclient/src/App.test.js index 1f706e5..bd5a5ed 100644 --- a/surveyclient/src/App.test.js +++ b/surveyclient/src/App.test.js @@ -17,7 +17,9 @@ import { } from "./components/FixedSectionTypes"; jest.mock("@aws-amplify/core"); -jest.spyOn(window, "scrollTo").mockImplementation(() => {}); +jest.spyOn(window, "scrollTo").mockImplementation(() => { + // Do nothing +}); describe("main App", () => { var container = null; diff --git a/surveyclient/src/components/auth/AuthSignOutWithConfirm.jsx b/surveyclient/src/components/auth/AuthSignOutWithConfirm.jsx index 1809972..343d299 100644 --- a/surveyclient/src/components/auth/AuthSignOutWithConfirm.jsx +++ b/surveyclient/src/components/auth/AuthSignOutWithConfirm.jsx @@ -4,7 +4,7 @@ import { signOut } from "learning-play-audit-shared"; import ConfirmDialog from "../ConfirmDialog"; import "../../App.css"; -export default function AuthSignOut() { +export default function AuthSignOutWithConfirm() { const [showConfirmDialog, setShowConfirmDialog] = useState(false); const dispatch = useDispatch(); diff --git a/surveyclient/src/model/TestUtils.js b/surveyclient/src/model/TestUtils.js index 96559c7..4a4db9e 100644 --- a/surveyclient/src/model/TestUtils.js +++ b/surveyclient/src/model/TestUtils.js @@ -202,7 +202,7 @@ function createTestState() { return result; } - const result = { + return { ...EMPTY_STATE, answerCounts: populateAnswerCounts(), answers: populateAnswers(), @@ -235,7 +235,6 @@ function createTestState() { }, }, }; - return result; } export const INPUT_STATE = createTestState();