diff --git a/packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js b/packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js index 24234f3a5..4f345a2dd 100644 --- a/packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js +++ b/packages/form-js-viewer/src/render/components/form-fields/DocumentPreview.js @@ -75,7 +75,7 @@ DocumentPreview.config = { name: 'Document preview', create: (options = {}) => ({ label: 'Document preview', - endpointKey: '=defaultDocumentsEndpointKey', + endpointKey: DEFAULT_ENDPOINT_KEY, ...options, }), }; @@ -83,6 +83,7 @@ DocumentPreview.config = { // helpers ///////////////////////////// const DOCUMENT_ID_PLACEHOLDER = '{documentId}'; +const DEFAULT_ENDPOINT_KEY = '=defaultDocumentsEndpointKey'; /** * @typedef GetErrorOptions @@ -98,16 +99,18 @@ function getErrors(options) { let errors = []; if (!isString(dataSource) || dataSource.length < 1) { - errors.push('Data source is not defined.'); + errors.push('Document reference is not defined.'); } if (!isString(endpointKey) || endpointKey.length < 1) { errors.push('Endpoint key is not defined.'); } - if (!URL.canParse(endpoint)) { - errors.push('Endpoint is not valid.'); - } else if (!isValidDocumentEndpoint(endpoint)) { + if (endpointKey !== DEFAULT_ENDPOINT_KEY && !URL.canParse(endpoint)) { + errors.push( + `If you change the endpoint key from "${DEFAULT_ENDPOINT_KEY}", the document preview won't work with Camunda Tasklist and you must provide a valid URL.`, + ); + } else if (endpointKey !== DEFAULT_ENDPOINT_KEY && !isValidDocumentEndpoint(endpoint)) { errors.push('Endpoint must contain "{documentId}".'); } diff --git a/packages/form-js-viewer/test/spec/render/components/form-fields/DocumentPreview.spec.js b/packages/form-js-viewer/test/spec/render/components/form-fields/DocumentPreview.spec.js index 4a826b132..ef9314627 100644 --- a/packages/form-js-viewer/test/spec/render/components/form-fields/DocumentPreview.spec.js +++ b/packages/form-js-viewer/test/spec/render/components/form-fields/DocumentPreview.spec.js @@ -42,29 +42,11 @@ describe('DocumentPreview', function () { // when const { container } = createDocumentPreview({ initialData: { - defaultDocumentsEndpointKey: false, + foobar: false, }, - services: { - expressionLanguage: mockExpressionLanguageService, - }, - }); - - // then - const formField = container.querySelector('.fjs-form-field'); - - expect(formField).to.exist; - expect(formField.classList.contains('fjs-form-field-documentPreview')).to.be.true; - - expect(screen.queryByText('Endpoint is not valid.')).to.exist; - }); - - it('should handle bad endpoint format', function () { - // when - const { container } = createDocumentPreview({ - initialData, field: { ...defaultField, - dataSource: undefined, + endpointKey: '=foobar', }, services: { expressionLanguage: mockExpressionLanguageService, @@ -77,16 +59,20 @@ describe('DocumentPreview', function () { expect(formField).to.exist; expect(formField.classList.contains('fjs-form-field-documentPreview')).to.be.true; - expect(screen.queryByText('Data source is not defined.')).to.exist; + expect( + screen.queryByText( + 'If you change the endpoint key from "=defaultDocumentsEndpointKey", the document preview won\'t work with Camunda Tasklist and you must provide a valid URL.', + ), + ).to.exist; }); - it('should handle missing endpoint', function () { + it('should handle bad endpoint format', function () { // when const { container } = createDocumentPreview({ initialData, field: { ...defaultField, - endpointKey: undefined, + dataSource: undefined, }, services: { expressionLanguage: mockExpressionLanguageService, @@ -99,8 +85,7 @@ describe('DocumentPreview', function () { expect(formField).to.exist; expect(formField.classList.contains('fjs-form-field-documentPreview')).to.be.true; - expect(screen.queryByText('Endpoint key is not defined.')).to.exist; - expect(screen.queryByText('Endpoint is not valid.')).to.exist; + expect(screen.queryByText('Document reference is not defined.')).to.exist; }); it('should handle missing data source', function () {