diff --git a/src/actions/errorNotificationActions.js b/src/actions/errorNotificationActions.ts similarity index 84% rename from src/actions/errorNotificationActions.js rename to src/actions/errorNotificationActions.ts index 97e7945b..5d93ca78 100644 --- a/src/actions/errorNotificationActions.js +++ b/src/actions/errorNotificationActions.ts @@ -1,7 +1,7 @@ export const SET_ERROR_NOTIFICATION = "SET_ERROR_NOTIFICATION"; export const CLEAR_ERROR_NOTIFICATION = "CLEAR_ERROR_NOTIFICATION"; -export function setErrorNotification(message) { +export function setErrorNotification(message: string) { return { type: SET_ERROR_NOTIFICATION, value: message, diff --git a/src/actions/keystoreActions.ts b/src/actions/keystoreActions.ts index 4ae30ea8..5a42afd6 100644 --- a/src/actions/keystoreActions.ts +++ b/src/actions/keystoreActions.ts @@ -16,7 +16,7 @@ export type SetKeystoreAction = { version: string; }; -type SetKeystoreNoteAction = { +export type SetKeystoreNoteAction = { type: typeof SET_KEYSTORE_NOTE; value: string; }; diff --git a/src/actions/testRunActions.ts b/src/actions/testRunActions.ts index 63865628..48fba65e 100644 --- a/src/actions/testRunActions.ts +++ b/src/actions/testRunActions.ts @@ -20,7 +20,7 @@ type ResetTestRunAction = { testRunIndex: number; }; -type SetTestRunNoteAction = { +export type SetTestRunNoteAction = { type: typeof SET_TEST_RUN_NOTE; testRunIndex: number; note: string; @@ -60,12 +60,12 @@ export function resetTestRun(testRunIndex: number): ResetTestRunAction { } export function setTestRunNote( - testRunIndex: number, - text: string + text: string, + testRunIndex?: number ): SetTestRunNoteAction { return { type: SET_TEST_RUN_NOTE, - testRunIndex, + testRunIndex: testRunIndex || 0, note: text, }; } diff --git a/src/components/TestSuiteRun/Note.tsx b/src/components/TestSuiteRun/Note.tsx index 678184d7..6a0516d7 100644 --- a/src/components/TestSuiteRun/Note.tsx +++ b/src/components/TestSuiteRun/Note.tsx @@ -1,33 +1,20 @@ import React from "react"; -import { connect } from "react-redux"; +import { useSelector, useDispatch } from "react-redux"; import { TextField } from "@mui/material"; -import { setKeystoreNote } from "../../actions/keystoreActions"; -import { setTestRunNote } from "../../actions/testRunActions"; +import { setKeystoreNote as setKeystoreNoteAction } from "../../actions/keystoreActions"; +import { setTestRunNote as setTestRunNoteAction } from "../../actions/testRunActions"; -const KEYSTORE_MODE = "keystore"; -const TEST_RUN_MODE = "testRun"; +import { getKeystore } from "../../selectors/keystore"; +import { getTestSuiteRun } from "../../selectors/testSuiteRun"; -interface NoteBaseProps { - note: string; - mode: string; - setNote: (note: string) => void; - testRunIndex?: number; - testSuiteRun?: { - currentTestRunIndex: number; - started: boolean; - testRuns: any[]; - }; -} - -const NoteBase = ({ note, mode, setNote, testRunIndex = 0 }: NoteBaseProps) => { +export const KeystoreNote = () => { + const note = useSelector(getKeystore).note; + const dispatch = useDispatch(); const handleChange = (event: React.ChangeEvent) => { const newNote = event.target.value; - if (mode === TEST_RUN_MODE) { - setNote(String(testRunIndex)); - } else { - setNote(newNote); - } + + dispatch(setKeystoreNoteAction(newNote)); }; return ( @@ -44,43 +31,24 @@ const NoteBase = ({ note, mode, setNote, testRunIndex = 0 }: NoteBaseProps) => { ); }; -const mapStateToKeystoreNoteProps = (state: { keystore: NoteBaseProps }) => { - return { - note: state.keystore.note, - mode: KEYSTORE_MODE, - }; -}; - -const mapDispatchToKeystoreNoteProps = { - setNote: setKeystoreNote, -}; - -const mapStateToTestRunNoteProps = (state: { - testSuiteRun: { - testRuns: any[]; - currentTestRunIndex: number; - }; - keystore: NoteBaseProps; -}) => { - return { - mode: TEST_RUN_MODE, - testRunIndex: state.testSuiteRun.currentTestRunIndex, - note: state.testSuiteRun.testRuns[state.testSuiteRun.currentTestRunIndex] - .note, +export const TestRunNote = () => { + const testRunIndex = useSelector(getTestSuiteRun).currentTestRunIndex | 0; + const note = useSelector(getTestSuiteRun).testRuns[testRunIndex].note; + const dispatch = useDispatch(); + const handleChange = () => { + dispatch(setTestRunNoteAction(String(testRunIndex))); }; -}; -const mapDispatchToTestRunNoteProps = { - setNote: setTestRunNote, + return ( + + ); }; - -const KeystoreNote = connect( - mapStateToKeystoreNoteProps, - mapDispatchToKeystoreNoteProps -)(NoteBase); -const TestRunNote = connect( - mapStateToTestRunNoteProps, - mapDispatchToTestRunNoteProps -)(NoteBase); - -export { KeystoreNote, TestRunNote };