UNPKG

@talend/react-containers

Version:

Provide connected components aka containers for @talend/react-cmf based on @talend/react-components.

77 lines (74 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppLoaderContainer = AppLoaderContainer; exports.default = void 0; exports.mapStateToProps = mapStateToProps; var _propTypes = _interopRequireDefault(require("prop-types")); var _reactCmf = require("@talend/react-cmf"); var _AppLoader = require("./AppLoader.saga"); var _reactComponents = require("@talend/react-components"); var _lodash = require("lodash"); var _jsxRuntime = require("react/jsx-runtime"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const CustomInject = (0, _reactCmf.cmfConnect)({ omitCMFProps: true, withComponentRegistry: true, withDispatch: true, withDispatchActionCreator: true, withComponentId: true })(_reactComponents.Inject); const appLoaderRenderer = appLoaderElement => appLoaderElement; /** * This container show the application's loader & bootstrap the app * @param {object} props the component props * @param {boolean} props.loading tell if the app loader should show the loader or the content * @param {function} props.renderer lets you customise the way we display the loader in the app * @param {object} props.children react element to show */ function AppLoaderContainer({ loading, renderer = appLoaderRenderer, children, ...rest }) { if (loading) { return renderer(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactComponents.AppLoader, { ...rest })); } const injected = _reactComponents.Inject.all(rest.getComponent, rest.components, CustomInject); return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", { children: [injected('before-children'), children || null, injected('after-children')] }); } AppLoaderContainer.displayName = 'AppLoader'; AppLoaderContainer.propTypes = { children: _propTypes.default.oneOfType([_propTypes.default.element, _propTypes.default.array]), loading: _propTypes.default.bool, renderer: _propTypes.default.func }; /** * calculate the loading attribute with the given props * @param {object} state the redux state * @param {object} ownProps the component props */ function mapStateToProps(state, ownProps) { return { loading: !(0, _lodash.get)(ownProps, 'hasCollections', []).every(collectionName => state.cmf.collections.has(collectionName)) }; } const connected = (0, _reactCmf.cmfConnect)({ mapStateToProps, omitCMFProps: true, withComponentRegistry: true, withDispatch: true, withDispatchActionCreator: true, withComponentId: true })(AppLoaderContainer); connected.sagas = { appLoaderSaga: _AppLoader.appLoaderSaga }; var _default = exports.default = connected; //# sourceMappingURL=AppLoader.connect.js.map