1- import { useMemo } from 'react' ;
1+ import { useCallback } from 'react' ;
22
3- import { useCommandPaletteQueryState } from 'sentry/components/commandPalette/context ' ;
3+ import { makeCommandPaletteLink } from 'sentry/components/commandPalette/makeCommandPaletteAction ' ;
44import type { CommandPaletteAction } from 'sentry/components/commandPalette/types' ;
5- import { useCommandPaletteActions } from 'sentry/components/commandPalette/useCommandPaletteActions ' ;
5+ import { useDynamicCommandPaletteAction } from 'sentry/components/commandPalette/useDynamicCommandPaletteAction ' ;
66import {
77 DSN_PATTERN ,
88 getDsnNavTargets ,
99} from 'sentry/components/search/sources/dsnLookupUtils' ;
1010import type { DsnLookupResponse } from 'sentry/components/search/sources/dsnLookupUtils' ;
1111import { IconIssues , IconList , IconSettings } from 'sentry/icons' ;
1212import { getApiUrl } from 'sentry/utils/api/getApiUrl' ;
13- import { useApiQuery } from 'sentry/utils/queryClient ' ;
13+ import { useApi } from 'sentry/utils/useApi ' ;
1414import { useOrganization } from 'sentry/utils/useOrganization' ;
1515
1616const ICONS : React . ReactElement [ ] = [
@@ -20,40 +20,36 @@ const ICONS: React.ReactElement[] = [
2020] ;
2121
2222export function useDsnLookupActions ( ) : void {
23- const { query } = useCommandPaletteQueryState ( ) ;
23+ const api = useApi ( ) ;
2424 const organization = useOrganization ( { allowNull : true } ) ;
2525 const hasDsnLookup = organization ?. features ?. includes ( 'cmd-k-dsn-lookup' ) ?? false ;
26- const isDsn = DSN_PATTERN . test ( query ) ;
27-
28- const { data} = useApiQuery < DsnLookupResponse > (
29- [
30- getApiUrl ( '/organizations/$organizationIdOrSlug/dsn-lookup/' , {
31- path : { organizationIdOrSlug : organization ?. slug ?? '' } ,
32- } ) ,
33- { query : { dsn : query } } ,
34- ] ,
35- {
36- staleTime : 30_000 ,
37- enabled : isDsn && ! ! organization && hasDsnLookup ,
38- }
26+
27+ const queryAction = useCallback (
28+ async ( query : string ) : Promise < CommandPaletteAction [ ] > => {
29+ if ( ! DSN_PATTERN . test ( query ) || ! organization || ! hasDsnLookup ) {
30+ return [ ] ;
31+ }
32+
33+ const url = getApiUrl ( '/organizations/$organizationIdOrSlug/dsn-lookup/' , {
34+ path : { organizationIdOrSlug : organization . slug } ,
35+ } ) ;
36+
37+ const data = await api . requestPromise ( url , { query : { dsn : query } } ) ;
38+
39+ return getDsnNavTargets ( data as DsnLookupResponse ) . map ( ( target , i ) =>
40+ makeCommandPaletteLink ( {
41+ display : {
42+ label : target . label ,
43+ details : target . description ,
44+ icon : ICONS [ i ] ,
45+ } ,
46+ groupingKey : 'search-result' ,
47+ to : target . to ,
48+ } )
49+ ) ;
50+ } ,
51+ [ api , organization , hasDsnLookup ]
3952 ) ;
4053
41- const actions : CommandPaletteAction [ ] = useMemo ( ( ) => {
42- if ( ! isDsn || ! data ) {
43- return [ ] ;
44- }
45-
46- return getDsnNavTargets ( data ) . map ( ( target , i ) => ( {
47- type : 'navigate' as const ,
48- to : target . to ,
49- display : {
50- label : target . label ,
51- details : target . description ,
52- icon : ICONS [ i ] ,
53- } ,
54- groupingKey : 'search-result' as const ,
55- } ) ) ;
56- } , [ isDsn , data ] ) ;
57-
58- useCommandPaletteActions ( actions ) ;
54+ useDynamicCommandPaletteAction ( queryAction ) ;
5955}
0 commit comments