Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default display of "Show Answer" and "Show reset option" #403

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget for Advanced
<div
className="my-3"
>
<ResetCard />
<ResetCard
defaultValue={false}
/>
</div>
<div
className="my-3"
Expand Down Expand Up @@ -143,7 +145,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget page 1`] = `
<div
className="my-3"
>
<ResetCard />
<ResetCard
defaultValue={false}
/>
</div>
<div
className="my-3"
Expand Down Expand Up @@ -224,7 +228,9 @@ exports[`SettingsWidget snapshot snapshot: renders Settings widget page advanced
<div
className="my-3"
>
<ResetCard />
<ResetCard
defaultValue={false}
/>
</div>
<div
className="my-3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ export const SettingsWidget = ({
/>
</div>
<div className="my-3">
<ResetCard showResetButton={settings.showResetButton} updateSettings={updateSettings} />
<ResetCard
showResetButton={settings.showResetButton}
defaultValue={defaultSettings.showResetButton}
updateSettings={updateSettings}
/>
</div>
{
problemType === ProblemTypeKeys.ADVANCED && (
Expand Down Expand Up @@ -165,7 +169,7 @@ SettingsWidget.propTypes = {
defaultSettings: PropTypes.shape({
maxAttempts: PropTypes.number,
showanswer: PropTypes.string,
showReseButton: PropTypes.bool,
showResetButton: PropTypes.bool,
rerandomize: PropTypes.string,
}).isRequired,
// eslint-disable-next-line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ import { selectors } from '../../../../../../data/redux';

export const ResetCard = ({
showResetButton,
defaultValue,
updateSettings,
// inject
intl,
}) => {
const isLibrary = useSelector(selectors.app.isLibrary);
const { setResetTrue, setResetFalse } = resetCardHooks(updateSettings);
const advancedSettingsLink = `${useSelector(selectors.app.studioEndpointUrl)}/settings/advanced/${useSelector(selectors.app.learningContextId)}#show_reset_button`;
const currentResetButton = showResetButton !== null ? showResetButton : defaultValue;
return (
<SettingsOption
title={intl.formatMessage(messages.resetSettingsTitle)}
summary={showResetButton
summary={currentResetButton
? intl.formatMessage(messages.resetSettingsTrue) : intl.formatMessage(messages.resetSettingsFalse)}
className="resetCard"
>
Expand All @@ -37,10 +39,10 @@ export const ResetCard = ({
</div>
)}
<ButtonGroup size="sm" className="resetSettingsButtons mb-2">
<Button variant={showResetButton ? 'outline-primary' : 'primary'} size="sm" onClick={setResetFalse}>
<Button variant={currentResetButton ? 'outline-primary' : 'primary'} size="sm" onClick={setResetFalse}>
<FormattedMessage {...messages.resetSettingsFalse} />
</Button>
<Button variant={showResetButton ? 'primary' : 'outline-primary'} size="sm" onClick={setResetTrue}>
<Button variant={currentResetButton ? 'primary' : 'outline-primary'} size="sm" onClick={setResetTrue}>
<FormattedMessage {...messages.resetSettingsTrue} />
</Button>
</ButtonGroup>
Expand All @@ -50,6 +52,7 @@ export const ResetCard = ({

ResetCard.propTypes = {
showResetButton: PropTypes.bool.isRequired,
defaultValue: PropTypes.bool.isRequired,
updateSettings: PropTypes.func.isRequired,
// injected
intl: intlShape.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const ShowAnswerCard = ({
showAttempts,
} = useAnswerSettings(showAnswer, updateSettings);

const currentShowAnswer = showAnswer.on || defaultValue;

const showAnswerSection = (
<>
<div className="pb-2">
Expand All @@ -43,7 +45,7 @@ export const ShowAnswerCard = ({
<Form.Group className="pb-0 mb-0">
<Form.Control
as="select"
value={showAnswer.on}
value={currentShowAnswer}
onChange={handleShowAnswerChange}
>
{Object.values(ShowAnswerTypesKeys).map((answerType) => {
Expand Down Expand Up @@ -79,7 +81,7 @@ export const ShowAnswerCard = ({
return (
<SettingsOption
title={intl.formatMessage(messages.showAnswerSettingsTitle)}
summary={intl.formatMessage(ShowAnswerTypes[showAnswer.on])}
summary={intl.formatMessage(ShowAnswerTypes[currentShowAnswer])}
>
{showAnswerSection}
</SettingsOption>
Expand Down
6 changes: 3 additions & 3 deletions src/editors/data/redux/problem/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash-es';
import { createSlice } from '@reduxjs/toolkit';
import { indexToLetterMap } from '../../../containers/ProblemEditor/data/OLXParser';
import { StrictDict } from '../../../utils';
import { ProblemTypeKeys, RichTextProblems, ShowAnswerTypesKeys } from '../../constants/problem';
import { ProblemTypeKeys, RichTextProblems } from '../../constants/problem';
import { ToleranceTypes } from '../../../containers/ProblemEditor/components/EditProblemView/SettingsWidget/settingsComponents/Tolerance/constants';

const nextAlphaId = (lastId) => String.fromCharCode(lastId.charCodeAt(0) + 1);
Expand All @@ -28,10 +28,10 @@ const initialState = {
hints: [],
timeBetween: 0,
showAnswer: {
on: ShowAnswerTypesKeys.FINISHED,
on: '',
afterAttempts: 0,
},
showResetButton: false,
showResetButton: null,
solutionExplanation: '',
tolerance: {
value: null,
Expand Down
Loading