@@ -12,41 +12,35 @@ import {
1212 SelectOption ,
1313 PageSection
1414} from '@patternfly/react-core' ;
15- import { TableComposable , Thead , Tr , Th , Tbody , Td , ActionsColumn } from '@patternfly/react-table' ;
15+ import { TableComposable , Thead , Tr , Th , Tbody , Td } from '@patternfly/react-table' ;
1616
1717import FilterIcon from '@patternfly/react-icons/dist/esm/icons/filter-icon' ;
18- import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon' ;
1918import DashboardWrapper from '@patternfly/react-core/src/demos/examples/DashboardWrapper' ;
19+ import { rows , columns } from '../../examples/Data.jsx' ;
2020
21- export const ComposableTable = ( ) => {
21+ export const CompactTable = ( ) => {
2222 const [ isSelectOpen , setIsSelectOpen ] = React . useState ( false ) ;
23+ const [ page , setPage ] = React . useState ( 1 ) ;
24+ const [ perPage , setPerPage ] = React . useState ( 10 ) ;
25+ const [ paginatedRows , setPaginatedRows ] = React . useState ( rows . slice ( 0 , 10 ) ) ;
26+ const handleSetPage = ( _evt , newPage , perPage , startIdx , endIdx ) => {
27+ setPaginatedRows ( rows . slice ( startIdx , endIdx ) ) ;
28+ setPage ( newPage ) ;
29+ } ;
30+ handlePerPageSelect = ( _evt , newPerPage , newPage , startIdx , endIdx ) => {
31+ setPaginatedRows ( rows . slice ( startIdx , endIdx ) ) ;
32+ setPage ( newPage ) ;
33+ setPerPage ( newPerPage ) ;
34+ } ;
2335
24- const columns = [ 'Contributor' , 'Position' , 'Location' , 'Last seen' , 'Numbers' , 'Icons' ] ;
25- const rows = [
26- [ 'Sam Jones' , 'CSS guru' , 'Not too sure' , 'May 9, 2018' , '0556' ] ,
27- [ 'Amy Miller' , 'Visual design' , 'Raleigh' , 'May 9, 2018' , '9492' ] ,
28- [ 'Steve Wilson' , 'Visual design lead' , 'Westford' , 'May 9, 2018' , '9929' ] ,
29- [ 'Emma Jackson' , 'Interaction design' , 'Westford' , 'May 9, 2018' , '2217' ]
30- ] ;
31-
32- const defaultActions = ( ) => [
33- {
34- title : 'Settings' ,
35- // eslint-disable-next-line no-console
36- onClick : ( ) => console . log ( `clicked on Settings` )
37- } ,
38- {
39- title : 'Help' ,
40- // eslint-disable-next-line no-console
41- onClick : ( ) => console . log ( `clicked on Help` )
42- }
43- ] ;
4436 const renderPagination = ( variant , isCompact ) => (
4537 < Pagination
4638 isCompact = { isCompact }
47- itemCount = { 36 }
48- page = { 1 }
49- perPage = { 10 }
39+ itemCount = { rows . length }
40+ page = { page }
41+ perPage = { perPage }
42+ onSetPage = { handleSetPage }
43+ onPerPageSelect = { handlePerPageSelect }
5044 variant = { variant }
5145 titles = { {
5246 paginationTitle : `${ variant } pagination`
@@ -89,37 +83,54 @@ export const ComposableTable = () => {
8983 </ Toolbar >
9084 ) ;
9185
86+ const renderLabel = labelText => {
87+ switch ( labelText ) {
88+ case 'Running' :
89+ return < Label color = "green" > { labelText } </ Label > ;
90+ case 'Stopped' :
91+ return < Label color = "orange" > { labelText } </ Label > ;
92+ case 'Needs Maintenance' :
93+ return < Label color = "blue" > { labelText } </ Label > ;
94+ case 'Down' :
95+ return < Label color = "red" > { labelText } </ Label > ;
96+ }
97+ } ;
9298 return (
9399 < React . Fragment >
94100 < DashboardWrapper hasPageTemplateTitle >
95101 < PageSection isFilled >
96102 < Card >
97103 { tableToolbar }
98- < TableComposable variant = "compact" aria-label = "Sortable Table" >
104+ < TableComposable variant = "compact" aria-label = "Compact Table" >
99105 < Thead >
100106 < Tr >
101- { columns . map ( ( column , columnIndex ) => (
102- < Th key = { columnIndex } > { column } </ Th >
103- ) ) }
107+ < Th key = { 0 } > { columns [ 0 ] } </ Th >
108+ < Th key = { 1 } > { columns [ 1 ] } </ Th >
109+ < Th key = { 2 } > { columns [ 2 ] } </ Th >
110+ < Th key = { 3 } > { columns [ 3 ] } </ Th >
111+ < Th key = { 4 } > { columns [ 4 ] } </ Th >
112+ < Th key = { 5 } > { columns [ 5 ] } </ Th >
113+ < Th key = { 6 } > { columns [ 6 ] } </ Th >
114+ < Th key = { 7 } width = { 10 } >
115+ { columns [ 7 ] }
116+ </ Th >
104117 </ Tr >
105118 </ Thead >
106119 < Tbody >
107- { rows . map ( ( row , rowIndex ) => (
120+ { paginatedRows . map ( ( row , rowIndex ) => (
108121 < Tr key = { rowIndex } >
109122 < >
110- < Td dataLabel = { columns [ 0 ] } > { row [ 0 ] } </ Td >
111- < Td dataLabel = { columns [ 1 ] } > { row [ 1 ] } </ Td >
112- < Td dataLabel = { columns [ 2 ] } > { row [ 2 ] } </ Td >
113- < Td dataLabel = { columns [ 3 ] } > { row [ 3 ] } </ Td >
114- < Td dataLabel = { columns [ 4 ] } > { row [ 4 ] } </ Td >
115- < Td dataLabel = { columns [ 5 ] } >
116- < CheckIcon key = "icon" />
117- </ Td >
118- < Td dataLabel = { 'Action' } >
119- < a href = "#" > Action link</ a >
120- </ Td >
121- < Td isActionCell >
122- < ActionsColumn items = { defaultActions ( ) } />
123+ < Td dataLabel = { columns [ 0 ] } > { row . name } </ Td >
124+ < Td dataLabel = { columns [ 1 ] } > { row . threads } </ Td >
125+ < Td dataLabel = { columns [ 2 ] } > { row . applications } </ Td >
126+ < Td dataLabel = { columns [ 3 ] } > { row . workspaces } </ Td >
127+ < Td dataLabel = { columns [ 4 ] } > { renderLabel ( row . status ) } </ Td >
128+ < Td dataLabel = { columns [ 5 ] } > { row . location } </ Td >
129+ < Td dataLabel = { columns [ 6 ] } > { row . lastModified } </ Td >
130+ < Td dataLabel = { columns [ 7 ] } modifier = "truncate" >
131+ < TableText >
132+ < a href = "#" > { row . url } </ a >
133+ </ TableText >
123134 </ Td >
124135 </ >
125136 </ Tr >
0 commit comments