cspace-ui
Version:
CollectionSpace user interface for browsers
59 lines (58 loc) • 2.42 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.ConnectedStructuredDateInput = void 0;
var _reactRedux = require("react-redux");
var _structuredDate = require("../../actions/structuredDate");
var _vocabulary = require("../../actions/vocabulary");
var _StructuredDateInput = _interopRequireDefault(require("../../components/record/StructuredDateInput"));
var _reducers = require("../../reducers");
var _withConfig = _interopRequireDefault(require("../../enhancers/withConfig"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const mapStateToProps = (state, ownProps) => {
const {
config,
structDateOptionListNames: ownStructDateOptionListNames,
structDateVocabNames: ownStructDateVocabNames
} = ownProps;
const {
structDateOptionListNames: configStructDateOptionListNames,
structDateVocabNames: configStructDateVocabNames
} = config;
const structDateOptionListNames = ownStructDateOptionListNames || configStructDateOptionListNames;
const structDateVocabNames = ownStructDateVocabNames || configStructDateVocabNames;
const optionLists = {};
const terms = {};
structDateOptionListNames.forEach(optionListName => {
optionLists[optionListName] = (0, _reducers.getOptionList)(state, optionListName);
});
structDateVocabNames.forEach(vocabName => {
const vocab = (0, _reducers.getVocabulary)(state, vocabName);
terms[vocabName] = vocab ? vocab.items : null;
});
return {
optionLists,
terms,
perms: (0, _reducers.getUserPerms)(state)
};
};
const mapDispatchToProps = {
parseDisplayDate: _structuredDate.parseDisplayDate,
readTerms: _vocabulary.readVocabularyItems
};
const mergeProps = (stateProps, dispatchProps, ownProps) => {
const {
structDateOptionListNames,
...remainingOwnProps
} = ownProps;
return {
...remainingOwnProps,
...stateProps,
...dispatchProps
};
};
const ConnectedStructuredDateInput = exports.ConnectedStructuredDateInput = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps, mergeProps)(_StructuredDateInput.default);
const ConnectedStructuredDateInputWithConfig = (0, _withConfig.default)(ConnectedStructuredDateInput);
ConnectedStructuredDateInputWithConfig.propTypes = _StructuredDateInput.default.propTypes;
var _default = exports.default = ConnectedStructuredDateInputWithConfig;
;