11import * as React from 'react' ;
22import { useTranslation } from 'react-i18next' ;
3- import { useSearchParams } from 'react-router-dom-v5-compat' ;
43import ExternalLink from 'src/components/utils/ExternalLink/ExternalLink' ;
54
65import ArgoCDLink from '@gitops/components/shared/ArgoCDLink/ArgoCDLink' ;
@@ -10,14 +9,11 @@ import { repoUrl } from '@gitops/utils/urls';
109import { ApplicationHistory , ApplicationKind } from '@gitops-models/ApplicationModel' ;
1110import { Timestamp , useK8sModel } from '@openshift-console/dynamic-plugin-sdk' ;
1211import { EmptyState , EmptyStateBody } from '@patternfly/react-core' ;
13- import DataView , { DataViewState } from '@patternfly/react-data-view/dist/esm/DataView' ;
14- import DataViewTable , {
15- DataViewTh ,
16- DataViewTr ,
17- } from '@patternfly/react-data-view/dist/esm/DataViewTable' ;
18- import { useDataViewSort } from '@patternfly/react-data-view/dist/esm/Hooks' ;
12+ import { DataViewTh , DataViewTr } from '@patternfly/react-data-view/dist/esm/DataViewTable' ;
1913import { CubesIcon } from '@patternfly/react-icons' ;
20- import { Tbody , Td , Tr } from '@patternfly/react-table' ;
14+ import { Tbody , Td , ThProps , Tr } from '@patternfly/react-table' ;
15+
16+ import { GitOpsDataViewTable , useGitOpsDataViewSort } from '../../shared/DataView' ;
2117
2218import './History.scss' ;
2319
@@ -28,34 +24,12 @@ interface HistoryListProps {
2824
2925const HistoryList : React . FC < HistoryListProps > = ( { history, obj } ) => {
3026 const { t } = useTranslation ( 'plugin__gitops-plugin' ) ;
31- const COLUMNS_KEYS_INDEXES = React . useMemo (
32- ( ) => [
33- { key : 'id' , index : 0 } ,
34- { key : 'started-at' , index : 1 } ,
35- { key : 'deployed-at' , index : 2 } ,
36- { key : 'initiated-by' , index : 3 } ,
37- { key : 'revision' , index : 4 } ,
38- ] ,
27+ const columnSortConfig = React . useMemo (
28+ ( ) => [ 'id' , 'started-at' , 'deployed-at' , 'initiated-by' , 'revision' ] . map ( ( key ) => ( { key } ) ) ,
3929 [ ] ,
4030 ) ;
4131
42- const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
43- const { sortBy, direction, onSort } = useDataViewSort ( { searchParams, setSearchParams } ) ;
44- const sortByIndex = React . useMemo (
45- ( ) => COLUMNS_KEYS_INDEXES . findIndex ( ( item ) => item . key === sortBy ) ,
46- [ COLUMNS_KEYS_INDEXES , sortBy ] ,
47- ) ;
48- const getSortParams = ( columnIndex : number ) => ( {
49- sortBy : {
50- index : sortByIndex ,
51- direction,
52- defaultDirection : 'asc' as const ,
53- } ,
54- onSort : ( _event : any , index : number , dir : 'asc' | 'desc' ) => {
55- onSort ( _event , COLUMNS_KEYS_INDEXES [ index ] . key , dir ) ;
56- } ,
57- columnIndex,
58- } ) ;
32+ const { sortBy, direction, getSortParams } = useGitOpsDataViewSort ( columnSortConfig ) ;
5933 const columnsDV = useColumnsDV ( getSortParams ) ;
6034
6135 const sortedHistory = React . useMemo ( ( ) => {
@@ -64,11 +38,6 @@ const HistoryList: React.FC<HistoryListProps> = ({ history, obj }) => {
6438
6539 const rows = useRowsDV ( sortedHistory , obj ) ;
6640
67- let currentActiveState = null ;
68- if ( rows . length === 0 ) {
69- currentActiveState = DataViewState . empty ;
70- }
71-
7241 const [ model ] = useK8sModel ( { group : 'route.openshift.io' , version : 'v1' , kind : 'Route' } ) ;
7342 const [ argoServer , setArgoServer ] = React . useState < ArgoServer > ( { host : '' , protocol : '' } ) ;
7443
@@ -117,9 +86,12 @@ const HistoryList: React.FC<HistoryListProps> = ({ history, obj }) => {
11786 '&view=tree&resource=&operation=false&rollback=0'
11887 }
11988 />
120- < DataView activeState = { currentActiveState } >
121- < DataViewTable rows = { rows } columns = { columnsDV } bodyStates = { empty && { empty } } />
122- </ DataView >
89+ < GitOpsDataViewTable
90+ rows = { rows }
91+ columns = { columnsDV }
92+ emptyState = { empty }
93+ isEmpty = { rows . length === 0 }
94+ />
12395 </ div >
12496 ) ;
12597} ;
@@ -223,7 +195,7 @@ const useRowsDV = (history: ApplicationHistory[], app: ApplicationKind): DataVie
223195 return rows . reverse ( ) ;
224196} ;
225197
226- const useColumnsDV = ( getSortParams ) => {
198+ const useColumnsDV = ( getSortParams : ( columnIndex : number ) => ThProps [ 'sort' ] ) => {
227199 const { t } = useTranslation ( 'plugin__gitops-plugin' ) ;
228200 const columns : DataViewTh [ ] = [
229201 {
0 commit comments