UNPKG

@talend/react-containers

Version:

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

68 lines (66 loc) 2.19 kB
import PropTypes from 'prop-types'; import { cmfConnect } from '@talend/react-cmf'; import { appLoaderSaga } from './AppLoader.saga'; import { AppLoader, Inject } from "@talend/react-components"; import { get } from "lodash"; import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; const CustomInject = cmfConnect({ omitCMFProps: true, withComponentRegistry: true, withDispatch: true, withDispatchActionCreator: true, withComponentId: true })(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 */ export function AppLoaderContainer({ loading, renderer = appLoaderRenderer, children, ...rest }) { if (loading) { return renderer(/*#__PURE__*/_jsx(AppLoader, { ...rest })); } const injected = Inject.all(rest.getComponent, rest.components, CustomInject); return /*#__PURE__*/_jsxs("div", { children: [injected('before-children'), children || null, injected('after-children')] }); } AppLoaderContainer.displayName = 'AppLoader'; AppLoaderContainer.propTypes = { children: PropTypes.oneOfType([PropTypes.element, PropTypes.array]), loading: PropTypes.bool, renderer: PropTypes.func }; /** * calculate the loading attribute with the given props * @param {object} state the redux state * @param {object} ownProps the component props */ export function mapStateToProps(state, ownProps) { return { loading: !get(ownProps, 'hasCollections', []).every(collectionName => state.cmf.collections.has(collectionName)) }; } const connected = cmfConnect({ mapStateToProps, omitCMFProps: true, withComponentRegistry: true, withDispatch: true, withDispatchActionCreator: true, withComponentId: true })(AppLoaderContainer); connected.sagas = { appLoaderSaga }; export default connected; //# sourceMappingURL=AppLoader.connect.js.map