Skip to content

Commit

Permalink
fix: correct data format
Browse files Browse the repository at this point in the history
  • Loading branch information
vsgoulart committed Dec 12, 2024
1 parent 628b56d commit 9b97770
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ function DocumentsDataSource(props) {
{
"documentId": "u123",
"metadata": {
"filename": "Document.pdf",
"mimeType": "application/pdf"
"fileName": "Document.pdf",
"contentType": "application/pdf"
}
}
]`;
Expand Down
12 changes: 6 additions & 6 deletions packages/form-js-playground/test/spec/Playground.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ describe('playground', function () {
{
documentId: 'document0',
metadata: {
filename: 'My document.pdf',
mimeType: 'application/pdf',
fileName: 'My document.pdf',
contentType: 'application/pdf',
},
},
{
documentId: 'document1',
metadata: {
filename: 'My document.png',
mimeType: 'image/png',
fileName: 'My document.png',
contentType: 'image/png',
},
},
{
documentId: 'document2',
metadata: {
filename: 'My document.zip',
mimeType: 'application/zip',
fileName: 'My document.zip',
contentType: 'application/zip',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const type = 'documentPreview';
* @typedef DocumentMetadata
* @property {string} documentId
* @property {Object} metadata
* @property {string} metadata.mimeType
* @property {string} metadata.filename
* @property {string} metadata.contentType
* @property {string} metadata.fileName
*
* @typedef Field
* @property {string} id
Expand Down Expand Up @@ -133,8 +133,8 @@ function isValidDocument(document) {
'documentId' in document &&
'metadata' in document &&
typeof document.metadata === 'object' &&
'mimeType' in document.metadata &&
'filename' in document.metadata
'contentType' in document.metadata &&
'fileName' in document.metadata
);
}

Expand Down Expand Up @@ -173,16 +173,16 @@ function DocumentRenderer(props) {
const errorMessageId = `${domId}-error-message`;
const errorMessage = 'Unable to download document';

if (metadata.mimeType.toLowerCase().startsWith('image/') && isInViewport) {
if (metadata.contentType.toLowerCase().startsWith('image/') && isInViewport) {
return (
<div
class={singleDocumentContainerClassName}
style={{ maxHeight }}
aria-describedby={hasError ? errorMessageId : undefined}>
<img src={fullUrl} alt={metadata.filename} class={`fjs-${type}-image`} />
<img src={fullUrl} alt={metadata.fileName} class={`fjs-${type}-image`} />
<DownloadButton
endpoint={fullUrl}
filename={metadata.filename}
fileName={metadata.fileName}
onDownloadError={() => {
setHasError(true);
}}
Expand All @@ -192,7 +192,7 @@ function DocumentRenderer(props) {
);
}

if (metadata.mimeType.toLowerCase() === 'application/pdf' && isInViewport) {
if (metadata.contentType.toLowerCase() === 'application/pdf' && isInViewport) {
return (
<div
class={singleDocumentContainerClassName}
Expand All @@ -201,7 +201,7 @@ function DocumentRenderer(props) {
<iframe src={fullUrl} class={`fjs-${type}-iframe`} />
<DownloadButton
endpoint={fullUrl}
filename={metadata.filename}
fileName={metadata.fileName}
onDownloadError={() => {
setHasError(true);
}}
Expand All @@ -217,12 +217,12 @@ function DocumentRenderer(props) {
ref={ref}
aria-describedby={hasError ? errorMessageId : undefined}>
<div>
<div class="fjs-document-preview-title">{metadata.filename}</div>
<div class="fjs-document-preview-title">{metadata.fileName}</div>
{hasError ? <Errors id={errorMessageId} errors={[errorMessage]} /> : null}
</div>
<DownloadButton
endpoint={endpoint}
filename={metadata.filename}
endpoint={fullUrl}
fileName={metadata.fileName}
onDownloadError={() => {
setHasError(true);
}}
Expand All @@ -234,13 +234,13 @@ function DocumentRenderer(props) {
/**
* @param {Object} props
* @param {string} props.endpoint
* @param {string} props.filename
* @param {string} props.fileName
* @param {Function} props.onDownloadError
*
* @returns {import("preact").JSX.Element}
*/
function DownloadButton(props) {
const { endpoint, filename, onDownloadError } = props;
const { endpoint, fileName, onDownloadError } = props;

const handleDownload = async () => {
try {
Expand All @@ -255,7 +255,7 @@ function DownloadButton(props) {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.download = fileName;
link.click();
window.URL.revokeObjectURL(url);
} catch {
Expand All @@ -268,7 +268,7 @@ function DownloadButton(props) {
type="button"
onClick={handleDownload}
class={classNames(`fjs-${type}-download-button`)}
aria-label={`Download ${filename}`}>
aria-label={`Download ${fileName}`}>
<DownloadIcon />
</button>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,22 @@ const initialData = {
{
documentId: 'document0',
metadata: {
filename: 'My document.pdf',
mimeType: 'application/pdf',
fileName: 'My document.pdf',
contentType: 'application/pdf',
},
},
{
documentId: 'document1',
metadata: {
filename: 'My document.png',
mimeType: 'image/png',
fileName: 'My document.png',
contentType: 'image/png',
},
},
{
documentId: 'document2',
metadata: {
filename: 'My document.zip',
mimeType: 'application/zip',
fileName: 'My document.zip',
contentType: 'application/zip',
},
},
],
Expand Down

0 comments on commit 9b97770

Please sign in to comment.