| 
									
										
										
										
											2019-08-31 20:51:14 -07:00
										 |  |  | import Component from '@ember/component'; | 
					
						
							|  |  |  | import { containerDataSource } from '@datahub/utils/api/data-source'; | 
					
						
							|  |  |  | import { inject as service } from '@ember/service'; | 
					
						
							|  |  |  | import Notifications from '@datahub/utils/services/notifications'; | 
					
						
							|  |  |  | import { NotificationEvent } from '@datahub/utils/constants/notifications'; | 
					
						
							|  |  |  | import { IDatasetView } from 'wherehows-web/typings/api/datasets/dataset'; | 
					
						
							|  |  |  | import { readDatasetSnapshot } from 'wherehows-web/utils/api/datasets/dataset'; | 
					
						
							|  |  |  | import { set } from '@ember/object'; | 
					
						
							|  |  |  | import { IDatasetSnapshot } from '@datahub/metadata-types/types/metadata/dataset-snapshot'; | 
					
						
							|  |  |  | import { tagName } from '@ember-decorators/component'; | 
					
						
							| 
									
										
										
										
											2019-09-04 21:46:02 -07:00
										 |  |  | import { task } from 'ember-concurrency'; | 
					
						
							| 
									
										
										
										
											2019-08-31 20:51:14 -07:00
										 |  |  | import { DatasetPlatform } from '@datahub/metadata-types/constants/entity/dataset/platform'; | 
					
						
							| 
									
										
										
										
											2019-09-04 21:46:02 -07:00
										 |  |  | import { ETaskPromise } from '@datahub/utils/types/concurrency'; | 
					
						
							| 
									
										
										
										
											2019-08-31 20:51:14 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Retrieves snapshot data for a specific ump dataset if the platform meets the condition of being a ump dataset | 
					
						
							|  |  |  |  * @export | 
					
						
							|  |  |  |  * @class DatasetSnapshotContainer | 
					
						
							|  |  |  |  * @extends {Component} | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | @tagName('') | 
					
						
							|  |  |  | @containerDataSource('getContainerDataTask', ['dataset']) | 
					
						
							|  |  |  | export default class DatasetSnapshotContainer extends Component { | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Reference to the application notifications Service | 
					
						
							|  |  |  |    * @type {Notifications} | 
					
						
							|  |  |  |    * @memberof DatasetSnapshotContainer | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   @service | 
					
						
							|  |  |  |   notifications: Notifications; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * References a specific dataset entity that could potentially be a UMP dataset | 
					
						
							|  |  |  |    * @type {IDatasetView} | 
					
						
							|  |  |  |    * @memberof DatasetSnapshotContainer | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   dataset: IDatasetView; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Snapshot data for this.dataset if the dataset is a UMP dataset, otherwise undefined value | 
					
						
							|  |  |  |    * @type {IDatasetSnapshot} | 
					
						
							|  |  |  |    * @memberof DatasetSnapshotContainer | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   snapshot?: IDatasetSnapshot; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** | 
					
						
							|  |  |  |    * Container task will fetch and set snapshot data for this.dataset | 
					
						
							|  |  |  |    * @memberof DatasetSnapshotContainer | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   @(task(function*(this: DatasetSnapshotContainer): IterableIterator<Promise<IDatasetSnapshot>> { | 
					
						
							|  |  |  |     const { notify } = this.notifications; | 
					
						
							|  |  |  |     const { uri, platform } = this.dataset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (platform === DatasetPlatform.UMP) { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         const datasetSnapshot: IDatasetSnapshot = yield readDatasetSnapshot(uri); | 
					
						
							|  |  |  |         set(this, 'snapshot', datasetSnapshot); | 
					
						
							|  |  |  |       } catch (e) { | 
					
						
							|  |  |  |         notify({ type: NotificationEvent.error, content: e }); | 
					
						
							|  |  |  |         throw e; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }).restartable()) | 
					
						
							| 
									
										
										
										
											2019-09-04 21:46:02 -07:00
										 |  |  |   getContainerDataTask!: ETaskPromise<IDatasetSnapshot>; | 
					
						
							| 
									
										
										
										
											2019-08-31 20:51:14 -07:00
										 |  |  | } |