Skip to content

Commit 30b4630

Browse files
feat(feedback): frontend for categories (#97402)
1 parent e3849c5 commit 30b4630

File tree

6 files changed

+739
-46
lines changed

6 files changed

+739
-46
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
2+
import {useApiQuery} from 'sentry/utils/queryClient';
3+
import useOrganization from 'sentry/utils/useOrganization';
4+
import usePageFilters from 'sentry/utils/usePageFilters';
5+
6+
type FeedbackCategory = {
7+
associatedLabels: string[];
8+
feedbackCount: number;
9+
primaryLabel: string;
10+
};
11+
12+
type FeedbackCategoriesResponse = {
13+
categories: FeedbackCategory[] | null;
14+
numFeedbacksContext: number;
15+
success: boolean;
16+
};
17+
18+
export default function useFeedbackCategories(): {
19+
categories: FeedbackCategory[] | null;
20+
isError: boolean;
21+
isPending: boolean;
22+
tooFewFeedbacks: boolean;
23+
} {
24+
const organization = useOrganization();
25+
26+
const {selection} = usePageFilters();
27+
28+
const normalizedDateRange = normalizeDateTimeParams(selection.datetime);
29+
30+
const {data, isPending, isError} = useApiQuery<FeedbackCategoriesResponse>(
31+
[
32+
`/organizations/${organization.slug}/feedback-categories/`,
33+
{
34+
query: {
35+
...normalizedDateRange,
36+
project: selection.projects,
37+
},
38+
},
39+
],
40+
{
41+
staleTime: 5000,
42+
retry: 1,
43+
}
44+
);
45+
46+
if (isPending) {
47+
return {
48+
categories: null,
49+
isPending: true,
50+
isError: false,
51+
tooFewFeedbacks: false,
52+
};
53+
}
54+
55+
if (isError) {
56+
return {
57+
categories: null,
58+
isPending: false,
59+
isError: true,
60+
tooFewFeedbacks: false,
61+
};
62+
}
63+
64+
return {
65+
categories: data.categories,
66+
isPending: false,
67+
isError: false,
68+
tooFewFeedbacks: data.numFeedbacksContext === 0 && !data.success,
69+
};
70+
}

0 commit comments

Comments
 (0)