-
Notifications
You must be signed in to change notification settings - Fork 313
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(content-explorer): Migrate IconCell (#3804)
- Loading branch information
1 parent
d3b6613
commit ea97280
Showing
17 changed files
with
518 additions
and
565 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
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
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,49 @@ | ||
import * as React from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
|
||
import { Archive, FolderArchive, FileBookmark } from '@box/blueprint-web-assets/icons/Content'; | ||
import FileIcon from '../../../icons/file-icon/FileIcon'; | ||
import FolderIcon from '../../../icons/folder-icon/FolderIcon'; | ||
|
||
import type { BoxItem } from '../../../common/types/core'; | ||
|
||
import { TYPE_FOLDER, TYPE_FILE, TYPE_WEBLINK } from '../../../constants'; | ||
import messages from '../messages'; | ||
|
||
import './IconCell.scss'; | ||
|
||
export interface IconCellProps { | ||
dimension?: number; | ||
rowData: BoxItem; | ||
} | ||
|
||
const IconCell = ({ rowData, dimension }: IconCellProps) => { | ||
const { formatMessage } = useIntl(); | ||
const { type, extension, has_collaborations, is_externally_owned, archive_type }: BoxItem = rowData; | ||
const isArchive = archive_type === 'archive'; | ||
const isArchiveFolder = archive_type === 'folder_archive'; | ||
switch (type) { | ||
case TYPE_FILE: | ||
return <FileIcon dimension={dimension} extension={extension} />; | ||
case TYPE_FOLDER: | ||
if (isArchive) { | ||
return <Archive aria-label={formatMessage(messages.archive)} height={dimension} width={dimension} />; | ||
} | ||
if (isArchiveFolder) { | ||
return ( | ||
<FolderArchive | ||
aria-label={formatMessage(messages.archivedFolder)} | ||
height={dimension} | ||
width={dimension} | ||
/> | ||
); | ||
} | ||
return <FolderIcon dimension={dimension} isCollab={has_collaborations} isExternal={is_externally_owned} />; | ||
case TYPE_WEBLINK: | ||
return <FileBookmark aria-label={formatMessage(messages.bookmark)} height={dimension} width={dimension} />; | ||
default: | ||
return <FileIcon dimension={dimension} />; | ||
} | ||
}; | ||
|
||
export default IconCell; |
This file was deleted.
Oops, something went wrong.
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,82 @@ | ||
import * as React from 'react'; | ||
import { render, screen } from '../../../../test-utils/testing-library'; | ||
|
||
import IconCell from '../IconCell'; | ||
import { TYPE_FILE, TYPE_FOLDER, TYPE_WEBLINK } from '../../../../constants'; | ||
|
||
const archiveItem = { | ||
type: TYPE_FOLDER, | ||
archive_type: 'archive', | ||
}; | ||
|
||
const externalFolderItem = { | ||
type: TYPE_FOLDER, | ||
has_collaborations: false, | ||
is_externally_owned: true, | ||
}; | ||
|
||
const fileItem = { | ||
type: TYPE_FILE, | ||
extension: 'pdf', | ||
}; | ||
|
||
const folderArchiveItem = { | ||
type: TYPE_FOLDER, | ||
archive_type: 'folder_archive', | ||
}; | ||
|
||
const folderItem = { | ||
type: TYPE_FOLDER, | ||
has_collaborations: true, | ||
is_externally_owned: false, | ||
}; | ||
|
||
const personalFolderItem = { | ||
type: TYPE_FOLDER, | ||
has_collaborations: false, | ||
is_externally_owned: false, | ||
}; | ||
|
||
const webLinkItem = { | ||
type: TYPE_WEBLINK, | ||
}; | ||
|
||
describe('elements/common/item/IconCell', () => { | ||
const renderComponent = props => { | ||
return render(<IconCell {...props} />); | ||
}; | ||
test('renders file icon with correct title', () => { | ||
renderComponent({ rowData: fileItem, dimension: 32 }); | ||
expect(screen.getByLabelText('PDF File')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders collaborated folder icon with correct title', () => { | ||
renderComponent({ rowData: folderItem, dimension: 32 }); | ||
expect(screen.getByLabelText('Collaborated Folder')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders external folder icon with correct title', () => { | ||
renderComponent({ rowData: externalFolderItem, dimension: 32 }); | ||
expect(screen.getByLabelText('External Folder')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders personal folder icon with correct title', () => { | ||
renderComponent({ rowData: personalFolderItem, dimension: 32 }); | ||
expect(screen.getByLabelText('Personal Folder')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders archive icon with correct aria-label', () => { | ||
renderComponent({ rowData: archiveItem, dimension: 32 }); | ||
expect(screen.getByLabelText('Archive')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders folder archive icon with correct aria-label', () => { | ||
renderComponent({ rowData: folderArchiveItem, dimension: 32 }); | ||
expect(screen.getByLabelText('Archived Folder')).toBeInTheDocument(); | ||
}); | ||
|
||
test('renders bookmark icon with correct title', () => { | ||
renderComponent({ rowData: webLinkItem, dimension: 32 }); | ||
expect(screen.getByLabelText('Bookmark')).toBeInTheDocument(); | ||
}); | ||
}); |
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
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
Oops, something went wrong.