Skip to content

fix(feedback): Update the feedback list when an item becomes read/unread #91596

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 13 additions & 9 deletions static/app/components/feedback/useFeedbackCache.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useCallback} from 'react';
import {useCallback, useMemo} from 'react';

import type {ApiResult} from 'sentry/api';
import useFeedbackQueryKeys from 'sentry/components/feedback/useFeedbackQueryKeys';
Expand All @@ -23,6 +23,10 @@ function isIssueEndpointUrl(query: any) {
export default function useFeedbackCache() {
const queryClient = useQueryClient();
const {getItemQueryKeys, listQueryKey} = useFeedbackQueryKeys();
const infiniteListQueryKey = useMemo(
() => (listQueryKey ? [...listQueryKey, 'infinite'] : undefined),
[listQueryKey]
);

const updateCachedQueryKey = useCallback(
(queryKey: ApiQueryKey, payload: Partial<FeedbackIssue>) => {
Expand Down Expand Up @@ -53,10 +57,10 @@ export default function useFeedbackCache() {

const updateCachedListPage = useCallback(
(ids: TFeedbackIds, payload: Partial<FeedbackIssue>) => {
if (!listQueryKey) {
if (!infiniteListQueryKey) {
return;
}
const listData = queryClient.getQueryData<ListCache>(listQueryKey);
const listData = queryClient.getQueryData<ListCache>(infiniteListQueryKey);
if (listData) {
const pages = listData.pages.map(([data, statusText, resp]) => [
data.map(item =>
Expand All @@ -65,10 +69,10 @@ export default function useFeedbackCache() {
statusText,
resp,
]);
queryClient.setQueryData(listQueryKey, {...listData, pages});
queryClient.setQueryData(infiniteListQueryKey, {...listData, pages});
}
},
[listQueryKey, queryClient]
[infiniteListQueryKey, queryClient]
);

const updateCached = useCallback(
Expand Down Expand Up @@ -96,17 +100,17 @@ export default function useFeedbackCache() {

const invalidateCachedListPage = useCallback(
(ids: TFeedbackIds) => {
if (!listQueryKey) {
if (!infiniteListQueryKey) {
return;
}
if (ids === 'all') {
queryClient.invalidateQueries({
queryKey: listQueryKey,
queryKey: infiniteListQueryKey,
type: 'all',
});
} else {
queryClient.refetchQueries({
queryKey: listQueryKey,
queryKey: infiniteListQueryKey,
predicate: query => {
// Check if any of the pages contain the items we want to invalidate
return Boolean(
Expand All @@ -118,7 +122,7 @@ export default function useFeedbackCache() {
});
}
},
[listQueryKey, queryClient]
[infiniteListQueryKey, queryClient]
);

const invalidateCached = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/feedback/useFetchFeedbackData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function useFetchFeedbackData({feedbackId}: Props) {
if (issueResult.isFetched && issueData && !issueData.hasSeen) {
markAsRead(true);
}
}, [issueResult.isFetched]); // eslint-disable-line react-hooks/exhaustive-deps
}, [issueData, issueResult.isFetched, markAsRead]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed wrong before. Because we were just looking at isFetched i think if you toggled back and forth between two unread feedbacks (so both are in cache), then we wouldn't re-run the useEffect when the visible feedback changed. We want to re-run it in case something else has flipped the hasSeen bit and we want to reset it.


return {
eventData,
Expand Down
Loading