@talend/react-containers
Version:
Provide connected components aka containers for @talend/react-cmf based on @talend/react-components.
75 lines • 2.43 kB
JavaScript
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); }
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import cmf, { cmfConnect } from '@talend/react-cmf';
import getOnClick from '../actionOnClick';
import { omit } from "lodash";
import { ActionDropdown } from "@talend/react-components";
import { jsx as _jsx } from "react/jsx-runtime";
export function mapStateToProps(state, ownProps = {}) {
let props = {};
const context = {
registry: cmf.registry.getRegistry(),
store: {
getState: () => state
}
};
if (ownProps.actionId) {
// deprecated
props = cmf.action.getActionInfo(context, ownProps.actionId);
}
const actionIds = ownProps.actionIds || props.actionIds;
if (actionIds) {
// deprecated
props.items = actionIds.map(itemId => cmf.action.getActionInfo(context, itemId));
}
return props;
}
export function mergeProps(stateProps, dispatchProps, ownProps) {
const props = {
...ownProps,
...stateProps,
...dispatchProps
};
if (props.actionId) {
delete props.actionId;
}
if (props.actionIds) {
delete props.actionIds;
}
return props;
}
export function ContainerActionDropdown({
items,
...props
}) {
const safeProps = omit(props, cmfConnect.INJECTED_PROPS);
if (items) {
// keep initial object as it can be immutable and have a prototype
const clikableItems = items.map(item => _extends(item, getOnClick(item, props)));
return /*#__PURE__*/_jsx(ActionDropdown, {
items: clikableItems,
...safeProps
});
}
return /*#__PURE__*/_jsx(ActionDropdown, {
...safeProps
});
}
ContainerActionDropdown.displayName = 'Container(ActionDropdown)';
ContainerActionDropdown.propTypes = {
items: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), ImmutablePropTypes.list]),
noCaret: PropTypes.bool,
pullRight: PropTypes.bool,
hideLabel: PropTypes.bool
};
export default cmfConnect({
mapStateToProps,
mergeProps,
omitCMFProps: true,
withComponentRegistry: true,
withDispatch: true,
withDispatchActionCreator: true,
withComponentId: true
})(ContainerActionDropdown);
//# sourceMappingURL=ActionDropdown.connect.js.map