Skip to content

Commit

Permalink
More Sonar warning cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Donal Stewart committed Mar 7, 2021
1 parent a6fb3fd commit d8095c0
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 43 deletions.
4 changes: 2 additions & 2 deletions adminclient/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions adminclient/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -15,7 +19,6 @@ import {
isAuthenticating,
signOut,
} from "learning-play-audit-shared";
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
import {
getSummaryResponses,
getFullResponses,
Expand Down
1 change: 0 additions & 1 deletion adminclient/src/PhotoGallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
6 changes: 3 additions & 3 deletions adminclient/src/SurveysAsCsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});

Expand Down
27 changes: 17 additions & 10 deletions adminclient/src/SurveysAsDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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({
Expand All @@ -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] : "";
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions adminclient/src/model/SurveyModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}

Expand Down Expand Up @@ -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);
}

Expand Down
3 changes: 1 addition & 2 deletions cdk-stacks/resources/confirmSurveyLambda/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ exports.handler = async (event) => {

console.log("Update result", updateResult);

const response = {
return {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
Expand All @@ -124,5 +124,4 @@ exports.handler = async (event) => {
},
body: JSON.stringify({ result: "Submission complete" }),
};
return response;
};
2 changes: 1 addition & 1 deletion sharedcode/src/components/auth/ConfirmRegistration.jsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
3 changes: 1 addition & 2 deletions sharedcode/src/components/auth/ConfirmSignIn.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useEffect, useState } from "react";
import { setAuthState } from "../../model/AuthActions";
import { useDispatch, useSelector } from "react-redux";
import {
SIGN_IN,
MFA_OPTION_TOTP,
MFA_OPTION_SMS,
SOFTWARE_TOKEN_MFA,
} from "../../model/AuthStates";
import { confirmSignIn } from "../../model/AuthActions";
import { setAuthState, confirmSignIn } from "../../model/AuthActions";

const CODE_ID = "codeInput";

Expand Down
9 changes: 2 additions & 7 deletions sharedcode/src/components/auth/TOTPSetup.jsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 1 addition & 2 deletions sharedcode/src/model/AuthStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
4 changes: 2 additions & 2 deletions surveyclient/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion surveyclient/src/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions surveyclient/src/model/TestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function createTestState() {
return result;
}

const result = {
return {
...EMPTY_STATE,
answerCounts: populateAnswerCounts(),
answers: populateAnswers(),
Expand Down Expand Up @@ -235,7 +235,6 @@ function createTestState() {
},
},
};
return result;
}

export const INPUT_STATE = createTestState();

0 comments on commit d8095c0

Please sign in to comment.