From 97231f55816098607dd5d68823bf830568839bee Mon Sep 17 00:00:00 2001 From: rodion Date: Thu, 21 Oct 2021 21:39:47 +0300 Subject: [PATCH 1/2] fix: sentry plugin allows search query parameter specified by documentation https://docs.sentry.io/api/events/list-a-projects-issues/ Signed-off-by: rodion --- .changeset/cold-wolves-eat.md | 5 +++++ plugins/sentry/api-report.md | 14 ++++++++++++-- plugins/sentry/src/api/production-api.ts | 10 ++++++++-- plugins/sentry/src/api/sentry-api.ts | 6 +++++- .../SentryIssuesWidget/SentryIssuesWidget.tsx | 6 ++++-- 5 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 .changeset/cold-wolves-eat.md diff --git a/.changeset/cold-wolves-eat.md b/.changeset/cold-wolves-eat.md new file mode 100644 index 0000000000..fa3a2180b2 --- /dev/null +++ b/.changeset/cold-wolves-eat.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-sentry': patch +--- + +feature: sentry-plugin allows passing search query for listing issues diff --git a/plugins/sentry/api-report.md b/plugins/sentry/api-report.md index 7143272284..89c1dd1bca 100644 --- a/plugins/sentry/api-report.md +++ b/plugins/sentry/api-report.md @@ -36,7 +36,11 @@ export class MockSentryApi implements SentryApi { export class ProductionSentryApi implements SentryApi { constructor(discoveryApi: DiscoveryApi, organization: string); // (undocumented) - fetchIssues(project: string, statsFor: string): Promise; + fetchIssues( + project: string, + statsFor: string, + query: string, + ): Promise; } // Warning: (ae-missing-release-tag) "Router" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -49,7 +53,11 @@ export const Router: ({ entity }: { entity: Entity }) => JSX.Element; // @public (undocumented) export interface SentryApi { // (undocumented) - fetchIssues(project: string, statsFor: string): Promise; + fetchIssues( + project: string, + statsFor: string, + query: string, + ): Promise; } // Warning: (ae-missing-release-tag) "sentryApiRef" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -100,10 +108,12 @@ export const SentryIssuesWidget: ({ entity, statsFor, variant, + query, }: { entity: Entity; statsFor?: '12h' | '24h' | undefined; variant?: InfoCardVariants | undefined; + query?: string | undefined; }) => JSX.Element; // Warning: (ae-missing-release-tag) "sentryPlugin" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) diff --git a/plugins/sentry/src/api/production-api.ts b/plugins/sentry/src/api/production-api.ts index e634650f96..d9ece065d3 100644 --- a/plugins/sentry/src/api/production-api.ts +++ b/plugins/sentry/src/api/production-api.ts @@ -24,15 +24,21 @@ export class ProductionSentryApi implements SentryApi { private readonly organization: string, ) {} - async fetchIssues(project: string, statsFor: string): Promise { + async fetchIssues( + project: string, + statsFor: string, + query: string, + ): Promise { if (!project) { return []; } const apiUrl = `${await this.discoveryApi.getBaseUrl('proxy')}/sentry/api`; + const queryPart = query ? `&query=${query}` : ''; + const response = await fetch( - `${apiUrl}/0/projects/${this.organization}/${project}/issues/?statsPeriod=${statsFor}`, + `${apiUrl}/0/projects/${this.organization}/${project}/issues/?statsPeriod=${statsFor}${queryPart}`, ); if (response.status >= 400 && response.status < 600) { diff --git a/plugins/sentry/src/api/sentry-api.ts b/plugins/sentry/src/api/sentry-api.ts index a755ca0941..5c0fb318a6 100644 --- a/plugins/sentry/src/api/sentry-api.ts +++ b/plugins/sentry/src/api/sentry-api.ts @@ -23,5 +23,9 @@ export const sentryApiRef = createApiRef({ }); export interface SentryApi { - fetchIssues(project: string, statsFor: string): Promise; + fetchIssues( + project: string, + statsFor: string, + query: string, + ): Promise; } diff --git a/plugins/sentry/src/components/SentryIssuesWidget/SentryIssuesWidget.tsx b/plugins/sentry/src/components/SentryIssuesWidget/SentryIssuesWidget.tsx index 46198e4b93..349ce61128 100644 --- a/plugins/sentry/src/components/SentryIssuesWidget/SentryIssuesWidget.tsx +++ b/plugins/sentry/src/components/SentryIssuesWidget/SentryIssuesWidget.tsx @@ -38,10 +38,12 @@ export const SentryIssuesWidget = ({ entity, statsFor = '24h', variant = 'gridItem', + query = '', }: { entity: Entity; statsFor?: '24h' | '12h'; variant?: InfoCardVariants; + query?: string; }) => { const errorApi = useApi(errorApiRef); const sentryApi = useApi(sentryApiRef); @@ -49,8 +51,8 @@ export const SentryIssuesWidget = ({ const projectId = useProjectSlug(entity); const { loading, value, error } = useAsync( - () => sentryApi.fetchIssues(projectId, statsFor), - [sentryApi, statsFor, projectId], + () => sentryApi.fetchIssues(projectId, statsFor, query), + [sentryApi, statsFor, projectId, query], ); useEffect(() => { From 43b77e1e5e855335da997f74562c9fd13b924697 Mon Sep 17 00:00:00 2001 From: rodion Date: Mon, 25 Oct 2021 15:05:07 +0300 Subject: [PATCH 2/2] fix: sentry-plugin query parameter is optional Signed-off-by: rodion --- plugins/sentry/api-report.md | 4 ++-- plugins/sentry/src/api/production-api.ts | 2 +- plugins/sentry/src/api/sentry-api.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/sentry/api-report.md b/plugins/sentry/api-report.md index 89c1dd1bca..078e89d96d 100644 --- a/plugins/sentry/api-report.md +++ b/plugins/sentry/api-report.md @@ -39,7 +39,7 @@ export class ProductionSentryApi implements SentryApi { fetchIssues( project: string, statsFor: string, - query: string, + query?: string, ): Promise; } @@ -56,7 +56,7 @@ export interface SentryApi { fetchIssues( project: string, statsFor: string, - query: string, + query?: string, ): Promise; } diff --git a/plugins/sentry/src/api/production-api.ts b/plugins/sentry/src/api/production-api.ts index d9ece065d3..5968d20011 100644 --- a/plugins/sentry/src/api/production-api.ts +++ b/plugins/sentry/src/api/production-api.ts @@ -27,7 +27,7 @@ export class ProductionSentryApi implements SentryApi { async fetchIssues( project: string, statsFor: string, - query: string, + query?: string, ): Promise { if (!project) { return []; diff --git a/plugins/sentry/src/api/sentry-api.ts b/plugins/sentry/src/api/sentry-api.ts index 5c0fb318a6..d2177cde2a 100644 --- a/plugins/sentry/src/api/sentry-api.ts +++ b/plugins/sentry/src/api/sentry-api.ts @@ -26,6 +26,6 @@ export interface SentryApi { fetchIssues( project: string, statsFor: string, - query: string, + query?: string, ): Promise; }