1- import { TableVariant } from '@patternfly/react-table' ;
2- import { InventoryTable } from '@redhat-cloud-services/frontend-components/Inventory' ;
1+
32import propTypes from 'prop-types' ;
4- import React , { useCallback } from 'react' ;
5- import { shallowEqual , useDispatch , useSelector , useStore } from 'react-redux' ;
6- import { combineReducers } from 'redux' ;
7- import messages from '../../Messages' ;
8- import searchFilter from '../../PresentationalComponents/Filters/SearchFilter' ;
3+ import React , { useState , useEffect } from 'react' ;
4+ import { useDispatch , useSelector } from 'react-redux' ;
95import ErrorHandler from '../../PresentationalComponents/Snippets/ErrorHandler' ;
10- import { defaultReducers } from '../../store' ;
116import { changeAffectedSystemsParams , clearAdvisorySystemsReducer ,
12- clearInventoryReducer , systemSelectAction } from '../../store/Actions/Actions' ;
13- import { inventoryEntitiesReducer , modifyAdvisorySystems } from '../../store/Reducers/InventoryEntitiesReducer' ;
14- import { exportAdvisorySystemsCSV , exportAdvisorySystemsJSON , fetchAdvisorySystems } from '../../Utilities/api' ;
15- import { remediationIdentifiers } from '../../Utilities/constants' ;
7+ clearInventoryReducer } from '../../store/Actions/Actions' ;
168import {
17- arrayFromObj , decodeQueryparams , persistantParams ,
18- remediationProvider , removeUndefinedObjectKeys
9+ decodeQueryparams
1910} from '../../Utilities/Helpers' ;
20- import {
21- useBulkSelectConfig , useGetEntities , useOnExport , useRemoveFilter , useOnSelect , ID_API_ENDPOINTS
22- } from '../../Utilities/hooks' ;
23- import { intl } from '../../Utilities/IntlProvider' ;
24- import { advisorySystemsColumns , systemsRowActions } from '../Systems/SystemsListAssets' ;
2511import RemediationWizard from '../Remediation/RemediationWizard' ;
26- import AsyncRemediationButton from '../Remediation/AsyncRemediationButton' ;
27- import { systemsColumnsMerger , buildActiveFiltersConfig } from '../../Utilities/SystemsHelpers' ;
28- import advisoryStatusFilter from '../../PresentationalComponents/Filters/AdvisoryStatusFilter' ;
2912import { useSearchParams } from 'react-router-dom' ;
13+ import { useActivateRemediationModal } from '../Systems/SystemsListAssets' ;
14+ import AdvisorySystemsTable from './AdvisorySystemsTable' ;
3015
3116const AdvisorySystems = ( { advisoryName } ) => {
3217 const dispatch = useDispatch ( ) ;
33- const store = useStore ( ) ;
3418 const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
3519
36- const [ isRemediationOpen , setRemediationOpen ] = React . useState ( false ) ;
37- const [
38- RemediationModalCmp ,
39- setRemediationModalCmp
40- ] = React . useState ( ( ) => ( ) => null ) ;
20+ const [ isRemediationOpen , setRemediationOpen ] = useState ( false ) ;
21+ const [ remediationIssues , setRemediationIssues ] = useState ( [ ] ) ;
4122
4223 const decodedParams = decodeQueryparams ( '?' + searchParams . toString ( ) ) ;
43- const systems = useSelector ( ( { entities } ) => entities ?. rows || [ ] , shallowEqual ) ;
4424 const status = useSelector (
4525 ( { entities } ) => entities ?. status || { }
4626 ) ;
47- const totalItems = useSelector (
48- ( { entities } ) => entities ?. total || 0
49- ) ;
50- const queryParams = useSelector (
51- ( { AdvisorySystemsStore } ) => AdvisorySystemsStore ?. queryParams || { }
52- ) ;
53- const selectedRows = useSelector (
54- ( { entities } ) => entities ?. selectedRows || [ ]
55- ) ;
5627 const metadata = useSelector (
5728 ( { AdvisorySystemsStore } ) => AdvisorySystemsStore ?. metadata || { }
5829 ) ;
5930
60- const { systemProfile, selectedTags,
61- filter, search, page, perPage, sort } = queryParams ;
62-
63- React . useEffect ( ( ) => {
31+ useEffect ( ( ) => {
6432 apply ( decodedParams ) ;
6533 return ( ) => {
6634 dispatch ( clearInventoryReducer ( ) ) ;
@@ -72,117 +40,32 @@ const AdvisorySystems = ({ advisoryName }) => {
7240 dispatch ( changeAffectedSystemsParams ( params ) ) ;
7341 }
7442
75- const [ deleteFilters ] = useRemoveFilter ( { search, ...filter } , apply ) ;
76-
77- const filterConfig = {
78- items : [
79- searchFilter ( apply , search ,
80- intl . formatMessage ( messages . labelsFiltersSystemsSearchTitle ) ,
81- intl . formatMessage ( messages . labelsFiltersSystemsSearchPlaceholder )
82- ) ,
83- advisoryStatusFilter ( apply , filter )
84- ]
85- } ;
86-
87- const activeFiltersConfig = buildActiveFiltersConfig ( filter , search , deleteFilters ) ;
88-
89- const showRemediationModal = useCallback ( async ( data ) => {
90- const resolvedData = await data ;
91- setRemediationModalCmp ( ( ) =>
92- ( ) => < RemediationWizard
93- data = { resolvedData }
94- isRemediationOpen
95- setRemediationOpen = { setRemediationOpen } /> ) ;
96- setRemediationOpen ( ! isRemediationOpen ) ;
97- } , [ isRemediationOpen ] ) ;
98-
99- const onSelect = useOnSelect (
100- systems ,
101- selectedRows ,
102- {
103- endpoint : ID_API_ENDPOINTS . advisorySystems ( advisoryName ) ,
104- queryParams,
105- selectionDispatcher : systemSelectAction ,
106- totalItems
107- }
43+ const activateRemediationModal = useActivateRemediationModal (
44+ setRemediationIssues ,
45+ setRemediationOpen
10846 ) ;
10947
110- const selectedCount = selectedRows && arrayFromObj ( selectedRows ) . length ;
111-
112- const getEntites = useGetEntities ( fetchAdvisorySystems , apply , { id : advisoryName } , setSearchParams ) ;
113-
114- const onExport = useOnExport ( advisoryName , queryParams , {
115- csv : exportAdvisorySystemsCSV ,
116- json : exportAdvisorySystemsJSON
117- } , dispatch ) ;
118-
119- const remediationDataProvider = ( ) => remediationProvider (
120- advisoryName ,
121- removeUndefinedObjectKeys ( selectedRows ) ,
122- remediationIdentifiers . advisory
123- ) ;
124-
125- const bulkSelectConfig = useBulkSelectConfig (
126- selectedCount , onSelect , { total_items : totalItems } , systems , null , queryParams
127- ) ;
48+ if ( status . hasError || metadata ?. has_systems === false ) {
49+ return < ErrorHandler code = { status . code } metadata = { metadata } /> ;
50+ }
12851
12952 return (
13053 < React . Fragment >
131- { isRemediationOpen && < RemediationModalCmp /> || null }
132- { ( status . hasError || metadata ?. has_systems === false )
133- && < ErrorHandler code = { status . code } metadata = { metadata } />
134- || < InventoryTable
135- isFullView
136- autoRefresh
137- initialLoading
138- ignoreRefresh
139- hideFilters = { { all : true , tags : false , operatingSystem : false } }
140- columns = { ( defaultColumns ) => systemsColumnsMerger ( defaultColumns , advisorySystemsColumns ) }
141- showTags
142- customFilters = { {
143- patchParams : {
144- search,
145- filter,
146- systemProfile,
147- selectedTags
148- }
149- } }
150- paginationProps = { {
151- isDisabled : totalItems === 0
152- } }
153- onLoad = { ( { mergeWithEntities } ) => {
154- store . replaceReducer ( combineReducers ( {
155- ...defaultReducers ,
156- ...mergeWithEntities (
157- inventoryEntitiesReducer ( advisorySystemsColumns ( false ) , modifyAdvisorySystems ) ,
158- persistantParams ( { page, perPage, sort, search } , decodedParams )
159- )
160- } ) ) ;
161- } }
162- getEntities = { getEntites }
163- tableProps = { {
164- actionResolver : ( row ) => systemsRowActions ( showRemediationModal , undefined , undefined , row ) ,
165- canSelectAll : false ,
166- variant : TableVariant . compact , className : 'patchCompactInventory' , isStickyHeader : true
167- } }
168- filterConfig = { filterConfig }
169- activeFiltersConfig = { activeFiltersConfig }
170- exportConfig = { {
171- isDisabled : totalItems === 0 ,
172- onSelect : onExport
173- } }
174- bulkSelect = { onSelect && bulkSelectConfig }
175- dedicatedAction = { (
176- < AsyncRemediationButton
177- remediationProvider = { remediationDataProvider }
178- isDisabled = {
179- arrayFromObj ( selectedRows ) . length === 0
180- }
181- />
182- ) }
183-
184- />
54+ { isRemediationOpen &&
55+ < RemediationWizard
56+ data = { remediationIssues }
57+ isRemediationOpen
58+ setRemediationOpen = { setRemediationOpen }
59+ />
60+ || null
18561 }
62+ < AdvisorySystemsTable
63+ setSearchParams = { setSearchParams }
64+ activateRemediationModal = { activateRemediationModal }
65+ advisoryName = { advisoryName }
66+ decodedParams = { decodedParams }
67+ apply = { apply }
68+ />
18669 </ React . Fragment >
18770 ) ;
18871} ;
0 commit comments