@@ -22,12 +22,12 @@ export { DashboardStatusEnum } from "./useEditModeHandler";
2222
2323function getAffectedWidgets ( widgets , updatedParameters = [ ] ) {
2424 return ! isEmpty ( updatedParameters )
25- ? widgets . filter ( widget =>
25+ ? widgets . filter ( ( widget ) =>
2626 Object . values ( widget . getParameterMappings ( ) )
2727 . filter ( ( { type } ) => type === "dashboard-level" )
2828 . some ( ( { mapTo } ) =>
2929 includes (
30- updatedParameters . map ( p => p . name ) ,
30+ updatedParameters . map ( ( p ) => p . name ) ,
3131 mapTo
3232 )
3333 )
@@ -50,7 +50,7 @@ function useDashboard(dashboardData) {
5050 [ dashboard ]
5151 ) ;
5252 const hasOnlySafeQueries = useMemo (
53- ( ) => every ( dashboard . widgets , w => ( w . getQuery ( ) ? w . getQuery ( ) . is_safe : true ) ) ,
53+ ( ) => every ( dashboard . widgets , ( w ) => ( w . getQuery ( ) ? w . getQuery ( ) . is_safe : true ) ) ,
5454 [ dashboard ]
5555 ) ;
5656
@@ -67,19 +67,19 @@ function useDashboard(dashboardData) {
6767
6868 const updateDashboard = useCallback (
6969 ( data , includeVersion = true ) => {
70- setDashboard ( currentDashboard => extend ( { } , currentDashboard , data ) ) ;
70+ setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard , data ) ) ;
7171 data = { ...data , id : dashboard . id } ;
7272 if ( includeVersion ) {
7373 data = { ...data , version : dashboard . version } ;
7474 }
7575 return Dashboard . save ( data )
76- . then ( updatedDashboard => {
77- setDashboard ( currentDashboard => extend ( { } , currentDashboard , pick ( updatedDashboard , keys ( data ) ) ) ) ;
76+ . then ( ( updatedDashboard ) => {
77+ setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard , pick ( updatedDashboard , keys ( data ) ) ) ) ;
7878 if ( has ( data , "name" ) ) {
7979 location . setPath ( url . parse ( updatedDashboard . url ) . pathname , true ) ;
8080 }
8181 } )
82- . catch ( error => {
82+ . catch ( ( error ) => {
8383 const status = get ( error , "response.status" ) ;
8484 if ( status === 403 ) {
8585 notification . error ( "Dashboard update failed" , "Permission Denied." ) ;
@@ -102,25 +102,25 @@ function useDashboard(dashboardData) {
102102
103103 const loadWidget = useCallback ( ( widget , forceRefresh = false ) => {
104104 widget . getParametersDefs ( ) ; // Force widget to read parameters values from URL
105- setDashboard ( currentDashboard => extend ( { } , currentDashboard ) ) ;
105+ setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard ) ) ;
106106 return widget
107107 . load ( forceRefresh )
108- . catch ( error => {
108+ . catch ( ( error ) => {
109109 // QueryResultErrors are expected
110110 if ( error instanceof QueryResultError ) {
111111 return ;
112112 }
113113 return Promise . reject ( error ) ;
114114 } )
115- . finally ( ( ) => setDashboard ( currentDashboard => extend ( { } , currentDashboard ) ) ) ;
115+ . finally ( ( ) => setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard ) ) ) ;
116116 } , [ ] ) ;
117117
118- const refreshWidget = useCallback ( widget => loadWidget ( widget , true ) , [ loadWidget ] ) ;
118+ const refreshWidget = useCallback ( ( widget ) => loadWidget ( widget , true ) , [ loadWidget ] ) ;
119119
120- const removeWidget = useCallback ( widgetId => {
121- setDashboard ( currentDashboard =>
120+ const removeWidget = useCallback ( ( widgetId ) => {
121+ setDashboard ( ( currentDashboard ) =>
122122 extend ( { } , currentDashboard , {
123- widgets : currentDashboard . widgets . filter ( widget => widget . id !== undefined && widget . id !== widgetId ) ,
123+ widgets : currentDashboard . widgets . filter ( ( widget ) => widget . id !== undefined && widget . id !== widgetId ) ,
124124 } )
125125 ) ;
126126 } , [ ] ) ;
@@ -132,11 +132,11 @@ function useDashboard(dashboardData) {
132132 ( forceRefresh = false , updatedParameters = [ ] ) => {
133133 const affectedWidgets = getAffectedWidgets ( dashboardRef . current . widgets , updatedParameters ) ;
134134 const loadWidgetPromises = compact (
135- affectedWidgets . map ( widget => loadWidget ( widget , forceRefresh ) . catch ( error => error ) )
135+ affectedWidgets . map ( ( widget ) => loadWidget ( widget , forceRefresh ) . catch ( ( error ) => error ) )
136136 ) ;
137137
138138 return Promise . all ( loadWidgetPromises ) . then ( ( ) => {
139- const queryResults = compact ( map ( dashboardRef . current . widgets , widget => widget . getQueryResult ( ) ) ) ;
139+ const queryResults = compact ( map ( dashboardRef . current . widgets , ( widget ) => widget . getQueryResult ( ) ) ) ;
140140 const updatedFilters = collectDashboardFilters ( dashboardRef . current , queryResults , location . search ) ;
141141 setFilters ( updatedFilters ) ;
142142 } ) ;
@@ -145,7 +145,7 @@ function useDashboard(dashboardData) {
145145 ) ;
146146
147147 const refreshDashboard = useCallback (
148- updatedParameters => {
148+ ( updatedParameters ) => {
149149 if ( ! refreshing ) {
150150 setRefreshing ( true ) ;
151151 loadDashboard ( true , updatedParameters ) . finally ( ( ) => setRefreshing ( false ) ) ;
@@ -154,15 +154,30 @@ function useDashboard(dashboardData) {
154154 [ refreshing , loadDashboard ]
155155 ) ;
156156
157+ const saveDashboardParameters = useCallback ( ( ) => {
158+ const currentDashboard = dashboardRef . current ;
159+
160+ return updateDashboard ( {
161+ options : {
162+ ...currentDashboard . options ,
163+ parameters : map ( globalParameters , ( p ) => p . toSaveableObject ( ) ) ,
164+ } ,
165+ } ) . catch ( ( error ) => {
166+ console . error ( "Failed to persist parameter values:" , error ) ;
167+ notification . error ( "Parameter values could not be saved. Your changes may not be persisted." ) ;
168+ throw error ;
169+ } ) ;
170+ } , [ globalParameters , updateDashboard ] ) ;
171+
157172 const archiveDashboard = useCallback ( ( ) => {
158173 recordEvent ( "archive" , "dashboard" , dashboard . id ) ;
159- Dashboard . delete ( dashboard ) . then ( updatedDashboard =>
160- setDashboard ( currentDashboard => extend ( { } , currentDashboard , pick ( updatedDashboard , [ "is_archived" ] ) ) )
174+ Dashboard . delete ( dashboard ) . then ( ( updatedDashboard ) =>
175+ setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard , pick ( updatedDashboard , [ "is_archived" ] ) ) )
161176 ) ;
162177 } , [ dashboard ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
163178
164179 const showShareDashboardDialog = useCallback ( ( ) => {
165- const handleDialogClose = ( ) => setDashboard ( currentDashboard => extend ( { } , currentDashboard ) ) ;
180+ const handleDialogClose = ( ) => setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard ) ) ;
166181
167182 ShareDashboardDialog . showModal ( {
168183 dashboard,
@@ -175,8 +190,8 @@ function useDashboard(dashboardData) {
175190 const showAddTextboxDialog = useCallback ( ( ) => {
176191 TextboxDialog . showModal ( {
177192 isNew : true ,
178- } ) . onClose ( text =>
179- dashboard . addWidget ( text ) . then ( ( ) => setDashboard ( currentDashboard => extend ( { } , currentDashboard ) ) )
193+ } ) . onClose ( ( text ) =>
194+ dashboard . addWidget ( text ) . then ( ( ) => setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard ) ) )
180195 ) ;
181196 } , [ dashboard ] ) ;
182197
@@ -188,13 +203,13 @@ function useDashboard(dashboardData) {
188203 . addWidget ( visualization , {
189204 parameterMappings : editableMappingsToParameterMappings ( parameterMappings ) ,
190205 } )
191- . then ( widget => {
206+ . then ( ( widget ) => {
192207 const widgetsToSave = [
193208 widget ,
194209 ...synchronizeWidgetTitles ( widget . options . parameterMappings , dashboard . widgets ) ,
195210 ] ;
196- return Promise . all ( widgetsToSave . map ( w => w . save ( ) ) ) . then ( ( ) =>
197- setDashboard ( currentDashboard => extend ( { } , currentDashboard ) )
211+ return Promise . all ( widgetsToSave . map ( ( w ) => w . save ( ) ) ) . then ( ( ) =>
212+ setDashboard ( ( currentDashboard ) => extend ( { } , currentDashboard ) )
198213 ) ;
199214 } )
200215 ) ;
@@ -238,6 +253,7 @@ function useDashboard(dashboardData) {
238253 setRefreshRate,
239254 disableRefreshRate,
240255 ...editModeHandler ,
256+ saveDashboardParameters,
241257 gridDisabled,
242258 setGridDisabled,
243259 fullscreen,
0 commit comments