UNPKG

cluedin-widget

Version:

This is the project for creating and managing widgets in CluedIn.

68 lines (55 loc) 2.25 kB
import React, { Component } from 'react'; import Widget from '../../core/components/widget.jsx'; import Overlay from '../../core/components/overlay.jsx'; import NoEntities from '../../core/components/noEntities.jsx'; import registry from '../../core/registry'; import config from '../../core/config'; import { connect } from 'react-redux'; import { shouldFetchGenericLastDocuments } from '../../core/action/document'; import Document from './../../core/components/entities/document.jsx'; import iso from '../../iso'; const collectionHelper = iso.collection; class LastDocument extends Component { componentWillMount() { const { entityId } = this.props; if ( entityId ) { return this.props.dispatch( shouldFetchGenericLastDocuments( entityId ) ); } this.props.dispatch( shouldFetchGenericLastDocuments() ); } render() { let content; let fakeHtml; let minHeight = 'auto'; const { isFetchingGenericDocuments, isFetchingEntity, documents, isFake, entityId } = this.props; let loading = isFetchingGenericDocuments; if ( entityId ) { loading = isFetchingGenericDocuments || isFetchingEntity; } if ( !isFetchingGenericDocuments ) { content = collectionHelper.take( documents, 5 ).map( function( doc ) { return <Document key={doc.id} entity={doc}></Document>; } ); } if ( isFake ) { fakeHtml = (<Overlay><NoEntities entityType="/Document/Document"></NoEntities></Overlay>); } return ( <Widget noScroll={isFake} loading={loading} title="Latest Documents" minHeight={minHeight}> {fakeHtml} <div className="cluedIn_entity_list"> {content} </div> </Widget> ); } } function select( state ) { return { documents: state.document.genericLastDocuments, isFetchingGenericDocuments: state.document.isFetchingGenericDocuments, isFake: state.document.isFakeGenericDocuments, entity: state.entity.selectedEntity }; } registry.register( 'genericLastDocuments', connect( select )( LastDocument ) );