Skip to content
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

feat: Inject content hash into document preview URL #1342

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/form-js-playground/test/spec/Playground.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ describe('playground', function () {
metadata: {
fileName: 'My document.pdf',
contentType: 'application/pdf',
customProperties: {
contentHash: '1234567890',
},
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @property {Object} metadata
* @property {string|undefined} [metadata.contentType]
* @property {string} metadata.fileName
* @property {Object} [metadata.customProperties]
* @property {string|undefined} [metadata.customProperties.contentHash]
*
* @typedef Field
* @property {string} id
Expand Down Expand Up @@ -170,7 +172,11 @@
const [hasError, setHasError] = useState(false);
const ref = useRef(null);
const isInViewport = useInViewport(ref);
const fullUrl = endpoint.replace(DOCUMENT_ID_PLACEHOLDER, documentMetadata.documentId);
const fullUrl = buildUrl({
baseUrl: endpoint,
documentId: documentMetadata.documentId,
customProperties: metadata.customProperties,
});
const singleDocumentContainerClassName = `fjs-${type}-single-document-container`;
const errorMessageId = `${domId}-error-message`;
const errorMessage = 'Unable to download document';
Expand Down Expand Up @@ -296,10 +302,32 @@

return () => {
if (ref.current) {
observer.unobserve(ref.current);

Check warning on line 305 in packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest, 20)

The ref value 'ref.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'ref.current' to a variable inside the effect, and use that variable in the cleanup function

Check warning on line 305 in packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 20)

The ref value 'ref.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'ref.current' to a variable inside the effect, and use that variable in the cleanup function

Check warning on line 305 in packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 20)

The ref value 'ref.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'ref.current' to a variable inside the effect, and use that variable in the cleanup function

Check warning on line 305 in packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

View workflow job for this annotation

GitHub Actions / Build (macos-latest, 20)

The ref value 'ref.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'ref.current' to a variable inside the effect, and use that variable in the cleanup function

Check warning on line 305 in packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

View workflow job for this annotation

GitHub Actions / Build (ubuntu-20.04, 20)

The ref value 'ref.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'ref.current' to a variable inside the effect, and use that variable in the cleanup function

Check warning on line 305 in packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js

View workflow job for this annotation

GitHub Actions / Build (windows-latest, 20)

The ref value 'ref.current' will likely have changed by the time this effect cleanup function runs. If this ref points to a node rendered by React, copy 'ref.current' to a variable inside the effect, and use that variable in the cleanup function
}
};
}, [ref]);

return isInViewport;
}

/**
* This solution should be a temporary fix, we should try to remove it via: https://github.com/bpmn-io/form-js/issues/1341
*
* @param {Object} options
* @param {string} options.baseUrl
* @param {string} options.documentId
* @param {Object} [options.customProperties]
* @param {string|undefined} [options.customProperties.contentHash]
*
* @returns {string}
*/
function buildUrl(options) {
const { baseUrl, documentId, customProperties } = options;
const finalUrl = new URL(baseUrl.replace(DOCUMENT_ID_PLACEHOLDER, documentId));

if (customProperties !== undefined && customProperties.contentHash !== undefined) {
finalUrl.searchParams.set('contentHash', customProperties.contentHash);
}

return decodeURI(finalUrl.toString());
}
Loading