-
Notifications
You must be signed in to change notification settings - Fork 81
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 8 commits
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** Shared interface that all Editor components (like ProblemEditor) adhere to */ | ||
export interface EditorComponent { | ||
onClose: (() => void) | null; | ||
// TODO: get a better type for the 'result' here | ||
returnFunction?: (() => (result: any) => void) | null; | ||
} |
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, | ||
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. These commented-out lines can be removed now that you're using selectors instead. |
||
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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ exports[`SelectTypeWrapper snapshot 1`] = ` | |
className="pgn__modal-close-container" | ||
> | ||
<IconButton | ||
alt="Exit the editor" | ||
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: several of these icon buttons had no alt text! |
||
iconAs="Icon" | ||
src={[MockFunction icons.Close]} | ||
/> | ||
|
@@ -30,7 +31,7 @@ exports[`SelectTypeWrapper snapshot 1`] = ` | |
test child | ||
</h1> | ||
</ModalDialog.Body> | ||
<injectIntl(ShimmedIntlComponent) | ||
<SelectTypeFooter | ||
selected="iMAsElecTedValUE" | ||
/> | ||
</div> | ||
|
This file was deleted.
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 tells typescript that when we import PNG files, that import is getting a
string
(from webpack, which is the URL to the image file)