3
3
// SPDX-License-Identifier: Apache-2.0
4
4
5
5
import React , { ReactElement , useContext , useMemo , useState } from 'react' ;
6
- import {
7
- Attributions ,
8
- AttributionsToHashes ,
9
- } from '../../../shared/shared-types' ;
6
+ import { AttributionsToHashes } from '../../../shared/shared-types' ;
10
7
import { AccordionPanel } from './AccordionPanel' ;
11
8
import { PackagePanelTitle } from '../../enums/enums' ;
12
9
import {
13
- AttributionIdsWithCountAndResourceId ,
14
- AttributionIdWithCount ,
10
+ DisplayAttributionsWithCountAndResourceId ,
11
+ DisplayAttributionWithCount ,
15
12
PanelData ,
16
13
} from '../../types/types' ;
17
14
import { AccordionWorkersContext } from '../WorkersContextProvider/WorkersContextProvider' ;
18
15
import { PanelAttributionData } from '../../util/get-contained-packages' ;
19
16
20
- const EMPTY_ATTRIBUTION_IDS_WITH_COUNT_AND_RESOURCE_ID = {
21
- resourceId : '' ,
22
- attributionIdsWithCount : [ ] ,
23
- } ;
17
+ const EMPTY_DISPLAY_ATTRIBUTIONS_WITH_COUNT_AND_RESOURCE_ID : DisplayAttributionsWithCountAndResourceId =
18
+ {
19
+ resourceId : '' ,
20
+ displayAttributionsWithCount : [ ] ,
21
+ } ;
24
22
25
23
type ContainedAttributionsAccordionWorkerArgs =
26
24
| ContainedExternalAttributionsAccordionWorkerArgs
@@ -44,21 +42,20 @@ interface WorkerAccordionPanelProps {
44
42
| PackagePanelTitle . ContainedManualPackages ;
45
43
workerArgs : ContainedAttributionsAccordionWorkerArgs ;
46
44
syncFallbackArgs ?: ContainedAttributionsAccordionWorkerArgs ;
47
- getDisplayAttributionIdsWithCount (
45
+ getDisplayAttributionsWithCount (
48
46
workerArgs : ContainedAttributionsAccordionWorkerArgs
49
- ) : Array < AttributionIdWithCount > ;
50
- attributions : Attributions ;
47
+ ) : Array < DisplayAttributionWithCount > ;
51
48
isAddToPackageEnabled : boolean ;
52
49
}
53
50
54
51
export function WorkerAccordionPanel (
55
52
props : WorkerAccordionPanelProps
56
53
) : ReactElement {
57
54
const [
58
- attributionIdsWithCountAndResourceId ,
59
- setAttributionIdsWithCountAndResourceId ,
60
- ] = useState < AttributionIdsWithCountAndResourceId > (
61
- EMPTY_ATTRIBUTION_IDS_WITH_COUNT_AND_RESOURCE_ID
55
+ displayAttributionsWithCountAndResourceId ,
56
+ setDisplayAttributionsWithCountAndResourceId ,
57
+ ] = useState < DisplayAttributionsWithCountAndResourceId > (
58
+ EMPTY_DISPLAY_ATTRIBUTIONS_WITH_COUNT_AND_RESOURCE_ID
62
59
) ;
63
60
const resourceDetailsTabsWorkers = useContext ( AccordionWorkersContext ) ;
64
61
@@ -79,8 +76,8 @@ export function WorkerAccordionPanel(
79
76
props . workerArgs ,
80
77
worker ,
81
78
props . title ,
82
- setAttributionIdsWithCountAndResourceId ,
83
- props . getDisplayAttributionIdsWithCount ,
79
+ setDisplayAttributionsWithCountAndResourceId ,
80
+ props . getDisplayAttributionsWithCount ,
84
81
props . syncFallbackArgs
85
82
) ;
86
83
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -89,19 +86,17 @@ export function WorkerAccordionPanel(
89
86
let panelData : PanelData ;
90
87
if (
91
88
props . workerArgs . selectedResourceId ===
92
- attributionIdsWithCountAndResourceId . resourceId
89
+ displayAttributionsWithCountAndResourceId . resourceId
93
90
) {
94
91
panelData = {
95
92
title : props . title ,
96
- attributionIdsWithCount :
97
- attributionIdsWithCountAndResourceId . attributionIdsWithCount ,
98
- attributions : props . attributions ,
93
+ displayAttributionsWithCount :
94
+ displayAttributionsWithCountAndResourceId . displayAttributionsWithCount ,
99
95
} ;
100
96
} else {
101
97
panelData = {
102
98
title : props . title ,
103
- attributionIdsWithCount : [ ] ,
104
- attributions : props . attributions ,
99
+ displayAttributionsWithCount : [ ] ,
105
100
} ;
106
101
}
107
102
@@ -118,16 +113,16 @@ async function loadAttributionIdsWithCount(
118
113
workerArgs : ContainedAttributionsAccordionWorkerArgs ,
119
114
worker : Worker ,
120
115
panelTitle : string ,
121
- setAttributionIdsWithCountAndResourceId : (
122
- attributionIdsWithCountAndResourceId : AttributionIdsWithCountAndResourceId
116
+ setDisplayAttributionsWithCountAndResourceId : (
117
+ attributionIdsWithCountAndResourceId : DisplayAttributionsWithCountAndResourceId
123
118
) => void ,
124
- getDisplayAttributionIdsWithCount : (
119
+ getDisplayAttributionsWithCount : (
125
120
workerArgs : ContainedAttributionsAccordionWorkerArgs
126
- ) => Array < AttributionIdWithCount > ,
121
+ ) => Array < DisplayAttributionWithCount > ,
127
122
syncFallbackArgs ?: ContainedAttributionsAccordionWorkerArgs
128
123
) : Promise < void > {
129
- setAttributionIdsWithCountAndResourceId (
130
- EMPTY_ATTRIBUTION_IDS_WITH_COUNT_AND_RESOURCE_ID
124
+ setDisplayAttributionsWithCountAndResourceId (
125
+ EMPTY_DISPLAY_ATTRIBUTIONS_WITH_COUNT_AND_RESOURCE_ID
131
126
) ;
132
127
133
128
// WebWorkers can fail for different reasons, e.g. because they run out
@@ -142,21 +137,21 @@ async function loadAttributionIdsWithCount(
142
137
logErrorAndComputeInMainProcess (
143
138
panelTitle ,
144
139
Error ( 'Web Worker execution error.' ) ,
145
- setAttributionIdsWithCountAndResourceId ,
146
- getDisplayAttributionIdsWithCount ,
140
+ setDisplayAttributionsWithCountAndResourceId ,
141
+ getDisplayAttributionsWithCount ,
147
142
workerArgs ,
148
143
syncFallbackArgs
149
144
) ;
150
145
} else {
151
- setAttributionIdsWithCountAndResourceId ( output ) ;
146
+ setDisplayAttributionsWithCountAndResourceId ( output ) ;
152
147
}
153
148
} ;
154
149
} catch ( error ) {
155
150
logErrorAndComputeInMainProcess (
156
151
panelTitle ,
157
152
error ,
158
- setAttributionIdsWithCountAndResourceId ,
159
- getDisplayAttributionIdsWithCount ,
153
+ setDisplayAttributionsWithCountAndResourceId ,
154
+ getDisplayAttributionsWithCount ,
160
155
workerArgs ,
161
156
syncFallbackArgs
162
157
) ;
@@ -166,21 +161,23 @@ async function loadAttributionIdsWithCount(
166
161
function logErrorAndComputeInMainProcess (
167
162
panelTitle : string ,
168
163
error : unknown ,
169
- setAttributionIdsWithCountAndResourceId : (
170
- attributionIdsWithCountAndResourceId : AttributionIdsWithCountAndResourceId
164
+ setDisplayAttributionsWithCountAndResourceId : (
165
+ attributionIdsWithCountAndResourceId : DisplayAttributionsWithCountAndResourceId
171
166
) => void ,
172
- getDisplayAttributionIdsWithCount : (
167
+ getDisplayAttributionsWithCount : (
173
168
workerArgs : ContainedAttributionsAccordionWorkerArgs
174
- ) => Array < AttributionIdWithCount > ,
169
+ ) => Array < DisplayAttributionWithCount > ,
175
170
workerArgs : ContainedAttributionsAccordionWorkerArgs ,
176
171
syncFallbackArgs ?: ContainedAttributionsAccordionWorkerArgs
177
172
) : void {
178
- const displayAttributionIdsWithCount = getDisplayAttributionIdsWithCount (
173
+ console . info ( `Error in ResourceDetailsTab ${ panelTitle } : ` , error ) ;
174
+
175
+ const displayAttributionIdsWithCount = getDisplayAttributionsWithCount (
179
176
syncFallbackArgs || workerArgs
180
177
) ;
181
178
182
- setAttributionIdsWithCountAndResourceId ( {
179
+ setDisplayAttributionsWithCountAndResourceId ( {
183
180
resourceId : workerArgs . selectedResourceId ,
184
- attributionIdsWithCount : displayAttributionIdsWithCount ,
181
+ displayAttributionsWithCount : displayAttributionIdsWithCount ,
185
182
} ) ;
186
183
}
0 commit comments