Skip to content

Commit 8e34f98

Browse files
authored
chore(storage-browser): add file extension as column type (#5641)
1 parent 43b069e commit 8e34f98

File tree

3 files changed

+75
-26
lines changed

3 files changed

+75
-26
lines changed

packages/react-storage/src/components/StorageBrowser/Views/Controls/Table.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export const LocationDetailViewTable = (): JSX.Element | null => {
411411
// @TODO: This should be it's own component instead of using `useCallback`
412412
const renderRowItem: RenderRowItem<LocationItem> = React.useCallback(
413413
(row, index) => {
414-
const parseTableData = (
414+
const renderTableData = (
415415
row: LocationItem,
416416
column: Column<LocationItem>
417417
) => {
@@ -441,6 +441,15 @@ export const LocationDetailViewTable = (): JSX.Element | null => {
441441
case 'download' as keyof LocationItem: {
442442
return <DownloadControl fileKey={`${path}${row.key}`} />;
443443
}
444+
case 'type': {
445+
const indexOfDot = row.key.lastIndexOf('.');
446+
447+
return indexOfDot > -1 ? (
448+
<TableDataText>{row.key.slice(indexOfDot + 1)}</TableDataText>
449+
) : (
450+
'-'
451+
);
452+
}
444453
case 'key': {
445454
return (
446455
<TableDataText>
@@ -477,6 +486,9 @@ export const LocationDetailViewTable = (): JSX.Element | null => {
477486
</TableDataButton>
478487
);
479488
}
489+
case 'type': {
490+
return <TableDataText>Folder</TableDataText>;
491+
}
480492
default:
481493
return <TableDataText>{row[column.key]}</TableDataText>;
482494
}
@@ -489,7 +501,7 @@ export const LocationDetailViewTable = (): JSX.Element | null => {
489501
{LOCATION_DETAIL_VIEW_COLUMNS.map((column) => {
490502
return (
491503
<TableData key={`${index}-${column.header}`} variant={column.key}>
492-
{parseTableData(row, column)}
504+
{renderTableData(row, column)}
493505
</TableData>
494506
);
495507
})}

packages/react-storage/src/components/StorageBrowser/Views/LocationActionView/UploadControls.tsx

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ const { Icon, DefinitionDetail, DefinitionList, DefinitionTerm } =
2727

2828
const { 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;

packages/react-storage/src/components/StorageBrowser/Views/LocationActionView/__tests__/UploadControls.spec.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const navigateState = {
2727
scope: 's3://test-bucket/*',
2828
type: 'BUCKET',
2929
},
30+
path: 'path',
3031
history: [
3132
{ prefix: '', position: 0 },
3233
{ prefix: 'folder1/', position: 1 },

0 commit comments

Comments
 (0)