Merge "Refactor: Make VectorTabs template data conform with MenuDefinition"

This commit is contained in:
jenkins-bot 2020-04-27 18:33:36 +00:00 committed by Gerrit Code Review
commit 358f26323e
4 changed files with 31 additions and 23 deletions

View file

@ -415,10 +415,11 @@ class VectorTemplate extends BaseTemplate {
*/ */
private function buildNamespacesProps() : array { private function buildNamespacesProps() : array {
$props = [ $props = [
'tabs-id' => 'p-namespaces', 'id' => 'p-namespaces',
'empty-portlet' => ( count( $this->get( 'namespace_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '', 'class' => ( count( $this->get( 'namespace_urls', [] ) ) == 0 ) ?
'emptyPortlet vectorTabs' : 'vectorTabs',
'label-id' => 'p-namespaces-label', 'label-id' => 'p-namespaces-label',
'msg-label' => $this->getMsg( 'namespaces' )->text(), 'label' => $this->getMsg( 'namespaces' )->text(),
'html-userlangattributes' => $this->get( 'userlangattributes', '' ), 'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
'html-items' => '', 'html-items' => '',
]; ];
@ -464,10 +465,11 @@ class VectorTemplate extends BaseTemplate {
*/ */
private function buildViewsProps() : array { private function buildViewsProps() : array {
$props = [ $props = [
'tabs-id' => 'p-views', 'id' => 'p-views',
'empty-portlet' => ( count( $this->get( 'view_urls', [] ) ) == 0 ) ? 'emptyPortlet' : '', 'class' => ( count( $this->get( 'view_urls', [] ) ) == 0 ) ?
'emptyPortlet vectorTabs' : 'vectorTabs',
'label-id' => 'p-views-label', 'label-id' => 'p-views-label',
'msg-label' => $this->getMsg( 'views' )->text(), 'label' => $this->getMsg( 'views' )->text(),
'html-userlangattributes' => $this->get( 'userlangattributes', '' ), 'html-userlangattributes' => $this->get( 'userlangattributes', '' ),
'html-items' => '', 'html-items' => '',
]; ];

View file

@ -1,13 +1,8 @@
{{! {{!
string tabs-id See @typedef MenuDefinition
string|null empty-portlet
string label-id
string|null msg-label
string|null html-userlangattributes
string|null html-items
}} }}
<div id="{{tabs-id}}" role="navigation" class="vectorTabs {{empty-portlet}}" aria-labelledby="{{label-id}}"> <div id="{{id}}" role="navigation" class="{{class}}" aria-labelledby="{{label-id}}">
<h3 id="{{label-id}}">{{msg-label}}</h3> <h3 id="{{label-id}}">{{label}}</h3>
<ul {{{html-userlangattributes}}}> <ul {{{html-userlangattributes}}}>
{{{html-items}}} {{{html-items}}}
</ul> </ul>

View file

@ -3,11 +3,14 @@ import vectorTabsTemplate from '!!raw-loader!../includes/templates/VectorTabs.mu
export { vectorTabsTemplate }; export { vectorTabsTemplate };
/**
* @type {MenuDefinition}
*/
export const pageActionsData = { export const pageActionsData = {
'tabs-id': 'p-views', id: 'p-views',
'empty-portlet': '', class: 'vectorTabs',
'label-id': 'p-views-label', 'label-id': 'p-views-label',
'msg-label': 'Views', label: 'Views',
'html-userlangattributes': htmluserlangattributes, 'html-userlangattributes': htmluserlangattributes,
'html-items': `<li id="ca-view" class="collapsible selected"> 'html-items': `<li id="ca-view" class="collapsible selected">
<a href="/wiki/Main_Page">Read</a> <a href="/wiki/Main_Page">Read</a>
@ -22,11 +25,14 @@ You can view its source [⌃⌥e]" accesskey="e">View source</a></li>
` `
}; };
/**
* @type {MenuDefinition}
*/
export const namespaceTabsData = { export const namespaceTabsData = {
'tabs-id': 'p-namespaces', id: 'p-namespaces',
'empty-portlet': '', class: 'vectorTabs',
'label-id': 'p-namespaces-label', 'label-id': 'p-namespaces-label',
'msg-label': 'Namespaces', label: 'Namespaces',
'html-userlangattributes': htmluserlangattributes, 'html-userlangattributes': htmluserlangattributes,
'html-items': `<li id="ca-nstab-main" class="selected"><a href="/wiki/Main_Page" title="View the content page [⌃⌥c]" accesskey="c">Main page</a></li> 'html-items': `<li id="ca-nstab-main" class="selected"><a href="/wiki/Main_Page" title="View the content page [⌃⌥c]" accesskey="c">Main page</a></li>
<li id="ca-talk"><a href="/wiki/Talk:Main_Page" rel="discussion" title="Discussion about the content page [⌃⌥t]" accesskey="t">Talk (3)</a></li>` <li id="ca-talk"><a href="/wiki/Talk:Main_Page" rel="discussion" title="Discussion about the content page [⌃⌥t]" accesskey="t">Talk (3)</a></li>`

View file

@ -134,6 +134,7 @@ class VectorTemplateTest extends MediaWikiIntegrationTestCase {
* @covers ::buildViewsProps * @covers ::buildViewsProps
* @covers ::buildActionsProps * @covers ::buildActionsProps
* @covers ::buildVariantsProps * @covers ::buildVariantsProps
* @covers ::buildNamespacesProps
* @covers ::getMenuProps * @covers ::getMenuProps
*/ */
public function testGetMenuProps() { public function testGetMenuProps() {
@ -147,17 +148,21 @@ class VectorTemplateTest extends MediaWikiIntegrationTestCase {
$props = $openVectorTemplate->getMenuProps(); $props = $openVectorTemplate->getMenuProps();
$views = $openVectorTemplate->buildViewsProps(); $views = $openVectorTemplate->buildViewsProps();
$namespaces = $openVectorTemplate->buildNamespacesProps();
$this->assertSame( $views, [ $this->assertSame( $views, [
'tabs-id' => 'p-views', 'id' => 'p-views',
'empty-portlet' => 'emptyPortlet', 'class' => 'emptyPortlet vectorTabs',
'label-id' => 'p-views-label', 'label-id' => 'p-views-label',
'msg-label' => 'Views', 'label' => 'Views',
'html-userlangattributes' => $langAttrs, 'html-userlangattributes' => $langAttrs,
'html-items' => '', 'html-items' => '',
'class' => 'emptyPortlet vectorTabs',
] ); ] );
$variants = $openVectorTemplate->buildVariantsProps(); $variants = $openVectorTemplate->buildVariantsProps();
$actions = $openVectorTemplate->buildActionsProps(); $actions = $openVectorTemplate->buildActionsProps();
$this->assertSame( $namespaces['class'],
'emptyPortlet vectorTabs' );
$this->assertSame( $variants['class'], $this->assertSame( $variants['class'],
'emptyPortlet vectorMenu' ); 'emptyPortlet vectorMenu' );
$this->assertSame( $actions['class'], $this->assertSame( $actions['class'],