-
Notifications
You must be signed in to change notification settings - Fork 33
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
feat: add grading method field in problem editor #430
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,11 +3,13 @@ import _ from 'lodash-es'; | |||||||||||||||
import PropTypes from 'prop-types'; | ||||||||||||||||
import { connect } from 'react-redux'; | ||||||||||||||||
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||||||||||||||||
import { getConfig } from '@edx/frontend-platform'; | ||||||||||||||||
import { Form, Hyperlink } from '@openedx/paragon'; | ||||||||||||||||
import { selectors } from '../../../../../../data/redux'; | ||||||||||||||||
import SettingsOption from '../SettingsOption'; | ||||||||||||||||
import messages from '../messages'; | ||||||||||||||||
import { scoringCardHooks } from '../hooks'; | ||||||||||||||||
import { GradingMethod, GradingMethodKeys } from '../../../../../../data/constants/problem'; | ||||||||||||||||
|
||||||||||||||||
export const ScoringCard = ({ | ||||||||||||||||
scoring, | ||||||||||||||||
|
@@ -20,32 +22,73 @@ export const ScoringCard = ({ | |||||||||||||||
learningContextId, | ||||||||||||||||
isLibrary, | ||||||||||||||||
}) => { | ||||||||||||||||
const isGradingMethodEnabled = getConfig().ENABLE_GRADING_METHOD_IN_PROBLEMS; | ||||||||||||||||
const { | ||||||||||||||||
handleUnlimitedChange, | ||||||||||||||||
handleMaxAttemptChange, | ||||||||||||||||
handleWeightChange, | ||||||||||||||||
handleGradingMethodChange, | ||||||||||||||||
handleOnChange, | ||||||||||||||||
attemptDisplayValue, | ||||||||||||||||
} = scoringCardHooks(scoring, updateSettings, defaultValue); | ||||||||||||||||
|
||||||||||||||||
const getScoringSummary = (weight, attempts, unlimited) => { | ||||||||||||||||
const getScoringSummary = (weight, attempts, unlimited, gradingMethod) => { | ||||||||||||||||
let summary = intl.formatMessage(messages.weightSummary, { weight }); | ||||||||||||||||
summary += ` ${String.fromCharCode(183)} `; | ||||||||||||||||
summary += unlimited | ||||||||||||||||
? intl.formatMessage(messages.unlimitedAttemptsSummary) | ||||||||||||||||
: intl.formatMessage(messages.attemptsSummary, { attempts: attempts || defaultValue }); | ||||||||||||||||
if (isGradingMethodEnabled) { | ||||||||||||||||
summary += ` ${String.fromCharCode(183)} `; | ||||||||||||||||
summary += intl.formatMessage(messages.gradingMethodSummary, { | ||||||||||||||||
gradingMethod: intl.formatMessage(GradingMethod[gradingMethod]), | ||||||||||||||||
}); | ||||||||||||||||
} | ||||||||||||||||
return summary; | ||||||||||||||||
}; | ||||||||||||||||
|
||||||||||||||||
return ( | ||||||||||||||||
<SettingsOption | ||||||||||||||||
title={intl.formatMessage(messages.scoringSettingsTitle)} | ||||||||||||||||
summary={getScoringSummary(scoring.weight, scoring.attempts.number, scoring.attempts.unlimited)} | ||||||||||||||||
summary={ | ||||||||||||||||
getScoringSummary( | ||||||||||||||||
scoring.weight, | ||||||||||||||||
scoring.attempts.number, | ||||||||||||||||
scoring.attempts.unlimited, | ||||||||||||||||
scoring.gradingMethod, | ||||||||||||||||
) | ||||||||||||||||
} | ||||||||||||||||
className="scoringCard" | ||||||||||||||||
> | ||||||||||||||||
<div className="mb-4"> | ||||||||||||||||
<FormattedMessage {...messages.scoringSettingsLabel} /> | ||||||||||||||||
{isGradingMethodEnabled && <FormattedMessage {...messages.scoringSettingsLabelWithGradingMethod} />} | ||||||||||||||||
{!isGradingMethodEnabled && <FormattedMessage {...messages.scoringSettingsLabel} />} | ||||||||||||||||
Comment on lines
+64
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
</div> | ||||||||||||||||
{isGradingMethodEnabled && ( | ||||||||||||||||
<Form.Group> | ||||||||||||||||
<Form.Control | ||||||||||||||||
as="select" | ||||||||||||||||
value={scoring.gradingMethod} | ||||||||||||||||
onChange={handleGradingMethodChange} | ||||||||||||||||
floatingLabel={intl.formatMessage(messages.scoringGradingMethodInputLabel)} | ||||||||||||||||
> | ||||||||||||||||
{Object.values(GradingMethodKeys).map((gradingMethod) => { | ||||||||||||||||
const optionDisplayName = GradingMethod[gradingMethod]; | ||||||||||||||||
return ( | ||||||||||||||||
<option | ||||||||||||||||
key={gradingMethod} | ||||||||||||||||
value={gradingMethod} | ||||||||||||||||
> | ||||||||||||||||
{intl.formatMessage(optionDisplayName)} | ||||||||||||||||
</option> | ||||||||||||||||
); | ||||||||||||||||
})} | ||||||||||||||||
</Form.Control> | ||||||||||||||||
<Form.Control.Feedback> | ||||||||||||||||
<FormattedMessage {...messages.gradingMethodHint} /> | ||||||||||||||||
</Form.Control.Feedback> | ||||||||||||||||
</Form.Group> | ||||||||||||||||
)} | ||||||||||||||||
<Form.Group> | ||||||||||||||||
<Form.Control | ||||||||||||||||
type="number" | ||||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import React from 'react'; | ||
import { shallow } from '@edx/react-unit-test-utils'; | ||
import { mergeConfig } from '@edx/frontend-platform'; | ||
import { formatMessage } from '../../../../../../../testUtils'; | ||
import { scoringCardHooks } from '../hooks'; | ||
import { ScoringCard } from './ScoringCard'; | ||
import { GradingMethodKeys } from '../../../../../../data/constants/problem'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about relative import paths as before (I see that |
||
|
||
mergeConfig({ | ||
ENABLE_GRADING_METHOD_IN_PROBLEMS: true, | ||
}); | ||
|
||
jest.mock('../hooks', () => ({ | ||
scoringCardHooks: jest.fn(), | ||
|
@@ -15,6 +21,7 @@ describe('ScoringCard', () => { | |
unlimited: false, | ||
number: 5, | ||
}, | ||
gradingMethod: GradingMethodKeys.LAST_SCORE, | ||
updateSettings: jest.fn().mockName('args.updateSettings'), | ||
intl: { formatMessage }, | ||
}; | ||
|
@@ -29,6 +36,7 @@ describe('ScoringCard', () => { | |
handleMaxAttemptChange: jest.fn().mockName('scoringCardHooks.handleMaxAttemptChange'), | ||
handleWeightChange: jest.fn().mockName('scoringCardHooks.handleWeightChange'), | ||
handleOnChange: jest.fn().mockName('scoringCardHooks.handleOnChange'), | ||
handleGradingMethodChange: jest.fn().mockName('scoringCardHooks.handleGradingMethodChange'), | ||
local: 5, | ||
}; | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could become problematic if we ever want to move this file. Does
not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your review! I was trying your suggestions and unfortunately, it doesn't work. I get that it doesn't find the module :(. It must be an absolute path, and that's how it's currently done in all the code.