|
1 | 1 | import * as React from 'react'; |
2 | | -import { useNexus } from '@bbp/react-nexus'; |
3 | | -import { |
4 | | - DEFAULT_ELASTIC_SEARCH_VIEW_ID, |
5 | | - ElasticSearchViewQueryResponse, |
6 | | -} from '@bbp/nexus-sdk'; |
| 2 | +import { useNexusContext } from '@bbp/react-nexus'; |
| 3 | +import { DEFAULT_ELASTIC_SEARCH_VIEW_ID, NexusClient } from '@bbp/nexus-sdk'; |
7 | 4 |
|
8 | 5 | import DropdownFilter from '../components/DropdownFilter'; |
9 | 6 | import { TypeDropdownItem } from '../components/DropdownFilter/DropdownItem'; |
| 7 | +import { useQuery } from 'react-query'; |
10 | 8 |
|
11 | 9 | // must be explicitly set for elasticSearch, default is 10 |
12 | 10 | const RESULTS_SIZE = 10000; |
13 | 11 |
|
14 | | -const TypeDropdownFilterContainer: React.FunctionComponent<{ |
| 12 | +const fetchESVTypes = ({ |
| 13 | + nexus, |
| 14 | + orgLabel, |
| 15 | + projectLabel, |
| 16 | + deprecated, |
| 17 | +}: { |
| 18 | + nexus: NexusClient; |
15 | 19 | orgLabel: string; |
16 | 20 | projectLabel: string; |
17 | 21 | deprecated: boolean; |
18 | | - value?: string; |
19 | | - onChange(value: string): void; |
20 | | -}> = ({ orgLabel, projectLabel, onChange, deprecated, value }) => { |
21 | | - const { loading: busy, data, error } = useNexus< |
22 | | - ElasticSearchViewQueryResponse<any> |
23 | | - >(nexus => |
24 | | - nexus.View.elasticSearchQuery( |
25 | | - orgLabel, |
26 | | - projectLabel, |
27 | | - encodeURIComponent(DEFAULT_ELASTIC_SEARCH_VIEW_ID), |
28 | | - { |
29 | | - aggregations: { |
30 | | - types: { |
31 | | - filter: { |
32 | | - term: { _deprecated: deprecated }, |
33 | | - }, |
34 | | - aggregations: { |
35 | | - filteredByDeprecation: { |
36 | | - terms: { |
37 | | - field: '@type', |
38 | | - size: RESULTS_SIZE, |
39 | | - }, |
| 22 | +}) => |
| 23 | + nexus.View.elasticSearchQuery( |
| 24 | + orgLabel, |
| 25 | + projectLabel, |
| 26 | + encodeURIComponent(DEFAULT_ELASTIC_SEARCH_VIEW_ID), |
| 27 | + { |
| 28 | + aggregations: { |
| 29 | + types: { |
| 30 | + filter: { |
| 31 | + term: { _deprecated: deprecated }, |
| 32 | + }, |
| 33 | + aggregations: { |
| 34 | + filteredByDeprecation: { |
| 35 | + terms: { |
| 36 | + field: '@type', |
| 37 | + size: RESULTS_SIZE, |
40 | 38 | }, |
41 | 39 | }, |
42 | 40 | }, |
43 | 41 | }, |
44 | | - } |
45 | | - ) |
| 42 | + }, |
| 43 | + } |
46 | 44 | ); |
| 45 | +const TypeDropdownFilterContainer: React.FunctionComponent<{ |
| 46 | + orgLabel: string; |
| 47 | + projectLabel: string; |
| 48 | + deprecated: boolean; |
| 49 | + value?: string; |
| 50 | + onChange(value: string): void; |
| 51 | +}> = ({ orgLabel, projectLabel, onChange, deprecated, value }) => { |
| 52 | + const nexus = useNexusContext(); |
| 53 | + |
| 54 | + const { data } = useQuery({ |
| 55 | + queryKey: [ |
| 56 | + 'resource-list-query-types', |
| 57 | + { |
| 58 | + deprecated, |
| 59 | + orgLabel, |
| 60 | + projectLabel, |
| 61 | + desv_id: DEFAULT_ELASTIC_SEARCH_VIEW_ID, |
| 62 | + }, |
| 63 | + ], |
| 64 | + queryFn: () => fetchESVTypes({ nexus, orgLabel, projectLabel, deprecated }), |
| 65 | + refetchOnWindowFocus: true, |
| 66 | + }); |
47 | 67 |
|
48 | 68 | return ( |
49 | 69 | <DropdownFilter |
|
0 commit comments