Browse Source

Implement ck-error for missing integration view.

panr 5 years ago
parent
commit
9f227912ad

+ 17 - 9
packages/ckeditor5-image/src/imageupload/utils.js

@@ -11,6 +11,7 @@
 
 import LabeledFieldView from '@ckeditor/ckeditor5-ui/src/labeledfield/labeledfieldview';
 import { createLabeledInputText } from '@ckeditor/ckeditor5-ui/src/labeledfield/utils';
+import { attachLinkToDocumentation } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
 
 /**
  * Creates a regular expression used to test for image files.
@@ -127,14 +128,21 @@ export function prepareIntegrations( editor ) {
 		} else if ( editor.ui.componentFactory.has( key ) ) {
 			object[ key ] = editor.ui.componentFactory.create( key );
 		} else {
-			// Console.warn should be enough because missing integration doesn't break the editor.
-			console.warn(
-				'It looks like integration "' + key + '" doesn\'t exist. ' +
-				'What may have happened: ' +
-				'\n- you passed the invalid integration name in the `image.upload.panel.items`,' +
-				'\n- integration component wasn\'t properly registered by the plugin,' +
-				'\n- the plugin that registers the component wasn\'t installed in the editor.'
-			);
+			/**
+			 * The specified name of the view cannot be created by the
+			 * {@link module:ui/componentfactory~ComponentFactory component factory}.
+			 *
+			 * Check whether:
+			 * * you passed the proper integration name as the
+			 *    `{@link module:image/imageupload~ImageUploadPanelConfig#items image.upload.panel.items}`,
+			 * * the plugin that registers the component was loaded to the editor,
+			 * * integration component was properly registered by the plugin.
+			 *
+			 * @error image-upload-integrations-invalid-view
+			 */
+			console.warn( attachLinkToDocumentation(
+				'image-upload-integrations-invalid-view: Trying to use a view that does not exist.'
+			), { key } );
 		}
 
 		return object;
@@ -156,7 +164,7 @@ export function createLabeledInputView( locale ) {
 		label: t( 'Insert image via URL' )
 	} );
 	labeledInputView.fieldView.placeholder = 'https://example.com/src/image.png';
-	labeledInputView.infoText = t( 'Paste the image source URL' );
+	labeledInputView.infoText = t( 'Paste the image source URL.' );
 
 	return labeledInputView;
 }

+ 3 - 2
packages/ckeditor5-image/tests/imageupload/utils.js

@@ -79,7 +79,8 @@ describe( 'Upload utils', () => {
 			editorElement.remove();
 		} );
 
-		it( 'should return only "insertImageViaUrl" integration and throw warning about missing integration', async () => {
+		it( 'should return only "insertImageViaUrl" integration and throw warning' +
+			'for "image-upload-integrations-invalid-view" error', async () => {
 			const editorElement = document.createElement( 'div' );
 			document.body.appendChild( editorElement );
 
@@ -108,7 +109,7 @@ describe( 'Upload utils', () => {
 			expect( Object.values( prepareIntegrations( editor ) ).length ).to.equal( 1 );
 
 			sinon.assert.calledOnce( consoleWarn );
-			expect( /Integration "openCKFinder" doesn't exist/gmi.test( consoleWarn.args[ 0 ][ 0 ] ) ).to.be.true;
+			expect( /image-upload-integrations-invalid-view/gmi.test( consoleWarn.args[ 0 ][ 0 ] ) ).to.be.true;
 
 			editor.destroy();
 			editorElement.remove();