-
Notifications
You must be signed in to change notification settings - Fork 331
refactor(content-preview): convert preview-header to TypeScript #3965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
devin-ai-integration
wants to merge
12
commits into
master
Choose a base branch
from
devin-ai/convert-ts-preview-header-1740441461
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
697accc
refactor(content-preview): convert preview-header to TypeScript
devin-ai-integration[bot] b4ca0de
fix: resolve TypeScript dynamic import errors in preview-header
devin-ai-integration[bot] 77810a6
refactor(content-preview): remove original JS files
devin-ai-integration[bot] a761699
refactor(content-preview): add index.js.flow file
devin-ai-integration[bot] d3eb830
refactor(content-preview): address PR comments
devin-ai-integration[bot] 89a6e49
refactor(content-preview): address additional PR comments
devin-ai-integration[bot] f7ac93c
refactor(content-preview): fix TS imports and button types
devin-ai-integration[bot] bbff88c
refactor(content-preview): fix TypeScript errors
devin-ai-integration[bot] 0a513da
refactor(content-preview): restore empty lines and fix injectIntl usage
devin-ai-integration[bot] 2c97254
refactor(content-preview): add empty lines
devin-ai-integration[bot] 753ac29
refactor(content-preview): use useIntl instead of injectIntl
devin-ai-integration[bot] d4aafc9
refactor(content-preview): address PR comments for type definitions
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or 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,27 @@ | ||
import React from 'react'; | ||
import FileIcon from '../../../icons/file-icon/FileIcon'; | ||
import type { BoxItem, BoxItemVersion } from '../../../common/types/core'; | ||
import './FileInfo.scss'; | ||
|
||
export interface FileInfoProps { | ||
file: BoxItem | null; | ||
version: BoxItemVersion | null; | ||
} | ||
|
||
const FileInfo = ({ file, version }: FileInfoProps) => { | ||
// Opt to show version over the file object since it is more specific | ||
const displayItem = version || file; | ||
|
||
return ( | ||
<div className="bcpr-FileInfo"> | ||
{displayItem && ( | ||
<> | ||
<FileIcon dimension={24} extension={displayItem.extension} /> | ||
<span className="bcpr-FileInfo-name">{displayItem.name}</span> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default FileInfo; |
File renamed without changes.
167 changes: 167 additions & 0 deletions
167
src/elements/content-preview/preview-header/PreviewHeader.tsx
This file contains hidden or 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,167 @@ | ||
import React from 'react'; | ||
import { injectIntl } from 'react-intl'; | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import type { IntlShape } from 'react-intl'; | ||
import classNames from 'classnames'; | ||
import get from 'lodash/get'; | ||
import AsyncLoad from '../../common/async-load'; | ||
import FileInfo from './FileInfo'; | ||
import IconClose from '../../../icons/general/IconClose'; | ||
import IconDownload from '../../../icons/general/IconDownloadSolid'; | ||
import IconDrawAnnotationMode from '../../../icons/annotations/IconDrawAnnotation'; | ||
import IconPointAnnotation from '../../../icons/annotations/IconPointAnnotation'; | ||
import IconPrint from '../../../icons/general/IconPrint'; | ||
import Logo from '../../common/header/Logo'; | ||
import messages from '../../common/messages'; | ||
import PlainButton from '../../../components/plain-button/PlainButton'; | ||
import { bdlGray50 } from '../../../styles/variables'; | ||
import type { BoxItem, BoxItemVersion } from '../../../common/types/core'; | ||
import type { ContentAnswersProps } from '../../common/content-answers/ContentAnswers'; | ||
import type { ContentOpenWithProps } from '../../content-open-with/ContentOpenWith'; | ||
|
||
import './PreviewHeader.scss'; | ||
|
||
export interface PreviewHeaderProps { | ||
canAnnotate: boolean; | ||
canDownload: boolean; | ||
canPrint?: boolean; | ||
contentAnswersProps?: Partial<ContentAnswersProps>; | ||
contentOpenWithProps?: Partial<ContentOpenWithProps>; | ||
file?: BoxItem; | ||
intl: IntlShape; | ||
logoUrl?: string; | ||
onClose?: React.MouseEventHandler<HTMLButtonElement>; | ||
onDownload: React.MouseEventHandler<HTMLButtonElement>; | ||
onPrint: React.MouseEventHandler<HTMLButtonElement>; | ||
selectedVersion: BoxItemVersion | null; | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
token: string | null; | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
const LoadableContentAnswers = AsyncLoad({ | ||
loader: () => import(/* webpackMode: "lazy", webpackChunkName: "content-answers" */ '../../common/content-answers'), | ||
}); | ||
const LoadableContentOpenWith = AsyncLoad({ | ||
loader: () => import(/* webpackMode: "lazy", webpackChunkName: "content-open-with" */ '../../content-open-with'), | ||
}); | ||
|
||
const PreviewHeader = ({ | ||
canAnnotate, | ||
canDownload, | ||
canPrint, | ||
contentAnswersProps = {} as Partial<ContentAnswersProps>, | ||
contentOpenWithProps = {} as Partial<ContentOpenWithProps>, | ||
file, | ||
intl, | ||
logoUrl, | ||
onClose, | ||
onDownload, | ||
onPrint, | ||
selectedVersion, | ||
token, | ||
}: PreviewHeaderProps) => { | ||
const fileId = file && file.id; | ||
const shouldRenderAnswers = fileId && contentAnswersProps.show; | ||
const shouldRenderOpenWith = fileId && contentOpenWithProps.show; | ||
const currentVersionId = get(file, 'file_version.id'); | ||
const selectedVersionId = get(selectedVersion, 'id', currentVersionId); | ||
const isPreviewingCurrentVersion = currentVersionId === selectedVersionId; | ||
|
||
// When previewing an older version the close button returns the user to the current version | ||
const closeMsg = isPreviewingCurrentVersion | ||
? intl.formatMessage(messages.close) | ||
: intl.formatMessage(messages.back); | ||
const printMsg = intl.formatMessage(messages.print); | ||
const downloadMsg = intl.formatMessage(messages.download); | ||
const drawMsg = intl.formatMessage(messages.drawAnnotation); | ||
const pointMsg = intl.formatMessage(messages.pointAnnotation); | ||
|
||
return ( | ||
<header | ||
className={classNames('bcpr-PreviewHeader', { | ||
'bcpr-PreviewHeader--basic': !isPreviewingCurrentVersion, | ||
})} | ||
> | ||
{/* | ||
bp-header and bp-base-header are used by box-annotations, | ||
and must be put one level under bcpr-PreviewHeader | ||
*/} | ||
<div className="bcpr-PreviewHeader-content bp-header bp-base-header"> | ||
{logoUrl ? <Logo url={logoUrl} /> : <FileInfo file={file || null} version={selectedVersion} />} | ||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<div className="bcpr-PreviewHeader-controls"> | ||
{isPreviewingCurrentVersion && ( | ||
<> | ||
{shouldRenderOpenWith && ( | ||
<LoadableContentOpenWith | ||
className="bcpr-bcow-btn" | ||
fileId={fileId} | ||
token={token} | ||
{...contentOpenWithProps} | ||
/> | ||
)} | ||
{shouldRenderAnswers && ( | ||
<LoadableContentAnswers | ||
className="bcpr-PreviewHeader-contentAnswers" | ||
file={file} | ||
{...contentAnswersProps} | ||
/> | ||
)} | ||
{canAnnotate && ( | ||
<> | ||
<PlainButton | ||
aria-label={drawMsg} | ||
className="bcpr-PreviewHeader-button bp-btn-annotate-draw bp-is-hidden" | ||
title={drawMsg} | ||
> | ||
<IconDrawAnnotationMode color={bdlGray50} height={18} width={18} /> | ||
</PlainButton> | ||
<PlainButton | ||
aria-label={pointMsg} | ||
className="bcpr-PreviewHeader-button bp-btn-annotate-point bp-is-hidden" | ||
title={pointMsg} | ||
> | ||
<IconPointAnnotation color={bdlGray50} height={18} width={18} /> | ||
</PlainButton> | ||
</> | ||
)} | ||
{canPrint && ( | ||
<PlainButton | ||
aria-label={printMsg} | ||
className="bcpr-PreviewHeader-button" | ||
onClick={onPrint} | ||
title={printMsg} | ||
> | ||
<IconPrint color={bdlGray50} height={22} width={22} /> | ||
</PlainButton> | ||
)} | ||
{canDownload && ( | ||
<PlainButton | ||
aria-label={downloadMsg} | ||
className="bcpr-PreviewHeader-button" | ||
onClick={onDownload} | ||
title={downloadMsg} | ||
> | ||
<IconDownload color={bdlGray50} height={18} width={18} /> | ||
</PlainButton> | ||
)} | ||
</> | ||
)} | ||
|
||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{onClose && ( | ||
<PlainButton | ||
aria-label={isPreviewingCurrentVersion && closeMsg} | ||
className="bcpr-PreviewHeader-button bcpr-PreviewHeader-button-close" | ||
onClick={onClose} | ||
> | ||
{isPreviewingCurrentVersion ? ( | ||
<IconClose color={bdlGray50} height={24} width={24} /> | ||
) : ( | ||
closeMsg | ||
)} | ||
</PlainButton> | ||
)} | ||
</div> | ||
</div> | ||
</header> | ||
); | ||
}; | ||
|
||
export default injectIntl(PreviewHeader); |
1 change: 1 addition & 0 deletions
1
...s/content-preview/preview-header/index.js → ...tent-preview/preview-header/index.js.flow
This file contains hidden or 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,2 +1,3 @@ | ||
// @flow | ||
|
||
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export { default } from './PreviewHeader'; |
tjuanitas marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 @@ | ||
export { default } from './PreviewHeader'; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.