@talend/react-containers
Version:
Provide connected components aka containers for @talend/react-cmf based on @talend/react-components.
69 lines (68 loc) • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
exports.getActionsProps = getActionsProps;
var _reactCmf = _interopRequireDefault(require("@talend/react-cmf"));
var _lodash = require("lodash");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
/**
* add support for expression in actions.
* it change the action props by their expression value
* it support the following props in the action
* * available
* * disabled
* * inProgress
* * labelExpression
*/
function evalExpressions(action, context, payload = {}) {
const newAction = _reactCmf.default.expression.getProps(action, ['active', 'available', 'disabled', 'inProgress'], context, payload);
return newAction;
}
function getActionsProps(context, ids, model) {
if (!ids) {
return [];
}
let tmpIds = ids;
const onlyOne = typeof ids === 'string' || typeof ids === 'object' && !Array.isArray(ids);
if (onlyOne) {
tmpIds = [ids];
}
const infos = tmpIds.map(id => {
if (typeof id === 'string') {
return _reactCmf.default.action.getActionInfo(context, id);
}
return id;
});
const props = infos.map(info => {
const newprops = {};
const dispatch = (0, _lodash.get)(context, 'store.dispatch');
if (dispatch) {
newprops.onClick = (event, data) => {
if (info.actionCreator) {
dispatch(_reactCmf.default.action.getActionObject(context, info.id, event, data));
} else {
dispatch({
model,
...info.payload
});
}
};
}
_extends(newprops, evalExpressions(info, context, {
model
}));
return newprops;
});
if (onlyOne) {
return props[0];
}
return props;
}
var _default = exports.default = {
getProps: getActionsProps,
evalExpressions
};
//# sourceMappingURL=actionAPI.js.map