| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  | import React from 'react'; | 
					
						
							| 
									
										
										
										
											2020-03-26 18:50:27 +08:00
										 |  |  | import { Button, ButtonVariant, ModalsController, FullWidthButtonContainer } from '@grafana/ui'; | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  | import { DashboardModel } from 'app/features/dashboard/state'; | 
					
						
							|  |  |  | import { connectWithProvider } from 'app/core/utils/connectWithReduxStore'; | 
					
						
							|  |  |  | import { provideModalsContext } from 'app/routes/ReactContainer'; | 
					
						
							|  |  |  | import { SaveDashboardAsModal } from './SaveDashboardAsModal'; | 
					
						
							|  |  |  | import { SaveDashboardModalProxy } from './SaveDashboardModalProxy'; | 
					
						
							| 
									
										
										
										
											2020-12-02 21:08:35 +08:00
										 |  |  | import { selectors } from '@grafana/e2e-selectors'; | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | interface SaveDashboardButtonProps { | 
					
						
							|  |  |  |   dashboard: DashboardModel; | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Added for being able to render this component as Angular directive! | 
					
						
							|  |  |  |    * TODO[angular-migrations]: Remove when we migrate Dashboard Settings view to React | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   getDashboard?: () => DashboardModel; | 
					
						
							|  |  |  |   onSaveSuccess?: () => void; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-27 14:07:56 +08:00
										 |  |  | export const SaveDashboardButton: React.FC<SaveDashboardButtonProps> = ({ dashboard, onSaveSuccess, getDashboard }) => { | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  |   return ( | 
					
						
							|  |  |  |     <ModalsController> | 
					
						
							|  |  |  |       {({ showModal, hideModal }) => { | 
					
						
							|  |  |  |         return ( | 
					
						
							| 
									
										
										
										
											2020-03-26 18:50:27 +08:00
										 |  |  |           <Button | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  |             onClick={() => { | 
					
						
							|  |  |  |               showModal(SaveDashboardModalProxy, { | 
					
						
							|  |  |  |                 // TODO[angular-migrations]: Remove tenary op when we migrate Dashboard Settings view to React
 | 
					
						
							|  |  |  |                 dashboard: getDashboard ? getDashboard() : dashboard, | 
					
						
							|  |  |  |                 onSaveSuccess, | 
					
						
							|  |  |  |                 onDismiss: hideModal, | 
					
						
							|  |  |  |               }); | 
					
						
							|  |  |  |             }} | 
					
						
							| 
									
										
										
										
											2020-12-02 21:08:35 +08:00
										 |  |  |             aria-label={selectors.pages.Dashboard.Settings.General.saveDashBoard} | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  |           > | 
					
						
							|  |  |  |             Save dashboard | 
					
						
							| 
									
										
										
										
											2020-03-26 18:50:27 +08:00
										 |  |  |           </Button> | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  |         ); | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |     </ModalsController> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 18:50:27 +08:00
										 |  |  | export const SaveDashboardAsButton: React.FC<SaveDashboardButtonProps & { variant?: ButtonVariant }> = ({ | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  |   dashboard, | 
					
						
							|  |  |  |   onSaveSuccess, | 
					
						
							|  |  |  |   getDashboard, | 
					
						
							|  |  |  |   variant, | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <ModalsController> | 
					
						
							|  |  |  |       {({ showModal, hideModal }) => { | 
					
						
							|  |  |  |         return ( | 
					
						
							| 
									
										
										
										
											2020-03-26 18:50:27 +08:00
										 |  |  |           <FullWidthButtonContainer> | 
					
						
							|  |  |  |             <Button | 
					
						
							|  |  |  |               onClick={() => { | 
					
						
							|  |  |  |                 showModal(SaveDashboardAsModal, { | 
					
						
							|  |  |  |                   // TODO[angular-migrations]: Remove tenary op when we migrate Dashboard Settings view to React
 | 
					
						
							|  |  |  |                   dashboard: getDashboard ? getDashboard() : dashboard, | 
					
						
							|  |  |  |                   onSaveSuccess, | 
					
						
							|  |  |  |                   onDismiss: hideModal, | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |               }} | 
					
						
							|  |  |  |               // TODO[angular-migrations]: Hacking the different variants for this single button
 | 
					
						
							|  |  |  |               // In Dashboard Settings in sidebar we need to use new form but with inverse variant to make it look like it should
 | 
					
						
							|  |  |  |               // Everywhere else we use old button component :(
 | 
					
						
							|  |  |  |               variant={variant as ButtonVariant} | 
					
						
							| 
									
										
										
										
											2020-12-02 21:08:35 +08:00
										 |  |  |               aria-label={selectors.pages.Dashboard.Settings.General.saveAsDashBoard} | 
					
						
							| 
									
										
										
										
											2020-03-26 18:50:27 +08:00
										 |  |  |             > | 
					
						
							|  |  |  |               Save As... | 
					
						
							|  |  |  |             </Button> | 
					
						
							|  |  |  |           </FullWidthButtonContainer> | 
					
						
							| 
									
										
										
										
											2020-03-03 15:22:26 +08:00
										 |  |  |         ); | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |     </ModalsController> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // TODO: this is an ugly solution for the save button to have access to Redux and Modals controller
 | 
					
						
							|  |  |  | // When we migrate dashboard settings to Angular it won't be necessary.
 | 
					
						
							|  |  |  | export const SaveDashboardButtonConnected = connectWithProvider(provideModalsContext(SaveDashboardButton)); | 
					
						
							|  |  |  | export const SaveDashboardAsButtonConnected = connectWithProvider(provideModalsContext(SaveDashboardAsButton)); |