Skip to content

Commit 7db6093

Browse files
committed
history: ship review changes
1 parent 9bf9837 commit 7db6093

File tree

6 files changed

+51
-23
lines changed

6 files changed

+51
-23
lines changed

special-pages/pages/history/app/global/Providers/HistoryServiceProvider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { generateHeights } from '../../utils.js';
1313
* | {kind: 'delete-domain'; domain: string }
1414
* | {kind: 'delete-entries-by-index'; value: number[] }
1515
* | {kind: 'open-url'; url: string, target: 'new-tab' | 'new-window' | 'same-tab' }
16-
* | {kind: 'show-entries-menu'; ids: string[]; indexes: number[] }
16+
* | {kind: 'show-entries-menu'; indexes: number[] }
1717
* | {kind: 'request-more'; end: number }
1818
* } Action
1919
*/
@@ -126,7 +126,7 @@ export function HistoryServiceProvider({ service, children, initial }) {
126126
}
127127
case 'show-entries-menu': {
128128
service
129-
.entriesMenu(action.ids, action.indexes)
129+
.entriesMenu(action.indexes)
130130
// eslint-disable-next-line promise/prefer-await-to-then
131131
.then((resp) => {
132132
if (resp.kind === 'domain-search') {

special-pages/pages/history/app/global/hooks/useButtonClickHandler.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect } from 'preact/hooks';
22
import { BTN_ACTION_ENTRIES_MENU, KNOWN_ACTIONS } from '../../constants.js';
33
import { useHistoryServiceDispatch } from '../Providers/HistoryServiceProvider.js';
4+
import { useSelected } from '../Providers/SelectionProvider.js';
45

56
/**
67
* This function registers button click handlers that communicate with the history service.
@@ -11,6 +12,7 @@ import { useHistoryServiceDispatch } from '../Providers/HistoryServiceProvider.j
1112
*/
1213
export function useButtonClickHandler() {
1314
const historyServiceDispatch = useHistoryServiceDispatch();
15+
const selected = useSelected();
1416
useEffect(() => {
1517
function clickHandler(/** @type {MouseEvent} */ event) {
1618
if (!(event.target instanceof Element)) return;
@@ -30,11 +32,19 @@ export function useButtonClickHandler() {
3032

3133
switch (action) {
3234
case BTN_ACTION_ENTRIES_MENU: {
33-
historyServiceDispatch({
34-
kind: 'show-entries-menu',
35-
ids: [btn.value],
36-
indexes: [Number(btn.dataset.index)],
37-
});
35+
const index = parseInt(btn.dataset.index ?? '-1', 10);
36+
const withinSelection = selected.value.has(index);
37+
if (withinSelection) {
38+
historyServiceDispatch({
39+
kind: 'show-entries-menu',
40+
indexes: [...selected.value],
41+
});
42+
} else {
43+
historyServiceDispatch({
44+
kind: 'show-entries-menu',
45+
indexes: [Number(btn.dataset.index)],
46+
});
47+
}
3848
return;
3949
}
4050
default:

special-pages/pages/history/app/global/hooks/useContextMenuForEntries.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from 'preact/hooks';
22
import { useSelected } from '../Providers/SelectionProvider.js';
3-
import { useHistoryServiceDispatch, useResultsData } from '../Providers/HistoryServiceProvider.js';
3+
import { useHistoryServiceDispatch } from '../Providers/HistoryServiceProvider.js';
44

55
/**
66
* Support for context menu on entries. This needs to be aware of
@@ -9,7 +9,6 @@ import { useHistoryServiceDispatch, useResultsData } from '../Providers/HistoryS
99
*/
1010
export function useContextMenuForEntries() {
1111
const selected = useSelected();
12-
const results = useResultsData();
1312
const dispatch = useHistoryServiceDispatch();
1413

1514
useEffect(() => {
@@ -26,18 +25,9 @@ export function useContextMenuForEntries() {
2625

2726
const isSelected = elem.getAttribute('aria-selected') === 'true';
2827
if (isSelected) {
29-
const indexes = [...selected.value];
30-
const ids = [];
31-
for (let i = 0; i < indexes.length; i++) {
32-
const current = results.value.items[indexes[i]];
33-
if (!current) throw new Error('unreachable');
34-
ids.push(current.id);
35-
}
36-
dispatch({ kind: 'show-entries-menu', ids, indexes });
28+
dispatch({ kind: 'show-entries-menu', indexes: [...selected.value] });
3729
} else {
38-
const button = /** @type {HTMLButtonElement|null} */ (elem.querySelector('button[value]'));
39-
const id = button?.value || '';
40-
dispatch({ kind: 'show-entries-menu', ids: [id], indexes: [Number(elem.dataset.index)] });
30+
dispatch({ kind: 'show-entries-menu', indexes: [Number(elem.dataset.index)] });
4131
}
4232
}
4333

special-pages/pages/history/app/history.service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,12 @@ export class HistoryService {
216216
}
217217

218218
/**
219-
* @param {string[]} ids
220219
* @param {number[]} indexes
221220
* @return {Promise<{kind: 'none'} | { kind: 'domain-search'; value: string }>}
222221
*/
223-
async entriesMenu(ids, indexes) {
224-
console.log('📤 [entries_menu]: ', JSON.stringify({ ids }));
222+
async entriesMenu(indexes) {
223+
const ids = this._collectIds(indexes);
224+
console.trace('📤 [entries_menu]: ', JSON.stringify({ ids }));
225225
const response = await this.history.messaging.request('entries_menu', { ids });
226226
if (response.action === 'none') {
227227
return { kind: 'none' };

special-pages/pages/history/integration-tests/history-selections.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,11 @@ test.describe('history selections', () => {
187187
await hp.selectsRowIndexWithShift(2);
188188
await hp.deletesWithKeyboard(hp.ids(3), { action: 'delete' });
189189
});
190+
test('3 dots menu on multiple history entries', async ({ page }, workerInfo) => {
191+
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
192+
await hp.openPage({});
193+
await hp.selectsRowIndex(0);
194+
await hp.selectsRowIndexWithShift(2);
195+
await hp.menuForMultipleHistoryEntries(0, hp.ids(3), { action: 'delete' });
196+
});
190197
});

special-pages/pages/history/integration-tests/history.page.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,27 @@ export class HistoryTestPage {
317317
cleanup();
318318
}
319319

320+
/**
321+
* @param {number} nth - row index to click the 3 dots on
322+
* @param {string[]} ids - expected ids
323+
* @param {import('../types/history.ts').DeleteRangeResponse} resp
324+
*/
325+
async menuForMultipleHistoryEntries(nth, ids, resp) {
326+
const { page } = this;
327+
328+
const cleanup = this._withDialogHandling(resp);
329+
// console.log(data[0].title);
330+
const data = generateSampleData({ count: this.entries, offset: 0 });
331+
const nthItem = data[nth];
332+
const row = page.getByText(nthItem.title);
333+
await row.hover();
334+
await page.locator(`[data-action="entries_menu"][value=${nthItem.id}]`).click();
335+
336+
const calls = await this.mocks.waitForCallCount({ method: 'entries_menu', count: 1 });
337+
expect(calls[0].payload.params).toStrictEqual({ ids: ids });
338+
cleanup();
339+
}
340+
320341
/**
321342
* @param {number} nth
322343
*/

0 commit comments

Comments
 (0)