-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(content-uploader): Migrated ItemAction
- Loading branch information
1 parent
219300f
commit 34feaea
Showing
8 changed files
with
297 additions
and
393 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
.bcu-item-action { | ||
width: 24px; | ||
height: 24px; | ||
|
||
.crawler { | ||
display: flex; | ||
align-items: center; | ||
|
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,129 @@ | ||
import * as React from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
import type { IntlShape } from 'react-intl'; | ||
import { Button, IconButton, LoadingIndicator } from '@box/blueprint-web'; | ||
import { ArrowCurveForward, Checkmark } from '@box/blueprint-web-assets/icons/Line'; | ||
import { EllipsisBadge, XMark } from '@box/blueprint-web-assets/icons/Fill'; | ||
|
||
import { AxiosError } from 'axios'; | ||
import { Size5, SurfaceStatusSurfaceSuccess } from '@box/blueprint-web-assets/tokens/tokens'; | ||
import Tooltip, { TooltipPosition } from '../../components/tooltip'; | ||
import { | ||
ERROR_CODE_UPLOAD_FILE_SIZE_LIMIT_EXCEEDED, | ||
STATUS_PENDING, | ||
STATUS_IN_PROGRESS, | ||
STATUS_STAGED, | ||
STATUS_COMPLETE, | ||
STATUS_ERROR, | ||
} from '../../constants'; | ||
|
||
import messages from '../common/messages'; | ||
|
||
import type { UploadStatus } from '../../common/types/upload'; | ||
|
||
import './ItemAction.scss'; | ||
|
||
export interface ItemActionProps { | ||
error?: AxiosError; | ||
intl: IntlShape; | ||
isFolder?: boolean; | ||
isResumableUploadsEnabled: boolean; | ||
onClick: React.MouseEventHandler<HTMLButtonElement>; | ||
onUpgradeCTAClick?: () => void; | ||
status: UploadStatus; | ||
} | ||
|
||
const getIconWithTooltip = ( | ||
icon: React.ReactNode, | ||
isDisabled: boolean, | ||
isLoading: boolean, | ||
onClick: React.MouseEventHandler<HTMLButtonElement>, | ||
tooltip: boolean, | ||
tooltipText: string, | ||
) => { | ||
if (isLoading) { | ||
return <LoadingIndicator aria-label="loading" />; | ||
} | ||
|
||
if (tooltip) { | ||
return ( | ||
<Tooltip position={TooltipPosition.TOP_LEFT} text={tooltipText}> | ||
<IconButton aria-label={tooltipText} disabled={isDisabled} onClick={onClick} icon={() => icon} /> | ||
</Tooltip> | ||
); | ||
} | ||
|
||
return <>{icon}</>; | ||
}; | ||
|
||
const ItemAction = ({ | ||
error, | ||
intl, | ||
isFolder = false, | ||
isResumableUploadsEnabled, | ||
onClick, | ||
onUpgradeCTAClick, | ||
status, | ||
}: ItemActionProps) => { | ||
let icon: React.ReactNode = <XMark color="black" height={Size5} width={Size5} />; | ||
let tooltip; | ||
let isLoading = false; | ||
const { code } = error || {}; | ||
const { formatMessage } = intl; | ||
|
||
if (isFolder && status !== STATUS_PENDING) { | ||
return null; | ||
} | ||
|
||
switch (status) { | ||
case STATUS_COMPLETE: | ||
icon = <Checkmark aria-label="complete" color={SurfaceStatusSurfaceSuccess} height={Size5} width={Size5} />; | ||
if (!isResumableUploadsEnabled) { | ||
tooltip = messages.remove; | ||
} | ||
break; | ||
case STATUS_ERROR: | ||
icon = <ArrowCurveForward aria-label="error" color="black" height={Size5} width={Size5} />; | ||
tooltip = isResumableUploadsEnabled ? messages.resume : messages.retry; | ||
break; | ||
case STATUS_IN_PROGRESS: | ||
case STATUS_STAGED: | ||
if (isResumableUploadsEnabled) { | ||
isLoading = true; | ||
} else { | ||
icon = <EllipsisBadge aria-label="staged" color="black" height={Size5} width={Size5} />; | ||
tooltip = messages.uploadsCancelButtonTooltip; | ||
} | ||
break; | ||
case STATUS_PENDING: | ||
default: | ||
if (isResumableUploadsEnabled) { | ||
isLoading = true; | ||
} else { | ||
tooltip = messages.uploadsCancelButtonTooltip; | ||
} | ||
break; | ||
} | ||
|
||
if (status === STATUS_ERROR && code === ERROR_CODE_UPLOAD_FILE_SIZE_LIMIT_EXCEEDED && !!onUpgradeCTAClick) { | ||
return ( | ||
<Button | ||
onClick={onUpgradeCTAClick} | ||
data-resin-target="large_version_error_inline_upgrade_cta" | ||
variant="primary" | ||
> | ||
{intl.formatMessage(messages.uploadsFileSizeLimitExceededUpgradeMessageForUpgradeCta)} | ||
</Button> | ||
); | ||
} | ||
const isDisabled = status === STATUS_STAGED; | ||
const tooltipText = tooltip && formatMessage(tooltip); | ||
|
||
return ( | ||
<div className="bcu-item-action"> | ||
{getIconWithTooltip(icon, isDisabled, isLoading, onClick, tooltip, tooltipText)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default injectIntl(ItemAction); |
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.