-
Notifications
You must be signed in to change notification settings - Fork 80
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 warnings in Problem Editor [FC-0062] #1280
Changes from 1 commit
108ca4e
986c100
217c7f3
ad10865
30bcff4
6b8f6ff
64be177
8b5a4c6
2a2879d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; | ||
import { | ||
ActionRow, | ||
Button, | ||
ModalDialog, | ||
} from '@openedx/paragon'; | ||
import { FormattedMessage, injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import messages from './messages'; | ||
import * as hooks from '../hooks'; | ||
|
||
|
@@ -16,68 +15,55 @@ import { actions, selectors } from '../../../../../data/redux'; | |
const SelectTypeFooter = ({ | ||
onCancel, | ||
selected, | ||
// redux | ||
defaultSettings, | ||
updateField, | ||
setBlockTitle, | ||
// injected, | ||
intl, | ||
}) => ( | ||
<div className="editor-footer fixed-bottom"> | ||
<ModalDialog.Footer className="border-top-0"> | ||
<ActionRow> | ||
<ActionRow.Spacer /> | ||
<Button | ||
aria-label={intl.formatMessage(messages.cancelButtonAriaLabel)} | ||
variant="tertiary" | ||
onClick={onCancel} | ||
> | ||
<FormattedMessage {...messages.cancelButtonLabel} /> | ||
</Button> | ||
<Button | ||
aria-label={intl.formatMessage(messages.selectButtonAriaLabel)} | ||
onClick={hooks.onSelect({ | ||
selected, | ||
updateField, | ||
setBlockTitle, | ||
defaultSettings, | ||
})} | ||
disabled={!selected} | ||
> | ||
<FormattedMessage {...messages.selectButtonLabel} /> | ||
</Button> | ||
</ActionRow> | ||
</ModalDialog.Footer> | ||
</div> | ||
); | ||
}) => { | ||
const intl = useIntl(); | ||
const defaultSettings = useSelector(selectors.problem.defaultSettings); | ||
const dispatch = useDispatch(); | ||
const updateField = React.useCallback((data) => dispatch(actions.problem.updateField(data)), [dispatch]); | ||
const setBlockTitle = React.useCallback((title) => dispatch(actions.app.setBlockTitle(title)), [dispatch]); | ||
return ( | ||
<div className="editor-footer fixed-bottom"> | ||
<ModalDialog.Footer className="border-top-0"> | ||
<ActionRow> | ||
<ActionRow.Spacer /> | ||
<Button | ||
aria-label={intl.formatMessage(messages.cancelButtonAriaLabel)} | ||
variant="tertiary" | ||
onClick={onCancel} | ||
> | ||
<FormattedMessage {...messages.cancelButtonLabel} /> | ||
</Button> | ||
<Button | ||
aria-label={intl.formatMessage(messages.selectButtonAriaLabel)} | ||
onClick={hooks.onSelect({ | ||
selected, | ||
updateField, | ||
setBlockTitle, | ||
defaultSettings, | ||
})} | ||
disabled={!selected} | ||
> | ||
<FormattedMessage {...messages.selectButtonLabel} /> | ||
</Button> | ||
</ActionRow> | ||
</ModalDialog.Footer> | ||
</div> | ||
); | ||
}; | ||
|
||
SelectTypeFooter.defaultProps = { | ||
selected: null, | ||
}; | ||
|
||
SelectTypeFooter.propTypes = { | ||
defaultSettings: PropTypes.shape({ | ||
maxAttempts: PropTypes.number, | ||
rerandomize: PropTypes.string, | ||
showResetButton: PropTypes.bool, | ||
showanswer: PropTypes.string, | ||
}).isRequired, | ||
// defaultSettings: PropTypes.shape({ | ||
// maxAttempts: PropTypes.number, | ||
// rerandomize: PropTypes.string, | ||
// showResetButton: PropTypes.bool, | ||
// showanswer: PropTypes.string, | ||
// }).isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
selected: PropTypes.string, | ||
updateField: PropTypes.func.isRequired, | ||
setBlockTitle: PropTypes.func.isRequired, | ||
// injected | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
export const mapStateToProps = (state) => ({ | ||
defaultSettings: selectors.problem.defaultSettings(state), | ||
}); | ||
|
||
export const mapDispatchToProps = { | ||
updateField: actions.problem.updateField, | ||
setBlockTitle: actions.app.setBlockTitle, | ||
}; | ||
|
||
export const SelectTypeFooterInternal = SelectTypeFooter; // For testing only | ||
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(SelectTypeFooter)); | ||
export default SelectTypeFooter; | ||
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. I modernized this component by:
There is no change to the actual code within the component itself. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,18 @@ import { FormattedMessage } from '@edx/frontend-platform/i18n'; | |
|
||
// SelectableBox in paragon has a bug where you can't change selection. So we override it | ||
import SelectableBox from '../../../../../sharedComponents/SelectableBox'; | ||
import { ProblemTypes, ProblemTypeKeys, AdvanceProblemKeys } from '../../../../../data/constants/problem'; | ||
import { | ||
ProblemTypes, | ||
ProblemTypeKeys, | ||
AdvanceProblemKeys, | ||
AdvancedProblemType, | ||
ProblemType, | ||
} from '../../../../../data/constants/problem'; | ||
import messages from './messages'; | ||
|
||
interface Props { | ||
selected: string; | ||
setSelected: (selected: string) => void; | ||
setSelected: (selected: ProblemType | AdvancedProblemType) => void; | ||
} | ||
|
||
const ProblemTypeSelect: React.FC<Props> = ({ | ||
|
@@ -18,7 +24,7 @@ const ProblemTypeSelect: React.FC<Props> = ({ | |
}) => { | ||
const handleChange = e => setSelected(e.target.value); | ||
const handleClick = () => setSelected(AdvanceProblemKeys.BLANK); | ||
const settings = { 'aria-label': 'checkbox', type: 'radio' }; | ||
const settings = { type: 'radio' }; | ||
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. a11y fix: in the "problem types" menu, every option had the same label for screen readers: 'checkbox'. This was worse than no label at all. Now they are labelled by their inner text ("Multiple choice", "Single select", etc.) |
||
|
||
return ( | ||
<Container style={{ width: '494px', height: '400px' }}> | ||
|
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.
These commented-out lines can be removed now that you're using selectors instead.