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..078e89d96d 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..5968d20011 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..d2177cde2a 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(() => {