Skip to content
This repository has been archived by the owner on Nov 7, 2022. It is now read-only.

Commit

Permalink
fix(editor): fix embed block editing url will lose url metadata (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darmody committed Jul 19, 2022
1 parent df8d693 commit 1c4555a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const renderImage = (
icon={<FileIcon fileType="image" />}
linkUrl={imageUrl}
node={node}
extension={extension}
deleteNode={deleteNode}
getPos={getPos}
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
Expand Down Expand Up @@ -90,6 +91,7 @@ const renderAttachment = (
deleteNode={deleteNode}
getPos={getPos}
node={node}
extension={extension}
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
/>
)
Expand All @@ -104,6 +106,7 @@ const renderAttachment = (
icon={<FileIcon fileType={fileType} />}
linkUrl={fileUrl}
node={node}
extension={extension}
deleteNode={deleteNode}
getPos={getPos}
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
Expand Down Expand Up @@ -187,6 +190,7 @@ export const EmbedView: FC<EmbedViewProps> = props => {
blockType="link"
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
node={node}
extension={extension}
deleteNode={deleteNode}
cover={cover}
description={description}
Expand All @@ -203,6 +207,7 @@ export const EmbedView: FC<EmbedViewProps> = props => {
blockType="link"
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
node={node}
extension={extension}
fileUrl={linkUrl}
fileType="html"
fileName={title ?? ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('WebsiteDocument', () => {
blockType="link"
icon="icon"
title="title"
extension={{} as any}
displayName="displayName"
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
url="url"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,26 @@ export function useLinkValue(
return
}

const normalizedUrl = prependUrlScheme(url)

if (!extension?.options.getUrlData) {
updateEmbedBlockAttributes(
{
type: 'ATTACHMENT',
key: url,
key: normalizedUrl,
source: 'EXTERNAL',
contentType: 'unknown',
name: url
name: normalizedUrl
},

'attachment'
)
onSubmit?.(url)
onSubmit?.(normalizedUrl)
return
}

progressing()
const { success, data } = await extension.options.getUrlData(prependUrlScheme(url))
const { success, data } = await extension.options.getUrlData(normalizedUrl)

if (!success) {
resetProgress()
Expand Down Expand Up @@ -72,13 +74,13 @@ export function useLinkValue(
key: data.url,
source: 'EXTERNAL',
contentType: data.type,
name: url
name: data.url
},
'attachment'
)
}

onSubmit?.(url)
onSubmit?.(data.url)
}, [extension?.options, onSubmit, progressing, resetProgress, t, updateEmbedBlockAttributes, url])

const handleLinkChange = useCallback<ChangeEventHandler<HTMLInputElement>>(event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface CardViewProps {
deleteNode: EmbedViewProps['deleteNode']
getPos: EmbedViewProps['getPos']
node: EmbedViewProps['node']
extension: EmbedViewProps['extension']
cover?: string | null
icon?: string | ReactElement
displayName: string
Expand Down Expand Up @@ -61,6 +62,7 @@ export const CardView: FC<CardViewProps> = ({
description,
blockType,
node,
extension,
getPos,
deleteNode,
updateEmbedBlockAttributes
Expand All @@ -82,12 +84,14 @@ export const CardView: FC<CardViewProps> = ({
deleteNode={deleteNode}
getPos={getPos}
editable="custom"
actionOptions={actionOptions}>
actionOptions={actionOptions}
>
<CardContainer
contentType={type}
data-testid={TEST_ID_ENUM.editor.embedBlock.link.id}
size="md"
onClick={onClick}>
onClick={onClick}
>
<CardCover blockType={blockType} cover={cover} icon={icon} />
<Content type={type}>
{displayName && <Title type={type}>{displayName}</Title>}
Expand All @@ -102,6 +106,7 @@ export const CardView: FC<CardViewProps> = ({
<EmbedToolbarContainer onClick={handleStopPropagation}>
<EmbedToolbar
mode="card"
extension={extension}
blockType={blockType}
displayName={displayName}
url={linkUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const DocumentFooter: FC<DocumentFooterProps> = ({
name,
icon,
blockType,
extension,
updateEmbedBlockAttributes,
onFullScreen
}) => {
Expand All @@ -71,6 +72,7 @@ export const DocumentFooter: FC<DocumentFooterProps> = ({
<EmbedToolbarContainer>
<EmbedToolbar
url={url}
extension={extension}
displayName={displayName}
mode="preview"
blockType={blockType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { usePdftronDocument } from './usePdftronDocument'
import { DocumentFooter } from '../DocumentFooter'
import { EmbedBlockType, UpdateEmbedBlockAttributes } from '../../../EmbedView'
import { DocumentUnavailable } from '../DocumentUnavailable'
import { PreviewViewProps } from '../PreviewView'

export interface PdftronDocumentProps {
blockType: EmbedBlockType
extension: PreviewViewProps['extension']
updateEmbedBlockAttributes: UpdateEmbedBlockAttributes
displayName: string
fileName: string
Expand Down Expand Up @@ -56,6 +58,7 @@ const DocumentFileIcon = styled(FileIcon, {

export const PdftronDocument: FC<PdftronDocumentProps> = ({
blockType,
extension,
updateEmbedBlockAttributes,
fileName,
fileType,
Expand All @@ -79,6 +82,7 @@ export const PdftronDocument: FC<PdftronDocumentProps> = ({
icon={<DocumentFileIcon fileType={fileType} />}
name={fileName}
blockType={blockType}
extension={extension}
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
onFullScreen={toggleFullScreen}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface PreviewViewProps {
deleteNode: EmbedViewProps['deleteNode']
getPos: EmbedViewProps['getPos']
node: EmbedViewProps['node']
extension: EmbedViewProps['extension']
updateEmbedBlockAttributes: UpdateEmbedBlockAttributes
displayName: string
fileName: string
Expand Down Expand Up @@ -44,7 +45,8 @@ export const PreviewView: FC<PreviewViewProps> = ({
fileType,
fileUrl,
icon,
node
node,
extension
}) => {
const isWebsite = fileType === 'html'
const [actionOptions] = useActionOptions(isWebsite ? undefined : fileUrl)
Expand All @@ -56,10 +58,12 @@ export const PreviewView: FC<PreviewViewProps> = ({
deleteNode={deleteNode}
editable="custom"
getPos={getPos}
actionOptions={actionOptions}>
actionOptions={actionOptions}
>
<DocumentContainer>
{isWebsite ? (
<WebsiteDocument
extension={extension}
blockType={blockType}
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
url={fileUrl}
Expand All @@ -69,6 +73,7 @@ export const PreviewView: FC<PreviewViewProps> = ({
/>
) : (
<PdftronDocument
extension={extension}
blockType={blockType}
updateEmbedBlockAttributes={updateEmbedBlockAttributes}
displayName={displayName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { FC } from 'react'
import { EmbedBlockType, UpdateEmbedBlockAttributes } from '../../EmbedView'
import { DocumentFooter } from './DocumentFooter'
import { DocumentUnavailable } from './DocumentUnavailable'
import { PreviewViewProps } from './PreviewView'
import { useWebsiteDocumentStatus } from './useWebsiteDocumentStatus'

export interface WebsiteDocumentProps {
blockType: EmbedBlockType
extension: PreviewViewProps['extension']
updateEmbedBlockAttributes: UpdateEmbedBlockAttributes
url: string
title?: string
Expand All @@ -29,6 +31,7 @@ const WebsiteFrame = styled('iframe', {
})

export const WebsiteDocument: FC<WebsiteDocumentProps> = ({
extension,
blockType,
updateEmbedBlockAttributes,
icon,
Expand All @@ -44,6 +47,7 @@ export const WebsiteDocument: FC<WebsiteDocumentProps> = ({
<DocumentFooter
displayName={displayName}
url={url}
extension={extension}
name={url}
icon={icon}
blockType={blockType}
Expand Down

0 comments on commit 1c4555a

Please sign in to comment.