UNPKG

cluedin-widget

Version:

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

60 lines (50 loc) 1.94 kB
import React, { Component } from 'react'; import Widget from '../../core/components/widget.jsx'; import Loading from '../../core/components/loading.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 './document.jsx'; import iso from '../../iso'; const collectionHelper = iso.collection; class LastDocument extends Component { componentWillMount() { this.props.dispatch( shouldFetchGenericLastDocuments() ); } render() { let content; let fakeHtml; let minHeight = 'auto'; const { isFetchingGenericDocuments, documents, isFake } = this.props; if ( isFetchingGenericDocuments ) { minHeight = '200px'; content = (<Loading></Loading>); } else { 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 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 }; } registry.register( 'genericLastDocuments', connect( select )( LastDocument ) );