Skip to content

Commit 3bad912

Browse files
committed
only reset if delete actually happened
1 parent b59d1c9 commit 3bad912

File tree

5 files changed

+43
-6
lines changed

5 files changed

+43
-6
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export function HistoryServiceProvider({ service, children }) {
5656
service
5757
.deleteRange(range)
5858
// eslint-disable-next-line promise/prefer-await-to-then
59-
.then(() => queryDispatch({ kind: 'reset' }))
59+
.then((resp) => {
60+
if (resp.kind === 'range-deleted') {
61+
queryDispatch({ kind: 'reset' });
62+
}
63+
})
6064
// eslint-disable-next-line promise/prefer-await-to-then
6165
.catch(console.error);
6266
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { OVERSCAN_AMOUNT } from './constants.js';
22
import { HistoryRangeService } from './history.range.service.js';
33

44
/**
5+
* @import {ActionResponse} from "../types/history.js"
56
* @typedef {import('../types/history.js').Range} Range
67
* @typedef {import('../types/history.js').HistoryQuery} HistoryQuery
78
* @typedef {import("../types/history.js").HistoryQueryInfo} HistoryQueryInfo
@@ -306,14 +307,17 @@ export class HistoryService {
306307

307308
/**
308309
* @param {Range} range
310+
* @return {Promise<{kind: 'none'} | {kind: "range-deleted"}>}
309311
*/
310312
async deleteRange(range) {
311-
console.log('📤 [deleteRange]: ', JSON.stringify({ range }));
312313
const resp = await this.range.deleteRange(range);
313314
if (resp.action === 'delete' && range === 'all') {
314315
this.reset();
315316
}
316-
return resp;
317+
if (resp.action === 'delete') {
318+
return { kind: 'range-deleted' };
319+
}
320+
return { kind: 'none' };
317321
}
318322

319323
/**

special-pages/pages/history/app/mocks/mock-transport.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export function mockTransport() {
103103
return Promise.resolve({ action: 'none' });
104104
}
105105
case 'title_menu': {
106-
// console.log('📤 [deleteRange]: ', JSON.stringify(msg.params));
107106
// prettier-ignore
108107
const lines = [
109108
`title_menu: ${JSON.stringify(msg.params)}`,
@@ -115,7 +114,7 @@ export function mockTransport() {
115114
return Promise.resolve({ action: 'none' });
116115
}
117116
case 'deleteRange': {
118-
console.log('📤 [deleteRange]: ', JSON.stringify(msg.params));
117+
// console.log('📤 [deleteRange]: ', JSON.stringify(msg.params));
119118
// prettier-ignore
120119
const lines = [
121120
`deleteRange: ${JSON.stringify(msg.params)}`,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ export class HistoryTestPage {
126126
expect(params).toStrictEqual({ query, limit: 150, offset: 0 });
127127
}
128128

129+
/**
130+
* @param {number} n
131+
*/
132+
async didMakeNQueries(n) {
133+
const calls = await this.mocks.outgoing({ names: ['query'] });
134+
expect(calls).toHaveLength(n);
135+
}
136+
129137
/**
130138
* @param {object} props
131139
* @param {number} props.nth

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test.describe('history', () => {
9191
await hp.openPage({});
9292
await hp.opensLinks();
9393
});
94-
test('deleting sidebar items', async ({ page }, workerInfo) => {
94+
test('deleting range from sidebar items + resetting the query state', async ({ page }, workerInfo) => {
9595
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
9696
await hp.openPage({});
9797
await hp.didMakeNthQuery({ nth: 0, query: { term: '' } });
@@ -111,6 +111,28 @@ test.describe('history', () => {
111111
await hp.deletesHistoryForYesterday({ action: 'none' });
112112
await hp.sidebarHasItem('Show history for today');
113113
});
114+
test(
115+
'presses delete on range, but dismisses the modal',
116+
{
117+
annotation: {
118+
type: 'issue',
119+
description: 'https://app.asana.com/0/1201141132935289/1209501378934498',
120+
},
121+
},
122+
async ({ page }, workerInfo) => {
123+
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
124+
await hp.openPage({});
125+
126+
// simulate a modal appearing, but the user dismissing it
127+
await hp.deletesHistoryForYesterday({ action: 'none' });
128+
129+
// this timeout is needed to simulate the bug - a small delay after closing the modal
130+
await page.waitForTimeout(100);
131+
132+
// now check only the first query occurred (on page load)
133+
await hp.didMakeNQueries(1);
134+
},
135+
);
114136
test('deleting from the header', async ({ page }, workerInfo) => {
115137
const hp = HistoryTestPage.create(page, workerInfo).withEntries(2000);
116138
await hp.openPage({});

0 commit comments

Comments
 (0)