Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace jumpMenu controls with menu-button components #2814

Draft
wants to merge 47 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d064beb
Add showSelectedValue option in menu-button component.
demiankatz Mar 31, 2023
bbe193c
Convert sort control to use menu-button.
demiankatz Mar 31, 2023
d97e578
Fix style.
demiankatz Mar 31, 2023
2706988
Convert limit control.
demiankatz Mar 31, 2023
9fa8233
php-cs-fixer
demiankatz Mar 31, 2023
c8ff113
Merge branch 'dev' into jumpmenu-to-menu-button
demiankatz Apr 4, 2023
0e2711b
Add support for custom link attributes.
demiankatz Apr 4, 2023
88cb036
Eliminate library card jump menu.
demiankatz Apr 4, 2023
7854e41
Fix styles.
demiankatz Apr 4, 2023
694dc0c
Style tweak.
demiankatz Apr 4, 2023
a621742
Refactor myresearch sort.
demiankatz Apr 4, 2023
626f46e
Allow no label.
demiankatz Apr 4, 2023
72fe14b
Refactor scheduled search control.
demiankatz Apr 4, 2023
9590f21
Finish jumpmenu conversion.
demiankatz Apr 4, 2023
01df62f
Remove jumpMenu logic.
demiankatz Apr 4, 2023
d496be6
style: apply button styles and alignment to new search controls.
crhallberg Apr 11, 2023
f6fca3e
Merge branch 'dev' into jumpmenu-to-menu-button
demiankatz Apr 12, 2023
0bb8fac
Separate selected value from label.
demiankatz Apr 12, 2023
83db603
style: visual and code styles.
crhallberg Apr 12, 2023
6cc486a
Revert accidental change.
demiankatz Apr 13, 2023
b7f3943
lessToSass
demiankatz Apr 13, 2023
0970aa1
Space out icon with CSS instead of actual space.
demiankatz Apr 13, 2023
1825b0f
Fix SearchLimitTest and make some associated fixes/improvements.
demiankatz Apr 13, 2023
09c6326
Fix SavedSearchesTest.
demiankatz Apr 13, 2023
607cb34
php-cs-fixer
demiankatz Apr 13, 2023
625c694
Merge branch 'dev' into jumpmenu-to-menu-button
demiankatz Apr 13, 2023
ad4af22
Merge branch 'dev' into jumpmenu-to-menu-button
demiankatz Jun 21, 2023
b713db9
Merge remote-tracking branch 'origin/dev' into jumpmenu-to-menu-button
crhallberg Jul 25, 2023
307197f
Merge branch 'dev' into jumpmenu-to-menu-button-2
EreMaijala Jan 11, 2024
7133452
Fix search controls, stack vertically.
EreMaijala Jan 11, 2024
63bed40
Fix alignment and spacing issues.
EreMaijala Jan 11, 2024
6ebf0f5
Fix empty label and white-space decoration issue in search history.
EreMaijala Jan 11, 2024
aa5824c
Fix Mink tests.
EreMaijala Jan 11, 2024
89014c8
Improve dropdown alignment and nav menu button style.
EreMaijala Jan 11, 2024
46be96d
Fix code style.
EreMaijala Jan 11, 2024
2144891
Merge pull request #29 from EreMaijala/jumpmenu-to-menu-button
demiankatz Jan 11, 2024
fd7264e
Merge remote-tracking branch 'origin/dev' into jumpmenu-to-menu-button
crhallberg Feb 6, 2024
d59134f
fix: style search controls to take up enough room.
crhallberg Feb 6, 2024
26171bc
lessToSass.
demiankatz Feb 8, 2024
4acca55
Merge branch 'dev' into jumpmenu-to-menu-button
demiankatz Feb 8, 2024
b0e7cab
Restore missing definition.
demiankatz Feb 8, 2024
f6a9570
Merge remote-tracking branch 'origin/dev' into jumpmenu-to-menu-button
crhallberg Feb 27, 2024
b0cd316
Merge remote-tracking branch 'origin/dev' into jumpmenu-to-menu-button
crhallberg Feb 28, 2024
c7dfee4
Use clickCss where possible.
demiankatz Feb 28, 2024
9ca7d95
Merge remote-tracking branch 'origin/dev' into jumpmenu-to-menu-button
crhallberg Mar 25, 2024
cf7d254
Merge remote-tracking branch 'origin/dev' into jumpmenu-to-menu-button
crhallberg May 7, 2024
2e0e7e0
chore: less
crhallberg May 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion module/VuFind/src/VuFind/AjaxHandler/GetSearchResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*
* PHP version 8
*
* Copyright (C) The National Library of Finland 2023.
* Copyright (C) The National Library of Finland 2023-2024.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -96,6 +96,14 @@ class GetSearchResults extends \VuFind\AjaxHandler\AbstractBase implements
'aria-live' => 'polite',
],
],
'.js-search-sort' => [
'method' => 'renderSort',
'target' => 'inner',
],
'.js-search-limit' => [
'method' => 'renderLimit',
'target' => 'inner',
],
'.js-result-list' => [
'method' => 'renderResults',
'target' => 'outer',
Expand Down Expand Up @@ -334,6 +342,46 @@ protected function renderSearchStats(ParamsHelper $requestParams, Results $resul
return $this->translate($statsKey, $transParams);
}

/**
* Render sort control
*
* @param Params $params Request params
* @param Results $results Search results
*
* @return ?string
*/
protected function renderSort(Params $params, Results $results): ?string
{
$params = $results->getParams();
return $this->renderer->render(
'search/controls/sort.phtml',
compact(
'results',
'params',
)
);
}

/**
* Render limit control
*
* @param Params $params Request params
* @param Results $results Search results
*
* @return ?string
*/
protected function renderLimit(Params $params, Results $results): ?string
{
$params = $results->getParams();
return $this->renderer->render(
'search/controls/limit.phtml',
compact(
'results',
'params',
)
);
}

/**
* Render analytics
*
Expand Down
16 changes: 12 additions & 4 deletions module/VuFind/src/VuFindTest/Feature/SearchSortTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ trait SearchSortTrait
*
* @var string
*/
protected $sortControlSelector = '#sort_options_1';
protected $sortControlSelector = '.search__sort';

/**
* VuFind default sort options
Expand Down Expand Up @@ -97,7 +97,15 @@ protected function assertResultTitles(Element $page, int $count, string $first,
*/
protected function sortResults(Element $page, string $value): void
{
$this->findCssAndSetValue($page, $this->sortControlSelector, $value);
$sortControl = $this->clickCss($page, $this->sortControlSelector);
$links = $sortControl->findAll('css', 'a');
foreach ($links as $link) {
if ($link->getText() === $value) {
$link->click();
return;
}
}
throw new \Exception("Sort link for '$value' not found");
}

/**
Expand All @@ -110,7 +118,7 @@ protected function sortResults(Element $page, string $value): void
*/
protected function assertSelectedSort(Element $page, string $active): void
{
$sort = $this->findCss($page, $this->sortControlSelector);
$this->assertEquals((string)$active, $sort->getValue());
$sort = $this->findCss($page, $this->sortControlSelector . ' li.active a');
$this->assertEquals($active, $sort->getText());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ public function testLoanHistory(): void
$this->findCssAndGetText($page, 'ul.record-list li a.title', null, $index)
);
}
$this->clickCss($page, '#sort_options_1 option', null, 2);
$this->clickCss($page, '.list__sort button.dropdown-toggle');
$this->clickCss($page, '.list__sort li a', null, 2);
$this->waitForPageLoad($page);
foreach (array_reverse($titles) as $index => $title) {
$this->assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public function testSwitchingCards(): void
$this->waitForPageLoad($page);

// Confirm the presence of a library card selector on the page:
$firstCard = $this->findCss($page, '#library_card option:nth-child(1)');
$secondCard = $this->findCss($page, '#library_card option:nth-child(2)');
$firstCard = $this->findCss($page, '.select-library-card li:nth-child(1) a');
$secondCard = $this->findCss($page, '.select-library-card li:nth-child(2) a');
$card2Value = $secondCard->getValue();
$this->assertEquals('card 1', $firstCard->getText());
$this->assertEquals('card 2', $secondCard->getText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function testTagSearch(): void
// Now perform the search:
$page = $this->performSearch('five', 'tag');
$this->assertResultTitles($page, 3, 'Dewey browse test', '<HTML> The Basics');
$this->assertSelectedSort($page, 'title');
$this->assertSelectedSort($page, 'Title');
}

/**
Expand All @@ -338,17 +338,16 @@ public function testTagSearch(): void
public static function getTagSearchSortData(): array
{
return [
[1, 'author', 'Fake Record 1 with multiple relators/', 'Dewey browse test'],
[2, 'year DESC', '<HTML> The Basics', 'Fake Record 1 with multiple relators/'],
[3, 'year', 'Fake Record 1 with multiple relators/', '<HTML> The Basics'],
['Author', 'Fake Record 1 with multiple relators/', 'Dewey browse test'],
['Date Descending', '<HTML> The Basics', 'Fake Record 1 with multiple relators/'],
['Date Ascending', 'Fake Record 1 with multiple relators/', '<HTML> The Basics'],
];
}

/**
* Test sorting the tag search results.
*
* @param int $index Sort drop-down index to test
* @param string $expectedSort Expected sort value at $index
* @param string $sort Sort option to use
* @param string $expectedFirst Expected first title after sorting
* @param string $expectedLast Expected last title after sorting
*
Expand All @@ -359,16 +358,15 @@ public static function getTagSearchSortData(): array
* @depends testTagSearch
*/
public function testTagSearchSort(
int $index,
string $expectedSort,
string $sort,
string $expectedFirst,
string $expectedLast
): void {
$page = $this->performSearch('five', 'tag');
$this->clickCss($page, $this->sortControlSelector . ' option', null, $index);
$this->sortResults($page, $sort);
$this->waitForPageLoad($page);
$this->assertResultTitles($page, 3, $expectedFirst, $expectedLast);
$this->assertSelectedSort($page, $expectedSort);
$this->assertSelectedSort($page, $sort);
}

/**
Expand Down Expand Up @@ -734,26 +732,24 @@ public function testRating($allowRemove): void
$this->findCss($page, 'form.comment-form a');
$this->clickCss($page, 'form.comment-form .btn-primary');
// Check result (wait for the value to update):
$this->assertEqualsWithTimeout(
[1, '80'],
function () use ($page, $checked) {
$inputs = $page->findAll('css', $checked);
$ratingCallback = function () use ($page, $checked) {
$inputs = $page->findAll('css', $checked);
// getValue can fail in the middle of update, so wrap in try..catch:
try {
return [count($inputs), $inputs ? $inputs[0]->getValue() : null];
} catch (\Exception $e) {
return [null, null];
}
);
};

$this->assertEqualsWithTimeout([1, '80'], $ratingCallback);
if ($allowRemove) {
// Clear rating when adding another comment
$this->findCssAndSetValue($page, 'form.comment-form [name="comment"]', 'two');
$this->clickCss($page, 'form.comment-form a');
$this->clickCss($page, 'form.comment-form .btn-primary');
// Check result (wait for the value to update):
$this->assertEqualsWithTimeout(
[1, '70'],
function () use ($page, $checked) {
$inputs = $page->findAll('css', $checked);
return [count($inputs), $inputs ? $inputs[0]->getValue() : null];
}
);
$this->assertEqualsWithTimeout([1, '70'], $ratingCallback);
} else {
// Check that the "Clear" link is no longer available:
$this->unFindCss($page, 'form.comment-form a');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ final class SavedSearchesTest extends \VuFindTest\Integration\MinkTestCase
use \VuFindTest\Feature\LiveDatabaseTrait;
use \VuFindTest\Feature\UserCreationTrait;

/**
* Selector for the schedule control
*
* @var string
*/
protected $scheduleSelector = '.search__notify';

/**
* Standard setup method.
*
Expand Down Expand Up @@ -114,18 +121,13 @@ protected function assertSavedSearchList(array $expected, Element $page): void
{
// Pull all the links from the search history table and format them into
// a string:
$saved = $page->findAll('css', '#saved-searches td a');
$saved = $page->findAll('css', '#saved-searches a.history-entry');
$callback = function ($link) {
return trim($link->getText());
};
$linkText = implode("\n", array_map($callback, $saved));

// Each expected search link should have a corresponding Delete link; create
// an expectation accordingly:
$expectedCallback = function ($link) {
return "$link\nDelete";
};
$expectedLinkText = implode("\n", array_map($expectedCallback, $expected));
$expectedLinkText = implode("\n", $expected);

// Compare the expected and actual strings:
$this->assertEquals($expectedLinkText, $linkText);
Expand Down Expand Up @@ -311,39 +313,39 @@ public function testNotificationSettings(): void
$this->findAndAssertLink($page, 'Search History')->click();

// By default, there should be no alert option at all:
$scheduleSelector = 'select[name="schedule"]';
$this->assertNull($page->find('css', $scheduleSelector));
$this->assertNull($page->find('css', $this->scheduleSelector));

// Now reconfigure to allow notifications, and refresh the page:
$page = $this->activateNotifications();

// Now there should be two alert options visible (one in saved, one in
// unsaved):
$this->assertCount(2, $page->findAll('css', $scheduleSelector));
$this->assertCount(2, $page->findAll('css', $this->scheduleSelector));
$this->assertCount(
1,
$page->findAll('css', '#recent-searches ' . $scheduleSelector)
$page->findAll('css', '#recent-searches ' . $this->scheduleSelector)
);
$this->assertCount(
1,
$page->findAll('css', '#saved-searches ' . $scheduleSelector)
$page->findAll('css', '#saved-searches ' . $this->scheduleSelector)
);

// At this point, our journals search should be in the unsaved list; let's
// set it up for alerts and confirm that this auto-saves it.
$select = $this->findCss($page, '#recent-searches ' . $scheduleSelector);
$select->selectOption(7);
$this->clickCss($page, '#recent-searches ' . $this->scheduleSelector);
$this->waitForPageLoad($page);
$this->findCss($page, '#recent-searches ' . $this->scheduleSelector)->findLink('Weekly')->click();
$this->waitForPageLoad($page);
$this->assertCount(
2,
$page->findAll('css', '#saved-searches ' . $scheduleSelector)
$page->findAll('css', '#saved-searches ' . $this->scheduleSelector)
);

// Now let's delete the saved search and confirm that this clears the
// alert subscription.
$this->findAndAssertLink($page, 'Delete')->click();
$this->waitForPageLoad($page);
$select = $this->findCss($page, '#recent-searches ' . $scheduleSelector);
$select = $this->findCss($page, '#recent-searches ' . $this->scheduleSelector);
$this->assertEquals(0, $select->getValue());
}

Expand Down Expand Up @@ -377,9 +379,9 @@ public function testNotificationsInSearchToolbar()
$this->waitForPageLoad($page);

// We should now be on a page with a schedule selector; let's pick something:
$scheduleSelector = 'select[name="schedule"]';
$select = $this->findCss($page, $scheduleSelector);
$select->selectOption(7);
$this->clickCss($page, $this->scheduleSelector);
$this->waitForPageLoad($page);
$this->findCss($page, $this->scheduleSelector)->findLink('Weekly')->click();
$this->waitForPageLoad($page);

// Let's confirm that if we repeat the search, the alert will now be set:
Expand Down Expand Up @@ -415,6 +417,11 @@ public function testNotificationsInSearchToolbarDeduplication()

// We should now be on a page with a schedule selector; because of the
// setting we set in the previous test, and with login deduplication, we
// should now see the "Weekly" option already selected:
$this->assertEquals(
'Weekly',
$this->findCss($page, $this->scheduleSelector . ' button')->getText()
);
// should now see the "7" option already selected:
$scheduleSelector = 'select[name="schedule"]';
$this->assertEquals(7, $this->findCssAndGetValue($page, $scheduleSelector));
Expand All @@ -439,20 +446,21 @@ public function testNotificationsInSearchHistoryDeduplication()
$this->waitForPageLoad($page);

// Now there should be one alert option visible (in unsaved):
$scheduleSelector = 'select[name="schedule"]';
$this->assertCount(1, $page->findAll('css', $scheduleSelector));
$this->assertCount(1, $page->findAll('css', $this->scheduleSelector));
$this->assertCount(
1,
$page->findAll('css', '#recent-searches ' . $scheduleSelector)
$page->findAll('css', '#recent-searches ' . $this->scheduleSelector)
);
$this->assertCount(
0,
$page->findAll('css', '#saved-searches ' . $scheduleSelector)
$page->findAll('css', '#saved-searches ' . $this->scheduleSelector)
);

// Let's set up our search for alerts and make sure it's handled correctly:
$select = $this->findCss($page, '#recent-searches ' . $scheduleSelector);
$select->selectOption(1);
$select = $this->findCss($page, '#recent-searches ' . $this->scheduleSelector);
$select->click();
$this->waitForPageLoad($page);
$select->findLink('Daily')->click();
$this->waitForPageLoad($page);

// We should now be prompted to log in:
Expand All @@ -469,8 +477,13 @@ public function testNotificationsInSearchHistoryDeduplication()
$this->assertSavedSearchList(['employment', 'test'], $page);
$this->assertCount(
2,
$page->findAll('css', '#saved-searches ' . $scheduleSelector)
$page->findAll('css', '#saved-searches ' . $this->scheduleSelector)
);
$this->assertEquals(
'Daily',
$this->findCss($page, $this->scheduleSelector . ' button')->getText()
);
$scheduleSelector = 'select[name="schedule"]';
$this->assertEquals(1, $this->findCssAndGetValue($page, $scheduleSelector));
}

Expand Down
Loading
Loading