Skip to content

Commit 3eb6c49

Browse files
committed
fix emptyspam/emptytrash buttons not clearing up the counts
1 parent 0cf2f16 commit 3eb6c49

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

projects/packages/forms/src/dashboard/components/empty-spam-button/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { store as noticesStore } from '@wordpress/notices';
1515
* Internal dependencies
1616
*/
1717
import useInboxData from '../../hooks/use-inbox-data';
18+
import { store as dashboardStore } from '../../store';
1819

1920
type CoreStore = typeof coreStore & {
2021
invalidateResolution: ( selector: string, args: unknown[] ) => void;
@@ -42,6 +43,7 @@ const EmptySpamButton = ( {
4243
const [ isEmpty, setIsEmpty ] = useState( true );
4344
const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore );
4445
const { invalidateResolution } = useDispatch( coreStore ) as unknown as CoreStore;
46+
const { invalidateCounts } = useDispatch( dashboardStore );
4547

4648
// Use props if provided, otherwise use hook
4749
const hookData = useInboxData();
@@ -103,12 +105,15 @@ const EmptySpamButton = ( {
103105
'feedback',
104106
{ ...currentQuery, per_page: 1, _fields: 'id' },
105107
] );
108+
// invalidate counts to refresh the counts across all status tabs
109+
invalidateCounts();
106110
} );
107111
}, [
108112
closeConfirmDialog,
109113
createErrorNotice,
110114
createSuccessNotice,
111115
invalidateResolution,
116+
invalidateCounts,
112117
isEmpty,
113118
isEmptying,
114119
currentQuery,

projects/packages/forms/src/dashboard/components/empty-trash-button/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { store as noticesStore } from '@wordpress/notices';
1515
* Internal dependencies
1616
*/
1717
import useInboxData from '../../hooks/use-inbox-data';
18+
import { store as dashboardStore } from '../../store';
1819

1920
type CoreStore = typeof coreStore & {
2021
invalidateResolution: ( selector: string, args: unknown[] ) => void;
@@ -42,6 +43,7 @@ const EmptyTrashButton = ( {
4243
const [ isEmpty, setIsEmpty ] = useState( true );
4344
const { createSuccessNotice, createErrorNotice } = useDispatch( noticesStore );
4445
const { invalidateResolution } = useDispatch( coreStore ) as unknown as CoreStore;
46+
const { invalidateCounts } = useDispatch( dashboardStore );
4547

4648
// Use props if provided, otherwise use hook
4749
const hookData = useInboxData();
@@ -103,12 +105,15 @@ const EmptyTrashButton = ( {
103105
'feedback',
104106
{ ...currentQuery, per_page: 1, _fields: 'id' },
105107
] );
108+
// invalidate counts to refresh the counts across all status tabs
109+
invalidateCounts();
106110
} );
107111
}, [
108112
closeConfirmDialog,
109113
createErrorNotice,
110114
createSuccessNotice,
111115
invalidateResolution,
116+
invalidateCounts,
112117
isEmpty,
113118
isEmptying,
114119
currentQuery,

projects/packages/forms/src/dashboard/store/action-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export const SET_CURRENT_QUERY = 'SET_CURRENT_QUERY';
44
export const SET_SELECTED_RESPONSES = 'SET_SELECTED_RESPONSES';
55
export const SET_COUNTS = 'SET_COUNTS';
66
export const UPDATE_COUNTS_OPTIMISTICALLY = 'UPDATE_COUNTS_OPTIMISTICALLY';
7+
export const INVALIDATE_COUNTS = 'INVALIDATE_COUNTS';

projects/packages/forms/src/dashboard/store/actions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
INVALIDATE_FILTERS,
1010
SET_COUNTS,
1111
UPDATE_COUNTS_OPTIMISTICALLY,
12+
INVALIDATE_COUNTS,
1213
} from './action-types';
1314

1415
/**
@@ -30,6 +31,15 @@ export const invalidateFilters = () => {
3031
return { type: INVALIDATE_FILTERS };
3132
};
3233

34+
/**
35+
* Invalidate the counts when responses are deleted.
36+
*
37+
* @return {object} Action object.
38+
*/
39+
export const invalidateCounts = () => {
40+
return { type: INVALIDATE_COUNTS };
41+
};
42+
3343
/**
3444
* Set the selected responses from current data set.
3545
*

projects/packages/forms/src/dashboard/store/resolvers.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import apiFetch from '@wordpress/api-fetch';
22
import { addQueryArgs } from '@wordpress/url';
3-
import { INVALIDATE_FILTERS } from './action-types';
3+
import { INVALIDATE_FILTERS, INVALIDATE_COUNTS } from './action-types';
44

55
export const getFilters =
66
() =>
@@ -39,3 +39,5 @@ export const getCounts =
3939
const response = await apiFetch( { path } );
4040
dispatch.setCounts( response );
4141
};
42+
43+
getCounts.shouldInvalidate = action => action.type === INVALIDATE_COUNTS;

0 commit comments

Comments
 (0)