You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					54 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					54 lines
				
				1.2 KiB
			| 
											3 years ago
										 | "use strict"; | ||
|  | 
 | ||
|  | Object.defineProperty(exports, "__esModule", { | ||
|  |   value: true | ||
|  | }); | ||
|  | exports.buildActionClickHandler = void 0; | ||
|  | 
 | ||
|  | var _actionHasComponent = require("./action-has-component"); | ||
|  | 
 | ||
|  | var _actionHref = require("./action-href"); | ||
|  | 
 | ||
|  | var _buildActionApiCallTrigger = require("./build-action-api-call-trigger"); | ||
|  | 
 | ||
|  | /* eslint-disable no-restricted-globals */ | ||
|  | 
 | ||
|  | /* eslint-disable no-undef */ | ||
|  | 
 | ||
|  | /* eslint-disable no-alert */ | ||
|  | const buildActionClickHandler = options => { | ||
|  |   const { | ||
|  |     action, | ||
|  |     params, | ||
|  |     actionResponseHandler, | ||
|  |     navigate | ||
|  |   } = options; | ||
|  | 
 | ||
|  |   const handleActionClick = event => { | ||
|  |     event.preventDefault(); | ||
|  |     event.stopPropagation(); | ||
|  |     const href = (0, _actionHref.actionHref)(action, params); | ||
|  |     const callApi = (0, _buildActionApiCallTrigger.buildActionCallApiTrigger)({ | ||
|  |       params, | ||
|  |       action, | ||
|  |       actionResponseHandler | ||
|  |     }); | ||
|  | 
 | ||
|  |     if (action.guard && !confirm(action.guard)) { | ||
|  |       return; | ||
|  |     } | ||
|  | 
 | ||
|  |     if ((0, _actionHasComponent.actionHasComponent)(action)) { | ||
|  |       // eslint-disable-next-line consistent-return
 | ||
|  |       return callApi(); | ||
|  |     } | ||
|  | 
 | ||
|  |     if (href) { | ||
|  |       navigate(href); | ||
|  |     } | ||
|  |   }; | ||
|  | 
 | ||
|  |   return handleActionClick; | ||
|  | }; | ||
|  | 
 | ||
|  | exports.buildActionClickHandler = buildActionClickHandler; |