1
1
import { Button , Typography } from 'antd' ;
2
2
import React , { useState } from 'react' ;
3
3
import styled from 'styled-components' ;
4
+ import { Maybe , ExecutionRequestResult } from '@src/types.generated' ;
4
5
import { useGetSearchResultsForMultipleQuery } from '../../../graphql/search.generated' ;
5
6
import { EmbeddedListSearchModal } from '../../entity/shared/components/styled/search/EmbeddedListSearchModal' ;
6
7
import { ANTD_GRAY } from '../../entity/shared/constants' ;
7
8
import { UnionType } from '../../search/utils/constants' ;
8
9
import { formatNumber } from '../../shared/formatNumber' ;
9
10
import { Message } from '../../shared/Message' ;
10
11
import { useEntityRegistry } from '../../useEntityRegistry' ;
11
- import { extractEntityTypeCountsFromFacets } from './utils' ;
12
+ import { extractEntityTypeCountsFromFacets , getEntitiesIngestedByType , getTotalEntitiesIngested } from './utils' ;
12
13
13
14
const HeaderContainer = styled . div `
14
15
display: flex;
@@ -51,19 +52,27 @@ const ViewAllButton = styled(Button)`
51
52
52
53
type Props = {
53
54
id : string ;
55
+ executionResult ?: Maybe < Partial < ExecutionRequestResult > > ;
54
56
} ;
55
57
56
58
const ENTITY_FACET_NAME = 'entity' ;
57
59
const TYPE_NAMES_FACET_NAME = 'typeNames' ;
58
60
59
- export default function IngestedAssets ( { id } : Props ) {
61
+ export default function IngestedAssets ( { id, executionResult } : Props ) {
60
62
const entityRegistry = useEntityRegistry ( ) ;
61
63
62
64
// First thing to do is to search for all assets with the id as the run id!
63
65
const [ showAssetSearch , setShowAssetSearch ] = useState ( false ) ;
64
66
67
+ // Try getting the counts via the ingestion report.
68
+ const totalEntitiesIngested = executionResult && getTotalEntitiesIngested ( executionResult ) ;
69
+ const entitiesIngestedByTypeFromReport = executionResult && getEntitiesIngestedByType ( executionResult ) ;
70
+
71
+ // Fallback to the search across entities.
72
+ // First thing to do is to search for all assets with the id as the run id!
65
73
// Execute search
66
74
const { data, loading, error } = useGetSearchResultsForMultipleQuery ( {
75
+ skip : totalEntitiesIngested === null || entitiesIngestedByTypeFromReport === null ,
67
76
variables : {
68
77
input : {
69
78
query : '*' ,
@@ -90,11 +99,13 @@ export default function IngestedAssets({ id }: Props) {
90
99
const hasSubTypeFacet = ( facets || [ ] ) . findIndex ( ( facet ) => facet . field === TYPE_NAMES_FACET_NAME ) >= 0 ;
91
100
const subTypeFacets =
92
101
( hasSubTypeFacet && facets ?. filter ( ( facet ) => facet . field === TYPE_NAMES_FACET_NAME ) [ 0 ] ) || undefined ;
102
+
93
103
const countsByEntityType =
94
- ( entityTypeFacets && extractEntityTypeCountsFromFacets ( entityRegistry , entityTypeFacets , subTypeFacets ) ) || [ ] ;
104
+ entitiesIngestedByTypeFromReport ??
105
+ ( entityTypeFacets ? extractEntityTypeCountsFromFacets ( entityRegistry , entityTypeFacets , subTypeFacets ) : [ ] ) ;
95
106
96
107
// The total number of assets ingested
97
- const total = data ?. searchAcrossEntities ?. total || 0 ;
108
+ const total = totalEntitiesIngested ?? data ?. searchAcrossEntities ?. total ?? 0 ;
98
109
99
110
return (
100
111
< >
0 commit comments