UNPKG

cluedin-widget

Version:

This project contains all the pages needed for browsing entities and searching them. The aim is to replace the CluedIn.Webapp project with this one when all the pages ( including the Admin page ) will be ported to REACT.

84 lines (72 loc) 2.15 kB
import React, { Component } from 'react'; import { register } from '../../core/registry'; import EntityListWidget from '../../core/components/entityRelated/EntityListWidget.jsx'; import { connect } from 'react-redux'; import { fetchGenericLast } from '../../core/action/entity'; import { getName } from '../../core/helpers/entity'; class LastGenericEntities extends Component { constructor(props) { super(props); this.state = { timestamp: +Date.now() }; } componentWillMount() { this.fetch(); } fetch() { const { entityId, entityType } = this.props; this.props.dispatch(fetchGenericLast(entityId, entityType, this.state.timestamp)); } render() { const { entitiesPerTimeStamp, isAdmin, layoutPosition, entityType } = this.props; let result = { entities: [], isFetching: true }; if (entitiesPerTimeStamp && entitiesPerTimeStamp[this.state.timestamp]) { result = entitiesPerTimeStamp[this.state.timestamp]; } const title = `Latest ${getName(entityType)}`; return ( <EntityListWidget widgetName={this.constructor.name} layoutPosition={layoutPosition} title={title} fetch={this.fetch.bind(this)} entities={result.entities} isFetching={result.isFetching} isAdmin={isAdmin} entityType={entityType} pageNumber={result.pageNumber} />); } } function select(state) { return { entitiesPerTimeStamp: state.entity.entitiesPerTimeStamp, }; } register('LastGenerics', connect(select)(LastGenericEntities), { name: 'LastGenerics', displayName: 'Custom Latest Information', description: 'Define the latest information you want to see in this widget.', fields: [{ displayName: 'Choose your entity Type', name: 'entityType', type: 'entityType', required: true, errorMessage: 'Please, choose a valid document type.' }], relatedProviders: [ 'dropbox', 'office365', 'googledrive', 'box', 'dropbox', 'slack', 'sharepoint', ], tags: [ 'support', 'sales', 'marketing', ], requireEntity: false, allowMultiplePerPage: true, });