cspace-ui
Version:
CollectionSpace user interface for browsers
38 lines (36 loc) • 1.49 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getTags = exports.default = void 0;
var _immutable = _interopRequireDefault(require("immutable"));
var _get = _interopRequireDefault(require("lodash/get"));
var _actionCodes = require("../constants/actionCodes");
var _xmlNames = require("../constants/xmlNames");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const handleProcedureByTagFulfilled = (state, action) => {
const response = action.payload;
const hasDocTypes = (0, _get.default)(response, ['data', _xmlNames.DOCUMENT_PROPERTY_NAME, `${_xmlNames.NS_PREFIX}:servicegroups_common`, 'hasDocTypes', 'hasDocType']);
if (!hasDocTypes) {
return state;
}
// currently this makes an assumption that doctypes will only have one service tag
// it should be updated to merge state properly
let nextState = state;
const docTypes = Array.isArray(hasDocTypes) ? hasDocTypes : [hasDocTypes];
docTypes.forEach(docType => {
nextState = nextState.setIn([docType.toLowerCase()], action.meta.tag);
});
return nextState;
};
var _default = (state = _immutable.default.Map(), action) => {
switch (action.type) {
case _actionCodes.PROCEDURE_BY_TAG_READ_FULFILLED:
return handleProcedureByTagFulfilled(state, action);
default:
return state;
}
};
exports.default = _default;
const getTags = (state, recordType) => state.get(recordType);
exports.getTags = getTags;
;