Page MenuHomePhabricator

Investigate: Make a reusable collapsible component so that IPInfo infobox matches collapsible form [8h]
Closed, ResolvedPublicFeb 9 2021

Assigned To
Authored By
Tchanders
Dec 10 2020, 6:59 PM
Referenced Files
F34120952: image.png
Feb 24 2021, 12:36 PM
F34120964: image.png
Feb 24 2021, 12:36 PM
F34120957: image.png
Feb 24 2021, 12:36 PM

Description

Our use-case is adding a collapsible infobox to Special:Contributions, as discussed in T269622.

The collapsible forms currently use a custom widget CollapsibleFieldsetLayout.php along with styling that assumes the presence of a form, and is difficult to re-use.

We need to decide which is the best option: This could involve making a collapsible PanelLayout in OOUI, or a custom collapsible MediaWiki widget.

Details

Due Date
Feb 9 2021, 5:00 AM

Event Timeline

@Tchanders could this be a good onboarding task for one of our new hires?

@Niharika I think this would be too difficult for onboarding; it would require a good understanding of OOUI.

ARamirez_WMF renamed this task from Make a reusable collapsible component so that IPInfo infobox matches collapsible form to Investigate: Make a reusable collapsible component so that IPInfo infobox matches collapsible form [8h].Jan 20 2021, 6:43 PM
ARamirez_WMF updated the task description. (Show Details)
ARamirez_WMF changed the subtype of this task from "Task" to "Deadline".
How reusable is CollapsibleFieldsetLayout?

The CollapsibleFieldsetLayout is implemented in MediaWiki (rather than OOUI). It is a PHP layout with JS added via jquery.makeCollapsible.js, which works with the class mw-collapsible. The same script is also used in several other components.

CollapsibleFieldsetLayout is currently only used in OOUIHTMLForm: https://codesearch.wmcloud.org/search/?q=CollapsibleFieldsetLayout&i=nope&files=&excludeFiles=&repos= The layouts for a collapsible form are assembled in OOUIHTMLForm::wrapForm. The structure is essentially: PanelLayout > FormLayout > CollapsibleFieldsetLayout > Widget > HTMLSnippet with form HTML.

Margins and padding are defined in mediawiki.htmlform.ooui.styles.less, and are only applied if there is an outer, padded PanelLayout with the class mw-htmlform-ooui-wrapper.

These things make CollapsibleFieldsetLayout difficult to reuse because:

  • It can't be used as a JS-only layout
  • If not used within a PanelLayout with the classes oo-ui-panelLayout-padded and mw-htmlform-ooui-wrapper the appearance will be broken:
In PanelLayout with right classesIn PanelLayout with wrong classesNot in PanelLayout
image.png (874×78 px, 2 KB)
image.png (871×91 px, 3 KB)
image.png (872×50 px, 2 KB)
How can we make the IPInfo infobox look right?

A few options from less to more work (i.e. more to less hacky):

  1. In the PHP hook handler InfoBoxHandler::onSpecialPageBeforeExecute, add a padded PanelLayout (with class mw-htmlform-ooui-wrapper) with a CollapsibleFieldsetLayout. Then in the JS, append the IpInfoWidget to the CollapsibleFieldsetLayout.
  1. Add CSS for CollapsibleFieldsetLayout then upstream the margins and padding in mediawiki.htmlform.ooui.styles.less so the layout at least always appears the same when included in a padded PanelLayout. Then do (1), without having to add the mw-htmlform-ooui-wrapper class.
  1. Implement a JS version of the CollapsibleFieldsetLayout. (This would mean its behaviour could diverge from jquery.makeCollapsible.js, which probably has advantages and disadvantages, but other OOUI widgets/layouts handle their own behaviour, and we could make some sort of collapsible mixin.) Generalise the CSS as in (2). Then only use the JS version in IPInfo.
Recommendation

I'd recommend doing (2) for now, since it's a simple solution that leaves behind a way for others to reuse this component outside of a form context. I'd recommend filing (3) for later; it might become an obsolete requirement for MediaWiki if the Vue library gets there first.

@Niharika We discussed this in the engineering meeting - nothing more to add really, except to run by you which option we should do?

@Niharika We discussed this in the engineering meeting - nothing more to add really, except to run by you which option we should do?

I'll defer to you on this as this is purely technical. Happy to go with #2 per your recommendation. I'll close this task once follow-up tickets have been created.