|
7 | 7 | SyncOutlined, |
8 | 8 | } from '@ant-design/icons'; |
9 | 9 | import { Button, Collapse, Input, Modal } from 'antd'; |
10 | | -import { without, intersection } from 'lodash'; |
| 10 | +import { without, intersection, uniq, flatten, map } from 'lodash'; |
11 | 11 | import * as React from 'react'; |
12 | 12 | import { getUsername } from '../../../shared/utils'; |
13 | 13 | import FriendlyTimeAgo from '../FriendlyDate'; |
@@ -38,10 +38,13 @@ import { |
38 | 38 | } from '../../types/plugins/report'; |
39 | 39 | import Tools from './Tools'; |
40 | 40 | import ToolsEdit from './ToolsEdit'; |
| 41 | +import { useSelector } from 'react-redux'; |
| 42 | +import { RootState } from 'shared/store/reducers'; |
41 | 43 |
|
42 | 44 | const AnalysisPlugin = ({ |
43 | 45 | analysisResourceType, |
44 | 46 | containerId, |
| 47 | + containerResourceTypes, |
45 | 48 | analysisReports, |
46 | 49 | onSave, |
47 | 50 | onDelete, |
@@ -88,11 +91,46 @@ const AnalysisPlugin = ({ |
88 | 91 | {FileUpload(currentlyBeingEditedAnalysisReportId)} |
89 | 92 | </Modal> |
90 | 93 | ); |
| 94 | + const { |
| 95 | + analysisPluginTypes: allReportTypes, |
| 96 | + analysisPluginCategories: allReportCategories, |
| 97 | + } = useSelector((state: RootState) => state.config); |
| 98 | + |
| 99 | + const availableReportTypes = (intersection( |
| 100 | + uniq(flatten(map(analysisReports, 'types'))), |
| 101 | + allReportTypes.map(({ label }) => label) |
| 102 | + ) as string[]).map(l => { |
| 103 | + const typeDescription = allReportTypes.find(t => t.label === l) |
| 104 | + ?.description as string; |
| 105 | + return { label: l, description: typeDescription }; |
| 106 | + }); |
| 107 | + |
| 108 | + const categoriesDefinedForContainerTypes = intersection( |
| 109 | + Object.keys(allReportCategories), |
| 110 | + containerResourceTypes |
| 111 | + ); |
| 112 | + |
| 113 | + const allReportCategoriesMatchingContainerType = |
| 114 | + categoriesDefinedForContainerTypes.length > 0 |
| 115 | + ? allReportCategories[categoriesDefinedForContainerTypes[0]] |
| 116 | + : []; |
| 117 | + |
| 118 | + const availableReportCategories = (intersection( |
| 119 | + uniq(flatten(map(analysisReports, 'categories'))), |
| 120 | + allReportCategoriesMatchingContainerType.map(({ label }) => label) |
| 121 | + ) as string[]).map(l => { |
| 122 | + const categoryDescription = allReportCategoriesMatchingContainerType.find( |
| 123 | + c => c.label === l |
| 124 | + )?.description as string; |
| 125 | + return { label: l, description: categoryDescription }; |
| 126 | + }); |
91 | 127 |
|
92 | 128 | return ( |
93 | 129 | <> |
94 | 130 | {mode === 'create' && ( |
95 | 131 | <NewReportForm |
| 132 | + categories={allReportCategoriesMatchingContainerType} |
| 133 | + types={allReportTypes} |
96 | 134 | dispatch={dispatch} |
97 | 135 | onSave={onSave} |
98 | 136 | FileUpload={FileUpload} |
@@ -121,18 +159,19 @@ const AnalysisPlugin = ({ |
121 | 159 | <FolderAddOutlined /> |
122 | 160 | </Button> |
123 | 161 | <CategoryWidget |
124 | | - dispatch={dispatch} |
| 162 | + allCategories={allReportCategoriesMatchingContainerType} |
| 163 | + availableCategories={availableReportCategories} |
125 | 164 | mode={mode} |
126 | 165 | selectedCategories={selectedCategories} |
127 | | - selectCategory={selectCategory} |
128 | | - analysisReports={analysisReports} |
| 166 | + toggleSelectCategory={selectCategory} |
129 | 167 | /> |
| 168 | + |
130 | 169 | <TypeWidget |
131 | | - dispatch={dispatch} |
| 170 | + allTypes={allReportTypes} |
| 171 | + availableTypes={availableReportTypes} |
132 | 172 | mode={mode} |
133 | 173 | selectedTypes={selectedTypes} |
134 | | - selectType={selectType} |
135 | | - analysisReports={analysisReports} |
| 174 | + toggleSelectType={selectType} |
136 | 175 | /> |
137 | 176 | </> |
138 | 177 | )} |
@@ -341,7 +380,6 @@ const AnalysisPlugin = ({ |
341 | 380 | aria-label="Edit Report" |
342 | 381 | style={{ |
343 | 382 | background: 'transparent', |
344 | | - padding: '12px', |
345 | 383 | }} |
346 | 384 | icon={<EditOutlined />} |
347 | 385 | title="Edit report" |
@@ -480,6 +518,9 @@ const AnalysisPlugin = ({ |
480 | 518 | {mode === 'edit' && ( |
481 | 519 | <section> |
482 | 520 | <CategoryEditWidget |
| 521 | + allCategories={ |
| 522 | + allReportCategoriesMatchingContainerType |
| 523 | + } |
483 | 524 | dispatch={dispatch} |
484 | 525 | currentlyBeingEditedAnalysisReportCategories={ |
485 | 526 | currentlyBeingEditedAnalysisReportCategories |
|
0 commit comments