Allow disambiguation previews to render when no summary found

This allows preview types to override the default behaviour
which prohibits previews from rendering when the API finds no
extract. In the case of disambiguation pages the summary is not
required to render a preview.

Bug: T346686
Change-Id: Ifb8bbef943b02dfa971e2af96511ac708733bdd1
This commit is contained in:
Jon Robson 2023-11-09 11:42:31 -08:00
parent bf3600f20a
commit 31e416ba68
7 changed files with 30 additions and 8 deletions

Binary file not shown.

Binary file not shown.

View file

@ -252,7 +252,8 @@ function handleDOMEventIfEligible( handler ) {
subTypes: [
{
type: previewTypes.TYPE_DISAMBIGUATION,
renderFn: createDisambiguationPreview
renderFn: createDisambiguationPreview,
doNotRequireSummary: true
}
]
} );

View file

@ -59,7 +59,8 @@ export default function createMwPopups( store, registerModel, registerPreviewUI,
* @param {PopupModule} module
*/
register: function ( module ) {
const { type, selector, gateway, renderFn, subTypes, delay, init } = module;
const { type, selector, gateway, renderFn, subTypes, delay, init,
doNotRequireSummary } = module;
if ( !type || !selector || !gateway ) {
throw new Error(
`Registration of Popups custom preview type "${type}" failed: You must specify a type, a selector, and a gateway.`
@ -67,10 +68,10 @@ export default function createMwPopups( store, registerModel, registerPreviewUI,
}
registerModel( type, selector, delay );
registerGatewayForPreviewType( type, gateway );
registerPreviewUI( type, renderFn );
registerPreviewUI( type, renderFn, doNotRequireSummary );
if ( subTypes ) {
subTypes.forEach( function ( subTypePreview ) {
registerPreviewUI( subTypePreview.type, subTypePreview.renderFn );
registerPreviewUI( subTypePreview.type, subTypePreview.renderFn, subTypePreview.doNotRequireSummary );
} );
}
// Run initialization function if provided.

View file

@ -2,6 +2,8 @@
* @module preview/model
*/
import { requiresSummary } from '../ui/renderer';
/**
* Page Preview types as defined in Schema:Popups
* https://meta.wikimedia.org/wiki/Schema:Popups
@ -180,7 +182,9 @@ function processExtract( extract ) {
*/
function getPagePreviewType( type, processedExtract ) {
if ( processedExtract === undefined ) {
// If the preview type requires a summary to display and no extract was
// found show the generic (error) preview.
if ( processedExtract === undefined && requiresSummary( type ) ) {
return previewTypes.TYPE_GENERIC;
}

View file

@ -142,14 +142,30 @@ export function render( model ) {
}
let renderers = {};
const renderersMeta = {};
/**
* @param {string} type
* @param {function( ext.popups.PreviewModel ): ext.popups.Preview} [previewFn]
* @param {boolean} [doNotRequireSummary] does this type require a summary to be renderable?
*
*/
export function registerPreviewUI( type, previewFn ) {
export function registerPreviewUI( type, previewFn, doNotRequireSummary ) {
renderers[ type ] = previewFn || createPagePreview;
renderersMeta[ type ] = {
requireSummary: !doNotRequireSummary
};
}
/**
* Check whether this render type requires a summary to be rendered.
*
* @param {string} type of preview
* @return {boolean}
*/
export function requiresSummary( type ) {
const meta = renderersMeta[ type ] || { requireSummary: true };
return meta.requireSummary;
}
/**

View file

@ -119,8 +119,8 @@ module.exports = ( env, argv ) => ( {
// Minified uncompressed size limits for chunks / assets and entrypoints. Keep these numbers
// up-to-date and rounded to the nearest 10th of a kibibyte so that code sizing costs are
// well understood. Related to bundlesize minified, gzipped compressed file size tests.
maxAssetSize: 46.9 * 1024,
maxEntrypointSize: 46.9 * 1024,
maxAssetSize: 47.1 * 1024,
maxEntrypointSize: 47.1 * 1024,
// The default filter excludes map files but we rename ours.
assetFilter: ( filename ) => !filename.endsWith( srcMapExt )