2018-02-21 09:46:04 -08:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import { get, setProperties } from '@ember/object';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { Task, task } from 'ember-concurrency';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
import Notifications from '@datahub/utils/services/notifications';
|
2018-02-21 09:46:04 -08:00
|
|
|
import { IDatasetView } from 'wherehows-web/typings/api/datasets/dataset';
|
|
|
|
import { readDatasetByUrn } from 'wherehows-web/utils/api/datasets/dataset';
|
|
|
|
import { updateDatasetDeprecationByUrn } from 'wherehows-web/utils/api/datasets/properties';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { containerDataSource } from '@datahub/utils/api/data-source';
|
|
|
|
import { NotificationEvent } from '@datahub/utils/constants/notifications';
|
2018-02-21 09:46:04 -08:00
|
|
|
|
2019-08-31 20:51:14 -07:00
|
|
|
@containerDataSource('getDeprecationPropertiesTask', ['urn'])
|
2018-02-21 09:46:04 -08:00
|
|
|
export default class DatasetPropertiesContainer extends Component {
|
|
|
|
/**
|
|
|
|
* The urn identifier for the dataset
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
urn: string;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flag indicating that the dataset is deprecated
|
2018-02-21 16:32:31 -08:00
|
|
|
* @type {IDatasetView.deprecated}
|
2018-02-21 09:46:04 -08:00
|
|
|
*/
|
2018-02-21 16:32:31 -08:00
|
|
|
deprecated: IDatasetView['deprecated'];
|
2018-02-21 09:46:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Text string, intended to indicate the reason for deprecation
|
2018-02-21 16:32:31 -08:00
|
|
|
* @type {IDatasetView.deprecationNote}
|
2018-02-21 09:46:04 -08:00
|
|
|
*/
|
2019-08-31 20:51:14 -07:00
|
|
|
deprecationNote: IDatasetView['deprecationNote'] = '';
|
2018-02-21 09:46:04 -08:00
|
|
|
|
2018-05-10 17:08:50 -07:00
|
|
|
/**
|
|
|
|
* Time when the dataset will be decommissioned
|
|
|
|
* @type {IDatasetView.decommissionTime}
|
|
|
|
*/
|
|
|
|
decommissionTime: IDatasetView['decommissionTime'];
|
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
/**
|
|
|
|
* THe list of properties for the dataset, currently unavailable for v2
|
|
|
|
* @type {any[]}
|
|
|
|
*/
|
|
|
|
properties: Array<never> = [];
|
|
|
|
|
2018-02-21 14:41:05 -08:00
|
|
|
/**
|
|
|
|
* References the application notifications service
|
|
|
|
* @memberof DatasetPropertiesContainer
|
|
|
|
* @type {ComputedProperty<Notifications>}
|
|
|
|
*/
|
2018-08-12 13:02:01 -07:00
|
|
|
@service
|
|
|
|
notifications: Notifications;
|
2018-02-21 14:41:05 -08:00
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
/**
|
|
|
|
* Reads the persisted deprecation properties for the dataset
|
|
|
|
* @type {Task<Promise<IDatasetView>, (a?: any) => TaskInstance<Promise<IDatasetView>>>}
|
|
|
|
*/
|
2019-08-31 20:51:14 -07:00
|
|
|
@task(function*(this: DatasetPropertiesContainer): IterableIterator<Promise<IDatasetView>> {
|
|
|
|
const { deprecated, deprecationNote, decommissionTime }: IDatasetView = yield readDatasetByUrn(this.urn);
|
2018-05-10 17:08:50 -07:00
|
|
|
setProperties(this, { deprecated, deprecationNote, decommissionTime });
|
2019-08-31 20:51:14 -07:00
|
|
|
})
|
|
|
|
getDeprecationPropertiesTask!: Task<Promise<IDatasetView>, () => Promise<IDatasetView>>;
|
2018-02-21 09:46:04 -08:00
|
|
|
/**
|
|
|
|
* Persists the changes to the dataset deprecation properties upstream
|
|
|
|
* @param {boolean} isDeprecated
|
|
|
|
* @param {string} updatedDeprecationNote
|
2018-05-10 17:08:50 -07:00
|
|
|
* @param {Date} decommissionTime dataset decommission date
|
2018-02-21 09:46:04 -08:00
|
|
|
* @return {Promise<void>}
|
|
|
|
*/
|
2018-02-21 14:41:05 -08:00
|
|
|
@action
|
|
|
|
async updateDeprecation(
|
|
|
|
this: DatasetPropertiesContainer,
|
|
|
|
isDeprecated: boolean,
|
2018-03-28 08:58:23 -07:00
|
|
|
updatedDeprecationNote: string,
|
2019-08-31 20:51:14 -07:00
|
|
|
decommissionTime: number | null
|
2018-02-21 14:41:05 -08:00
|
|
|
): Promise<void> {
|
|
|
|
const { notify } = get(this, 'notifications');
|
|
|
|
|
|
|
|
try {
|
2018-03-28 08:58:23 -07:00
|
|
|
await updateDatasetDeprecationByUrn(
|
|
|
|
get(this, 'urn'),
|
|
|
|
isDeprecated,
|
|
|
|
updatedDeprecationNote || '',
|
2019-08-31 20:51:14 -07:00
|
|
|
isDeprecated && decommissionTime ? decommissionTime : null
|
2018-03-28 08:58:23 -07:00
|
|
|
);
|
2018-02-21 14:41:05 -08:00
|
|
|
|
2019-08-31 20:51:14 -07:00
|
|
|
notify({
|
|
|
|
type: NotificationEvent.success,
|
2018-02-21 14:41:05 -08:00
|
|
|
content: 'Successfully updated deprecation status'
|
|
|
|
});
|
|
|
|
} catch (e) {
|
2019-08-31 20:51:14 -07:00
|
|
|
notify({
|
|
|
|
type: NotificationEvent.error,
|
2018-02-21 14:41:05 -08:00
|
|
|
content: `An error occurred: ${e.message}`
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
// set current state
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
this.getDeprecationPropertiesTask.perform();
|
2018-02-21 14:41:05 -08:00
|
|
|
}
|
2018-02-21 09:46:04 -08:00
|
|
|
}
|
|
|
|
}
|