@@ -2,23 +2,19 @@ import {Fragment, useEffect, useRef, useState} from 'react';
2
2
import { useTheme } from '@emotion/react' ;
3
3
import styled from '@emotion/styled' ;
4
4
import isEqual from 'lodash/isEqual' ;
5
- import pick from 'lodash/pick' ;
6
5
7
6
import { Breadcrumbs } from 'sentry/components/breadcrumbs' ;
8
7
import { openConfirmModal } from 'sentry/components/confirm' ;
9
8
import { Button } from 'sentry/components/core/button' ;
10
9
import ErrorBoundary from 'sentry/components/errorBoundary' ;
11
10
import SlideOverPanel from 'sentry/components/slideOverPanel' ;
12
- import { URL_PARAM } from 'sentry/constants/pageFilters' ;
13
11
import { IconClose } from 'sentry/icons' ;
14
12
import { t } from 'sentry/locale' ;
15
13
import { space } from 'sentry/styles/space' ;
16
14
import { trackAnalytics } from 'sentry/utils/analytics' ;
17
15
import { WidgetBuilderVersion } from 'sentry/utils/analytics/dashboardsAnalyticsEvents' ;
18
16
import type { TableDataWithTitle } from 'sentry/utils/discover/discoverQuery' ;
19
- import { useLocation } from 'sentry/utils/useLocation' ;
20
17
import useMedia from 'sentry/utils/useMedia' ;
21
- import { useNavigate } from 'sentry/utils/useNavigate' ;
22
18
import useOrganization from 'sentry/utils/useOrganization' ;
23
19
import { useValidateWidgetQuery } from 'sentry/views/dashboards/hooks/useValidateWidget' ;
24
20
import {
@@ -47,6 +43,8 @@ import {useWidgetBuilderContext} from 'sentry/views/dashboards/widgetBuilder/con
47
43
import useDashboardWidgetSource from 'sentry/views/dashboards/widgetBuilder/hooks/useDashboardWidgetSource' ;
48
44
import useIsEditingWidget from 'sentry/views/dashboards/widgetBuilder/hooks/useIsEditingWidget' ;
49
45
import { convertBuilderStateToWidget } from 'sentry/views/dashboards/widgetBuilder/utils/convertBuilderStateToWidget' ;
46
+ import { convertWidgetToBuilderStateParams } from 'sentry/views/dashboards/widgetBuilder/utils/convertWidgetToBuilderStateParams' ;
47
+ import { getTopNConvertedDefaultWidgets } from 'sentry/views/dashboards/widgetLibrary/data' ;
50
48
51
49
type WidgetBuilderSlideoutProps = {
52
50
dashboard : DashboardDetails ;
@@ -78,15 +76,13 @@ function WidgetBuilderSlideout({
78
76
thresholdMetaState,
79
77
} : WidgetBuilderSlideoutProps ) {
80
78
const organization = useOrganization ( ) ;
81
- const { state} = useWidgetBuilderContext ( ) ;
79
+ const { state, dispatch } = useWidgetBuilderContext ( ) ;
82
80
const [ initialState ] = useState ( state ) ;
83
81
const [ customizeFromLibrary , setCustomizeFromLibrary ] = useState ( false ) ;
84
82
const [ error , setError ] = useState < Record < string , any > > ( { } ) ;
85
83
const theme = useTheme ( ) ;
86
84
const isEditing = useIsEditingWidget ( ) ;
87
85
const source = useDashboardWidgetSource ( ) ;
88
- const navigate = useNavigate ( ) ;
89
- const location = useLocation ( ) ;
90
86
const validatedWidgetResponse = useValidateWidgetQuery (
91
87
convertBuilderStateToWidget ( state )
92
88
) ;
@@ -144,21 +140,20 @@ function WidgetBuilderSlideout({
144
140
return ( ) => observer . disconnect ( ) ;
145
141
} , [ setIsPreviewDraggable , openWidgetTemplates ] ) ;
146
142
143
+ const widgetLibraryWidgets = getTopNConvertedDefaultWidgets ( organization ) ;
144
+
147
145
const widgetLibraryElement = (
148
146
< SlideoutBreadcrumb
149
147
onClick = { ( ) => {
150
148
setCustomizeFromLibrary ( false ) ;
151
149
setOpenWidgetTemplates ( true ) ;
152
150
// clears the widget to start fresh on the library page
153
- navigate (
154
- {
155
- pathname : location . pathname ,
156
- query : {
157
- ...pick ( location . query , [ ...Object . values ( URL_PARAM ) ] ) ,
158
- } ,
159
- } ,
160
- { preventScrollReset : true }
161
- ) ;
151
+ dispatch ( {
152
+ type : 'SET_STATE' ,
153
+ payload : convertWidgetToBuilderStateParams (
154
+ widgetLibraryWidgets [ 0 ] ?? ( { } as Widget )
155
+ ) ,
156
+ } ) ;
162
157
} }
163
158
>
164
159
{ t ( 'Widget Library' ) }
0 commit comments