@@ -27,11 +27,19 @@ const { Icon, DefinitionDetail, DefinitionList, DefinitionTerm } =
2727
2828const { Cancel, Exit, Primary, Summary, Table } = Controls ;
2929
30- const LOCATION_ACTION_VIEW_COLUMNS : Column < CancelableTask > [ ] = [
30+ interface LocationActionViewColumns extends CancelableTask {
31+ type : string ;
32+ }
33+
34+ const LOCATION_ACTION_VIEW_COLUMNS : Column < LocationActionViewColumns > [ ] = [
3135 {
3236 key : 'key' ,
3337 header : 'Name' ,
3438 } ,
39+ {
40+ key : 'type' ,
41+ header : 'Type' ,
42+ } ,
3543 {
3644 key : 'size' ,
3745 header : 'Size' ,
@@ -105,9 +113,46 @@ const LocationActionViewColumnSortMap = {
105113 size : compareNumbers ,
106114 status : compareStrings ,
107115 progress : compareNumbers ,
116+ type : compareStrings ,
108117} ;
109118
110- const renderRowItem : RenderRowItem < CancelableTask > = ( row , index ) => {
119+ const renderRowItem : RenderRowItem < LocationActionViewColumns > = (
120+ row ,
121+ index
122+ ) => {
123+ const renderTableData = (
124+ columnKey : keyof LocationActionViewColumns ,
125+ row : LocationActionViewColumns
126+ ) => {
127+ switch ( columnKey ) {
128+ case 'key' :
129+ return (
130+ < TableDataText >
131+ < ActionIcon status = { row . status } />
132+ { row . key }
133+ </ TableDataText >
134+ ) ;
135+ case 'type' : {
136+ return < TableDataText > { row . type } </ TableDataText > ;
137+ }
138+ case 'size' :
139+ return < TableDataText > { humanFileSize ( row . size , true ) } </ TableDataText > ;
140+ case 'status' :
141+ return < TableDataText > { row . status } </ TableDataText > ;
142+ case 'progress' :
143+ return < TableDataText > { row . progress } </ TableDataText > ;
144+ case 'cancel' :
145+ return (
146+ < Cancel
147+ onClick = { row . cancel }
148+ ariaLabel = { `Cancel upload for ${ row . key } ` }
149+ />
150+ ) ;
151+ default :
152+ return null ;
153+ }
154+ } ;
155+
111156 return (
112157 < Table . TableRow key = { index } >
113158 { LOCATION_ACTION_VIEW_COLUMNS . map ( ( column ) => {
@@ -116,23 +161,7 @@ const renderRowItem: RenderRowItem<CancelableTask> = (row, index) => {
116161 key = { `${ index } -${ column . header } ` }
117162 variant = { column . key }
118163 >
119- { column . key === 'key' ? (
120- < TableDataText >
121- < ActionIcon status = { row . status } />
122- { row . key }
123- </ TableDataText >
124- ) : column . key === 'size' ? (
125- < TableDataText > { humanFileSize ( row . size , true ) } </ TableDataText >
126- ) : column . key === 'status' ? (
127- < TableDataText > { row . status } </ TableDataText >
128- ) : column . key === 'progress' ? (
129- < TableDataText > { row . progress } </ TableDataText >
130- ) : column . key === 'cancel' ? (
131- < Cancel
132- onClick = { row . cancel }
133- ariaLabel = { `Cancel upload for ${ row . key } ` }
134- />
135- ) : null }
164+ { renderTableData ( column . key , row ) }
136165 </ Table . TableData >
137166 ) ;
138167 } ) }
@@ -169,6 +198,11 @@ export const UploadControls = (): JSX.Element => {
169198 files,
170199 } ) ;
171200
201+ let tableData = tasks . map ( ( task ) => ( {
202+ ...task ,
203+ type : task . data . type ?? '-' ,
204+ } ) ) ;
205+
172206 const { options } = actions [ selected . type ! ] ;
173207 const { selectionData } = options ?? { } ;
174208
@@ -182,20 +216,22 @@ export const UploadControls = (): JSX.Element => {
182216 const [ compareFn , setCompareFn ] = React . useState < ( a : any , b : any ) => number > (
183217 ( ) => compareStrings
184218 ) ;
185- const [ sortState , setSortState ] = React . useState < SortState < CancelableTask > > ( {
219+ const [ sortState , setSortState ] = React . useState <
220+ SortState < LocationActionViewColumns >
221+ > ( {
186222 selection : 'key' ,
187223 direction : 'ascending' ,
188224 } ) ;
189225
190226 const { direction, selection } = sortState ;
191227
192- const tableData =
228+ tableData =
193229 direction === 'ascending'
194- ? tasks . sort ( ( a , b ) => compareFn ( a [ selection ] , b [ selection ] ) )
195- : tasks . sort ( ( a , b ) => compareFn ( b [ selection ] , a [ selection ] ) ) ;
230+ ? tableData . sort ( ( a , b ) => compareFn ( a [ selection ] , b [ selection ] ) )
231+ : tableData . sort ( ( a , b ) => compareFn ( b [ selection ] , a [ selection ] ) ) ;
196232
197233 const renderHeaderItem = React . useCallback (
198- ( column : Column < CancelableTask > ) => {
234+ ( column : Column < LocationActionViewColumns > ) => {
199235 // Defining this function inside the `UploadControls` to get access
200236 // to the current sort state
201237 const { header, key } = column ;
0 commit comments