Description We are encountering a bug in our stage environment that is very hard to reproduce locally, but not impossible. This is the same bug dealt with in several previous PRs like for example #871 (here I'm working on another component that uses the same paragon component and therefore encounters the same bug). Since I was able to reproduce it locally, it is definitely not just a bug affecting only 2U-specific things. Expected behavior open a course with files select a different sorting order (for example oldest to newest) you should be able to select the different option you should be able to successfully apply it Actual behavior on stage environment you can't select different option you can't apply different option Previous steps Previously, I reproduced this locally by just adding the latest version of SelectableBox as a copy into this repo and importing it from there. Then, under the mistaken assumption that there was a missing context provider, I added that and it got fixed locally. However it turned out to not work on stage. Measures taken in this PR I replaced the entire SelectableBox component with all subcomponents with a version from @edx/paragon@21.5.6, which was apparently the version in the commit that didn't have the error yet. In theory, this would just fix the problem, though I have my doubts. But it's worth a try. I only imported it in one place, in this SortAndFilter modal. I added console logging for onChange events which seem to the problem, as they are not triggering a change in the value of the context on stage. I see little choice than to log them to get more info. This will only affect the component that's not working.
78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
import React, { useContext } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { callAllHandlers } from './fieldUtils';
|
|
|
|
const identityFn = props => props;
|
|
|
|
const FormCheckboxSetContext = React.createContext({
|
|
getCheckboxControlProps: identityFn,
|
|
hasCheckboxSetProvider: false,
|
|
});
|
|
|
|
const useCheckboxSetContext = () => useContext(FormCheckboxSetContext);
|
|
|
|
const FormCheckboxSetContextProvider = ({
|
|
children,
|
|
name,
|
|
onBlur,
|
|
onFocus,
|
|
onChange,
|
|
value,
|
|
defaultValue,
|
|
}) => {
|
|
const isControlled = !defaultValue && Array.isArray(value);
|
|
const getCheckboxControlProps = (checkboxProps) => ({
|
|
...checkboxProps,
|
|
name,
|
|
/* istanbul ignore next */
|
|
onBlur: checkboxProps.onBlur ? callAllHandlers(onBlur, checkboxProps.onBlur) : onBlur,
|
|
/* istanbul ignore next */
|
|
onFocus: checkboxProps.onFocus ? callAllHandlers(onFocus, checkboxProps.onFocus) : onFocus,
|
|
/* istanbul ignore next */
|
|
onChange: checkboxProps.onChange ? callAllHandlers(onChange, checkboxProps.onChange) : onChange,
|
|
checked: isControlled ? value.includes(checkboxProps.value) : undefined,
|
|
defaultChecked: isControlled ? undefined : (defaultValue && defaultValue.includes(checkboxProps.value)),
|
|
});
|
|
// eslint-disable-next-line react/jsx-no-constructed-context-values
|
|
const contextValue = {
|
|
name,
|
|
value,
|
|
defaultValue,
|
|
getCheckboxControlProps,
|
|
onBlur,
|
|
onFocus,
|
|
onChange,
|
|
hasCheckboxSetProvider: true,
|
|
};
|
|
return (
|
|
<FormCheckboxSetContext.Provider value={contextValue}>
|
|
{children}
|
|
</FormCheckboxSetContext.Provider>
|
|
);
|
|
};
|
|
|
|
FormCheckboxSetContextProvider.propTypes = {
|
|
children: PropTypes.node.isRequired,
|
|
name: PropTypes.string,
|
|
onBlur: PropTypes.func,
|
|
onFocus: PropTypes.func,
|
|
onChange: PropTypes.func,
|
|
value: PropTypes.arrayOf(PropTypes.string),
|
|
defaultValue: PropTypes.arrayOf(PropTypes.string),
|
|
};
|
|
|
|
FormCheckboxSetContextProvider.defaultProps = {
|
|
onBlur: undefined,
|
|
name: undefined,
|
|
onFocus: undefined,
|
|
onChange: undefined,
|
|
value: undefined,
|
|
defaultValue: undefined,
|
|
};
|
|
|
|
export default FormCheckboxSetContext;
|
|
export {
|
|
useCheckboxSetContext,
|
|
FormCheckboxSetContextProvider,
|
|
};
|