-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable customization of displayText for location detail view dat…
…aTable headers (#6346) * fix: enable customization of displayText for location detail view dataTable headers * fix: update location detail view test to include displayText * chore: converting default headers to string array, adding unit tests
- Loading branch information
Showing
9 changed files
with
184 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@aws-amplify/ui-react-storage': patch | ||
--- | ||
|
||
Fixed displayText override for LocationDetailView dataTable headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...wser/views/LocationDetailView/getLocationDetailViewTableData/__tests__/getHeaders.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getHeaders } from '../getHeaders'; | ||
|
||
describe('getHeaders', () => { | ||
const mockProps = { | ||
tableColumnLastModifiedHeader: 'Custom Last Modified', | ||
tableColumnNameHeader: 'Custom Name', | ||
tableColumnSizeHeader: 'Custom Size', | ||
tableColumnTypeHeader: 'Custom Type', | ||
areAllFilesSelected: false, | ||
selectAllFilesLabel: 'Select all files', | ||
onSelectAll: jest.fn(), | ||
hasFiles: true, | ||
}; | ||
|
||
it('should return correct headers when files exist', () => { | ||
const result = getHeaders(mockProps); | ||
|
||
expect(result).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
content: { label: mockProps.tableColumnNameHeader }, | ||
}), | ||
expect.objectContaining({ | ||
content: { label: mockProps.tableColumnTypeHeader }, | ||
}), | ||
expect.objectContaining({ | ||
content: { label: mockProps.tableColumnSizeHeader }, | ||
}), | ||
expect.objectContaining({ | ||
content: { label: mockProps.tableColumnLastModifiedHeader }, | ||
}), | ||
]) | ||
); | ||
}); | ||
|
||
it('should include checkbox column when hasFiles is true', () => { | ||
const result = getHeaders(mockProps); | ||
|
||
const checkboxColumn = result.find((header) => header.type === 'checkbox'); | ||
expect(checkboxColumn).toBeDefined(); | ||
}); | ||
|
||
it('should not include checkbox column when hasFiles is false', () => { | ||
const result = getHeaders({ | ||
...mockProps, | ||
hasFiles: false, | ||
}); | ||
|
||
const checkboxColumn = result.find((header) => header.type === 'checkbox'); | ||
expect(checkboxColumn).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletions
16
...nents/StorageBrowser/views/LocationDetailView/getLocationDetailViewTableData/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { LocationDetailViewHeaders } from './types'; | ||
import { HeaderKeys } from './types'; | ||
|
||
export const LOCATION_DETAIL_VIEW_HEADERS: LocationDetailViewHeaders = [ | ||
{ key: 'checkbox', type: 'text', content: { text: '' } }, | ||
{ key: 'name', type: 'sort', content: { label: 'Name' } }, | ||
{ key: 'type', type: 'sort', content: { label: 'Type' } }, | ||
{ key: 'last-modified', type: 'sort', content: { label: 'Last modified' } }, | ||
{ key: 'size', type: 'sort', content: { label: 'Size' } }, | ||
{ key: 'download', type: 'text', content: { text: '' } }, | ||
export const LOCATION_DETAIL_VIEW_HEADERS: HeaderKeys[] = [ | ||
'checkbox', | ||
'name', | ||
'type', | ||
'last-modified', | ||
'size', | ||
'download', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ents/StorageBrowser/views/LocationDetailView/getLocationDetailViewTableData/getHeaders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { LocationDetailViewHeaders } from './types'; | ||
import { LOCATION_DETAIL_VIEW_HEADERS } from './constants'; | ||
|
||
export const getHeaders = ({ | ||
tableColumnLastModifiedHeader, | ||
tableColumnNameHeader, | ||
tableColumnSizeHeader, | ||
tableColumnTypeHeader, | ||
areAllFilesSelected, | ||
selectAllFilesLabel, | ||
onSelectAll, | ||
hasFiles, | ||
}: { | ||
tableColumnLastModifiedHeader: string; | ||
tableColumnNameHeader: string; | ||
tableColumnSizeHeader: string; | ||
tableColumnTypeHeader: string; | ||
areAllFilesSelected: boolean; | ||
selectAllFilesLabel: string; | ||
onSelectAll: () => void; | ||
hasFiles: boolean; | ||
}): LocationDetailViewHeaders => | ||
LOCATION_DETAIL_VIEW_HEADERS.map((key) => { | ||
switch (key) { | ||
case 'checkbox': { | ||
if (hasFiles) { | ||
return { | ||
key, | ||
type: 'checkbox', | ||
content: { | ||
checked: areAllFilesSelected, | ||
label: selectAllFilesLabel, | ||
id: 'header-checkbox', | ||
onSelect: onSelectAll, | ||
}, | ||
}; | ||
} else { | ||
return { | ||
key, | ||
type: 'text', | ||
content: { text: '' }, | ||
}; | ||
} | ||
} | ||
case 'name': { | ||
return { | ||
key, | ||
type: 'sort', | ||
content: { | ||
label: tableColumnNameHeader, | ||
}, | ||
}; | ||
} | ||
case 'type': { | ||
return { | ||
key, | ||
type: 'sort', | ||
content: { | ||
label: tableColumnTypeHeader, | ||
}, | ||
}; | ||
} | ||
case 'last-modified': { | ||
return { | ||
key, | ||
type: 'sort', | ||
content: { | ||
label: tableColumnLastModifiedHeader, | ||
}, | ||
}; | ||
} | ||
case 'size': { | ||
return { | ||
key, | ||
type: 'sort', | ||
content: { | ||
label: tableColumnSizeHeader, | ||
}, | ||
}; | ||
} | ||
case 'download': { | ||
return { key, type: 'text', content: { text: '' } }; | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters