Merge "Menu groups have identifiers"

This commit is contained in:
jenkins-bot 2019-10-28 13:50:30 +00:00 committed by Gerrit Code Review
commit 91243b1691
17 changed files with 66 additions and 29 deletions

View file

@ -1,2 +1,2 @@
{{> ToggleList/ToggleList}}
<!-- version 1.0.2 - used for partial template invalidation -->
<!-- version 1.1.0 - used for partial template invalidation -->

View file

@ -24,7 +24,7 @@
data-event-name="{{analyticsEventName}}">
{{text}}
</label>
<ul class="toggle-list__list new {{listClass}}">
<ul class="toggle-list__list new {{listClass}}" id="{{listID}}">
{{#items}}
{{> ToggleList/ToggleListItem}}
{{/items}}

View file

@ -33,6 +33,27 @@ final class Group {
*/
private $entries = [];
/**
* @var string
*/
private $id = '';
/**
* @param string $id of the menu defaults to null (optional)
*/
public function __construct( $id ) {
$this->id = $id;
}
/**
* Get the identifier for the group
*
* @return string
*/
public function getId() {
return $this->id;
}
/**
* Return entries count
*
@ -151,6 +172,17 @@ final class Group {
$index = $this->search( $targetName );
return $this->entries[$index];
}
/**
* Serialize the group for use in a template
* @return array{entries:array,id:string}
*/
public function serialize() {
return [
'entries' => $this->getEntries(),
'id' => $this->getId(),
];
}
}
/**

View file

@ -94,7 +94,7 @@ final class AdvancedMainMenuBuilder implements IMainMenuBuilder {
* @throws MWException
*/
private function getSiteTools(): Group {
$group = new Group();
$group = new Group( 'p-interaction' );
$this->definitions->insertRecentChanges( $group );
$this->definitions->insertSpecialPages( $group );

View file

@ -40,7 +40,7 @@ final class BuilderUtil {
* @throws MWException
*/
public static function getDiscoveryTools( Definitions $definitions ): Group {
$group = new Group();
$group = new Group( 'p-navigation' );
$definitions->insertHomeItem( $group );
$definitions->insertRandomItem( $group );
@ -63,7 +63,7 @@ final class BuilderUtil {
public static function getConfigurationTools(
Definitions $definitions, $showMobileOptions
): Group {
$group = new Group();
$group = new Group( 'pt-preferences' );
$showMobileOptions ?
$definitions->insertMobileOptionsItem( $group ) :
@ -79,7 +79,7 @@ final class BuilderUtil {
* @throws MWException
*/
public static function getSiteLinks( Definitions $definitions ): Group {
$group = new Group();
$group = new Group( 'p-minerva-sitelinks' );
$definitions->insertAboutItem( $group );
$definitions->insertDisclaimersItem( $group );

View file

@ -92,7 +92,7 @@ final class DefaultMainMenuBuilder implements IMainMenuBuilder {
* @throws MWException
*/
private function getPersonalTools(): Group {
$group = new Group();
$group = new Group( 'p-personal' );
$this->definitions->insertAuthMenuItem( $group );

View file

@ -93,7 +93,7 @@ final class MainMenuDirector {
];
foreach ( $this->builder->getGroups() as $group ) {
if ( $group->hasEntries() ) {
$menuData['items']['groups'][] = $group->getEntries();
$menuData['items']['groups'][] = $group->serialize();
}
}
return $menuData;

View file

@ -45,7 +45,7 @@ class DefaultOverflowBuilder implements IOverflowBuilder {
* @inheritDoc
*/
public function getGroup( array $toolbox ): Group {
$group = new Group();
$group = new Group( 'p-tb' );
$possibleEntries = array_filter( [
$this->build( 'info', 'infoFilled', 'info', $toolbox ),
$this->build( 'permalink', 'link', 'permalink', $toolbox ),

View file

@ -28,6 +28,6 @@ class EmptyOverflowBuilder implements IOverflowBuilder {
* @inheritDoc
*/
public function getGroup( array $toolbox ): Group {
return new Group();
return new Group( 'p-tb' );
}
}

View file

@ -80,6 +80,7 @@ final class PageActionsDirector {
'item-id' => 'page-actions-overflow',
'checkboxID' => 'page-actions-overflow-checkbox',
'toggleID' => 'page-actions-overflow-toggle',
'listID' => $overflowMenu->getId(),
'toggleClass' => MinervaUI::iconClass( 'page-actions-overflow', 'element' ),
'listClass' => 'page-actions-overflow-list toggle-list__list--drop-down',
'text' => $this->messageLocalizer->msg( 'minerva-page-actions-overflow' ),

View file

@ -105,7 +105,7 @@ class ToolbarBuilder {
* @throws MWException
*/
public function getGroup(): Group {
$group = new Group();
$group = new Group( 'p-views' );
$permissions = $this->permissions;
$userPageWithOveflowMode = $this->skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) &&
$this->userPageHelper->isUserPage();

View file

@ -86,7 +86,7 @@ class UserNamespaceOverflowBuilder implements IOverflowBuilder {
* @throws MWException
*/
public function getGroup( array $toolbox ): Group {
$group = new Group();
$group = new Group( 'p-tb' );
if ( $this->permissions->isAllowed( IMinervaPagePermissions::SWITCH_LANGUAGE ) ) {
$group->insertEntry( new LanguageSelectorEntry(
$this->title,

View file

@ -66,7 +66,7 @@ final class AdvancedUserMenuBuilder implements IUserMenuBuilder {
* @return Group
*/
public function getGroup( array $personalTools ): Group {
$group = new Group();
$group = new Group( 'p-personal' );
$group->insertEntry( new ProfileMenuEntry( $this->user ) );
$talkPage = $this->user->getUserPage()->getTalkPageIfDefined();
if ( $talkPage ) {

View file

@ -30,6 +30,6 @@ final class DefaultUserMenuBuilder implements IUserMenuBuilder {
* @return Group
*/
public function getGroup( array $personalTools ): Group {
return new Group();
return new Group( 'p-personal' );
}
}

View file

@ -52,7 +52,8 @@ final class UserMenuDirector {
* @return string|null
*/
public function renderMenuData( array $personalTools ) {
$entries = $this->builder->getGroup( $personalTools )->getEntries();
$group = $this->builder->getGroup( $personalTools );
$entries = $group->getEntries();
$templateParser = new TemplateParser( __DIR__ . '/../../../components' );
return empty( $entries )
@ -64,6 +65,7 @@ final class UserMenuDirector {
'toggleClass' => MinervaUI::iconClass(
'page-actions-overflow', 'element', 'wikimedia-ui-' . 'userAvatarOutline' . '-base20'
),
'listID' => $group->getId(),
'listClass' => 'minerva-user-menu-list toggle-list__list--drop-down', // See ToggleList/*.less.
'text' => $this->localizer->msg( 'minerva-user-menu-button' )->escaped(),
'analyticsEventName' => 'ui.usermenu',

View file

@ -1,10 +1,12 @@
<div class="menu view-border-box">
{{#groups}}
<ul>
<ul id="{{id}}">
{{! "." means "current context", which allows us to iterate over Plain Old PHP Arrays™. }}
{{#.}}
{{#entries}}
{{#.}}
{{> menuGroup}}
{{/.}}
{{/.}}
{{/entries}}
</ul>
{{/groups}}
<ul class="hlist">

View file

@ -28,7 +28,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers ::getEntries
*/
public function testItShouldntHaveEntriesByDefault() {
$menu = new Group();
$menu = new Group( 'p-test' );
$this->assertEmpty( $menu->getEntries() );
}
@ -40,7 +40,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers \MediaWiki\Minerva\Menu\Entries\MenuEntry::addComponent
*/
public function testInsertingAnEntry() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'home' )
->addComponent(
$this->homeComponent['text'],
@ -68,7 +68,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers \MediaWiki\Minerva\Menu\Entries\MenuEntry::addComponent
*/
public function testInsertingAnEntryAfterAnother() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'home' )
->addComponent(
$this->homeComponent['text'],
@ -118,7 +118,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers \MediaWiki\Minerva\Menu\Entries\MenuEntry::addComponent
*/
public function testInsertAfterWhenTargetEntryDoesntExist() {
$menu = new Group();
$menu = new Group( 'p-test' );
$this->expectException( DomainException::class );
$this->expectExceptionMessage( 'The "home" entry doesn\'t exist.' );
$menu->insertAfter( 'home', 'nearby' )
@ -133,7 +133,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers ::insertAfter
*/
public function testInsertAfterWithAnEntryWithAnExistingName() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'home' );
$menu->insert( 'car' );
$this->expectException( DomainException::class );
@ -145,7 +145,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers ::insert
*/
public function testInsertingAnEntryWithAnExistingName() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'home' );
$this->expectException( DomainException::class );
$this->expectExceptionMessage( 'The "home" entry already exists.' );
@ -157,7 +157,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers ::insertAfter
*/
public function testInsertingAnEntryAfterAnotherOne() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'first' );
$menu->insert( 'last' );
$menu->insertAfter( 'first', 'middle' );
@ -187,7 +187,7 @@ class GroupTest extends \MediaWikiTestCase {
'mw-ui-icon mw-ui-icon-element secondary-logout secondary-action truncated-text',
];
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'auth' )
->addComponent(
$authLoginComponent['text'],
@ -219,7 +219,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers \MediaWiki\Minerva\Menu\Entries\MenuEntry::addComponent
*/
public function testInsertingAJavascriptOnlyEntry() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'nearby', $isJSOnly = true )
->addComponent(
$this->nearbyComponent['text'],
@ -243,7 +243,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers ::search
*/
public function testGetEntryByName() {
$menu = new Group();
$menu = new Group( 'p-test' );
$menu->insert( 'home' )
->addComponent(
$this->homeComponent['text'],
@ -257,7 +257,7 @@ class GroupTest extends \MediaWikiTestCase {
* @covers ::search
*/
public function testGetEntryByNameException() {
$menu = new Group();
$menu = new Group( 'p-test' );
$this->expectException( DomainException::class );
$menu->getEntryByName( 'home' );
}