import * as React from 'react'; import { Empty } from 'antd'; import NewWindow from 'react-new-window'; import { useParams } from 'react-router-dom'; import useApplicationConfigStore from '../../stores/ApplicationConfigStore'; import { EntityViewParams } from '../../stores/EntityStore'; import { OspreyEvent } from '../../types/QueryTypes'; import OspreyButton from '../../uikit/OspreyButton'; import Text, { TextColors } from '../../uikit/Text'; import { formatUtcTimestamp, localizeAndFormatTimestamp } from '../../utils/DateUtils'; import { wrapEntityKeysWithFeatureLocationsMenu, wrapEntityValuesWithLabelMenu } from '../../utils/EntityUtils'; import CopyLinkButton from '../common/CopyLinkButton'; import Feature from '../common/Feature'; import PropertyTable, { Entries } from '../common/PropertyTable'; import styles from './EventStreamCard.module.css'; import { FeatureLocation } from '../../types/ConfigTypes'; import Tooltip, { TooltipSizes } from '../../uikit/Tooltip'; interface EventStreamCardProps { eventDetails: OspreyEvent; selectedFeatures: Array; featureLocations: Array | undefined; isListView: boolean; } const EventStreamCard = ({ eventDetails, selectedFeatures, featureLocations, isListView }: EventStreamCardProps) => { const [showWindow, setShowWindow] = React.useState(false); const { entityId, entityType } = useParams(); const decodedEntityId = entityId != null ? decodeURIComponent(entityId) : null; const decodedEntityType = entityType != null ? decodeURIComponent(entityType) : null; const featureNameToEntityTypeMapping = useApplicationConfigStore((state) => state.featureNameToEntityTypeMapping); const handleShowWindow = () => { setShowWindow(true); }; const handleWindowClose = () => { setShowWindow(false); }; const renderDescriptionBlock = (features: readonly string[]) => { const entries: Record = {}; features.forEach((feature) => { if (Object.prototype.hasOwnProperty.call(eventDetails.extracted_features, feature)) { entries[feature] = eventDetails.extracted_features[feature]; } }); if (Object.keys(entries).length === 0) return null; return entries; }; const renderContent = () => { if (isListView) return null; const features = selectedFeatures.map(renderDescriptionBlock).filter((block) => block != null) as Entries[]; const isEmpty = features.length === 0; let entityViewProps = {}; if (decodedEntityId != null && decodedEntityType != null) { entityViewProps = { shouldHighlightCell: ([key, value]: [string, string]) => { if (value == null) return false; const featureEntityType = featureNameToEntityTypeMapping.get(key); return decodedEntityType === featureEntityType && decodedEntityId.toString() === value.toString(); }, }; } return isEmpty ? ( ) : ( wrapEntityKeysWithFeatureLocationsMenu(key, featureLocations)} renderValue={([key, value]) => wrapEntityValuesWithLabelMenu(value, key)} {...entityViewProps} /> ); }; const eventUrl = `${document.location.origin}/events/${eventDetails.id}`; const cardTitle = (
{localizeAndFormatTimestamp(eventDetails.timestamp)} {formatUtcTimestamp(eventDetails.timestamp)} } size={TooltipSizes.SMALL} >
); return (
{cardTitle} See Details {showWindow && ( )}
{renderContent()}
); }; export default EventStreamCard;