-
Notifications
You must be signed in to change notification settings - Fork 308
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 previewDialog
- Loading branch information
1 parent
1850977
commit aaa6b3a
Showing
8 changed files
with
380 additions
and
115 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
README.md | ||
flow-typed/* |
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 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,110 @@ | ||
/** | ||
* @flow | ||
* @file Content Explorer Preview Dialog | ||
* @author Box | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { Modal } from '@box/blueprint-web'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
|
||
import ContentPreview from '../content-preview'; | ||
import { TYPE_FILE } from '../../constants'; | ||
import type { ContentPreviewProps } from '../content-preview'; | ||
import type { Token, BoxItem, Collection } from '../../common/types/core'; | ||
import type APICache from '../../utils/Cache'; | ||
|
||
import messages from '../common/messages'; | ||
|
||
type PreviewDialogProps = { | ||
apiHost: string, | ||
appHost: string, | ||
cache: APICache, | ||
canDownload: boolean, | ||
contentPreviewProps: ContentPreviewProps, | ||
currentCollection: Collection, | ||
isOpen: boolean, | ||
isTouch: boolean, | ||
item: BoxItem, | ||
onCancel: any, | ||
onDownload: any, | ||
onPreview: any, | ||
parentElement: HTMLElement, | ||
previewLibraryVersion: string, | ||
responseInterceptor?: any, | ||
requestInterceptor?: any, | ||
sharedLink?: string, | ||
sharedLinkPassword?: string, | ||
staticHost: string, | ||
staticPath: string, | ||
token: Token, | ||
}; | ||
|
||
const PreviewDialog = ({ | ||
apiHost, | ||
appHost, | ||
cache, | ||
canDownload, | ||
contentPreviewProps, | ||
currentCollection, | ||
isOpen, | ||
item, | ||
onCancel, | ||
onDownload, | ||
onPreview, | ||
parentElement, | ||
previewLibraryVersion, | ||
requestInterceptor, | ||
responseInterceptor, | ||
sharedLink, | ||
sharedLinkPassword, | ||
staticHost, | ||
staticPath, | ||
token, | ||
}: PreviewDialogProps) => { | ||
const { formatMessage } = useIntl(); | ||
const { items }: Collection = currentCollection; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const onLoad = (data: any): void => { | ||
if (onPreview) { | ||
onPreview(cloneDeep(data)); | ||
} | ||
}; | ||
|
||
if (!item || !items) { | ||
return null; | ||
} | ||
|
||
const files: BoxItem[] = items.filter(({ type }) => type === TYPE_FILE); | ||
return ( | ||
<Modal onOpenChange={onCancel} open={isOpen}> | ||
<Modal.Content aria-label={formatMessage(messages.preview)} container={parentElement} size="xlarge"> | ||
<ContentPreview | ||
{...contentPreviewProps} | ||
autoFocus | ||
apiHost={apiHost} | ||
appHost={appHost} | ||
cache={cache} | ||
canDownload={canDownload} | ||
collection={files} | ||
fileId={item.id} | ||
hasHeader | ||
onClose={onCancel} | ||
onDownload={onDownload} | ||
onLoad={onLoad} | ||
previewLibraryVersion={previewLibraryVersion} | ||
staticHost={staticHost} | ||
staticPath={staticPath} | ||
sharedLink={sharedLink} | ||
sharedLinkPassword={sharedLinkPassword} | ||
requestInterceptor={requestInterceptor} | ||
responseInterceptor={responseInterceptor} | ||
token={token} | ||
/> | ||
</Modal.Content> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default PreviewDialog; |
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,16 @@ | ||
[class^='bp_modal_module_content'].bce-PreviewDialog { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
z-index: 1000; | ||
display: grid; | ||
max-width: 100%; | ||
max-height: 100%; | ||
margin: 0; | ||
inset: 0; | ||
border-radius: 0; | ||
|
||
.be.bcpr { | ||
height: 100vh; | ||
} | ||
} |
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,106 @@ | ||
import * as React from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import { Modal } from '@box/blueprint-web'; | ||
import cloneDeep from 'lodash/cloneDeep'; | ||
|
||
import ContentPreview, { ContentPreviewProps } from '../content-preview'; | ||
import { TYPE_FILE } from '../../constants'; | ||
import type { Token, BoxItem, Collection } from '../../common/types/core'; | ||
import type APICache from '../../utils/Cache'; | ||
|
||
import messages from '../common/messages'; | ||
|
||
import './PreviewDialog.scss'; | ||
|
||
export interface PreviewDialogProps { | ||
apiHost: string; | ||
appHost: string; | ||
cache: APICache; | ||
canDownload: boolean; | ||
contentPreviewProps: ContentPreviewProps; | ||
currentCollection: Collection; | ||
isOpen: boolean; | ||
isTouch: boolean; | ||
item: BoxItem; | ||
onCancel: () => void; | ||
onDownload: () => void; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
onPreview: (data: any) => void; | ||
parentElement: HTMLElement; | ||
previewLibraryVersion: string; | ||
requestInterceptor?: () => void; | ||
responseInterceptor?: () => void; | ||
sharedLink?: string; | ||
sharedLinkPassword?: string; | ||
staticHost: string; | ||
staticPath: string; | ||
token: Token; | ||
} | ||
|
||
const PreviewDialog = ({ | ||
apiHost, | ||
appHost, | ||
cache, | ||
canDownload, | ||
contentPreviewProps, | ||
currentCollection, | ||
isOpen, | ||
item, | ||
onCancel, | ||
onDownload, | ||
onPreview, | ||
parentElement, | ||
previewLibraryVersion, | ||
requestInterceptor, | ||
responseInterceptor, | ||
sharedLink, | ||
sharedLinkPassword, | ||
staticHost, | ||
staticPath, | ||
token, | ||
}: PreviewDialogProps) => { | ||
const { formatMessage } = useIntl(); | ||
const { items }: Collection = currentCollection; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const onLoad = (data: any): void => { | ||
if (onPreview) { | ||
onPreview(cloneDeep(data)); | ||
} | ||
}; | ||
|
||
if (!item || !items) { | ||
return null; | ||
} | ||
|
||
const files: BoxItem[] = items.filter(({ type }) => type === TYPE_FILE); | ||
return ( | ||
<Modal onOpenChange={onCancel} open={isOpen}> | ||
<Modal.Content aria-label={formatMessage(messages.preview)} container={parentElement} size="xlarge"> | ||
<ContentPreview | ||
{...contentPreviewProps} | ||
autoFocus | ||
apiHost={apiHost} | ||
appHost={appHost} | ||
cache={cache} | ||
canDownload={canDownload} | ||
collection={files} | ||
fileId={item.id} | ||
hasHeader | ||
onClose={onCancel} | ||
onDownload={onDownload} | ||
onLoad={onLoad} | ||
previewLibraryVersion={previewLibraryVersion} | ||
staticHost={staticHost} | ||
staticPath={staticPath} | ||
sharedLink={sharedLink} | ||
sharedLinkPassword={sharedLinkPassword} | ||
requestInterceptor={requestInterceptor} | ||
responseInterceptor={responseInterceptor} | ||
token={token} | ||
/> | ||
</Modal.Content> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default PreviewDialog; |
Oops, something went wrong.