|
|
|
@ -7,15 +7,16 @@ import { metadataProfileNames } from 'Helpers/Props';
|
|
|
|
|
import createSortedSectionSelector from 'Store/Selectors/createSortedSectionSelector';
|
|
|
|
|
import sortByName from 'Utilities/Array/sortByName';
|
|
|
|
|
import translate from 'Utilities/String/translate';
|
|
|
|
|
import SelectInput from './SelectInput';
|
|
|
|
|
import EnhancedSelectInput from './EnhancedSelectInput';
|
|
|
|
|
|
|
|
|
|
function createMapStateToProps() {
|
|
|
|
|
return createSelector(
|
|
|
|
|
createSortedSectionSelector('settings.metadataProfiles', sortByName),
|
|
|
|
|
(state, { includeNoChange }) => includeNoChange,
|
|
|
|
|
(state, { includeNoChangeDisabled }) => includeNoChangeDisabled,
|
|
|
|
|
(state, { includeMixed }) => includeMixed,
|
|
|
|
|
(state, { includeNone }) => includeNone,
|
|
|
|
|
(metadataProfiles, includeNoChange, includeMixed, includeNone) => {
|
|
|
|
|
(metadataProfiles, includeNoChange, includeNoChangeDisabled = true, includeMixed, includeNone) => {
|
|
|
|
|
|
|
|
|
|
const profiles = metadataProfiles.items.filter((item) => item.name !== metadataProfileNames.NONE);
|
|
|
|
|
const noneProfile = metadataProfiles.items.find((item) => item.name === metadataProfileNames.NONE);
|
|
|
|
@ -38,7 +39,7 @@ function createMapStateToProps() {
|
|
|
|
|
values.unshift({
|
|
|
|
|
key: 'noChange',
|
|
|
|
|
value: translate('NoChange'),
|
|
|
|
|
disabled: true
|
|
|
|
|
disabled: includeNoChangeDisabled
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -69,8 +70,8 @@ class MetadataProfileSelectInputConnector extends Component {
|
|
|
|
|
values
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
if (!value || !_.some(values, (option) => parseInt(option.key) === value)) {
|
|
|
|
|
const firstValue = _.find(values, (option) => !isNaN(parseInt(option.key)));
|
|
|
|
|
if (!value || !values.some((option) => option.key === value || parseInt(option.key) === value)) {
|
|
|
|
|
const firstValue = values.find((option) => !isNaN(parseInt(option.key)));
|
|
|
|
|
|
|
|
|
|
if (firstValue) {
|
|
|
|
|
this.onChange({ name, value: firstValue.key });
|
|
|
|
@ -82,7 +83,7 @@ class MetadataProfileSelectInputConnector extends Component {
|
|
|
|
|
// Listeners
|
|
|
|
|
|
|
|
|
|
onChange = ({ name, value }) => {
|
|
|
|
|
this.props.onChange({ name, value: parseInt(value) });
|
|
|
|
|
this.props.onChange({ name, value: value === 'noChange' ? value : parseInt(value) });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
@ -90,7 +91,7 @@ class MetadataProfileSelectInputConnector extends Component {
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<SelectInput
|
|
|
|
|
<EnhancedSelectInput
|
|
|
|
|
{...this.props}
|
|
|
|
|
onChange={this.onChange}
|
|
|
|
|
/>
|
|
|
|
@ -108,7 +109,8 @@ MetadataProfileSelectInputConnector.propTypes = {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
MetadataProfileSelectInputConnector.defaultProps = {
|
|
|
|
|
includeNoChange: false
|
|
|
|
|
includeNoChange: false,
|
|
|
|
|
includeNone: true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(createMapStateToProps)(MetadataProfileSelectInputConnector);
|
|
|
|
|