2018-02-21 09:46:04 -08:00
|
|
|
import Component from '@ember/component';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { get } from '@ember/object';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { action } from '@ember/object';
|
|
|
|
import Notifications from '@datahub/utils/services/notifications';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { updateDatasetDeprecationByUrn } from 'datahub-web/utils/api/datasets/properties';
|
2019-08-31 20:51:14 -07:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { NotificationEvent } from '@datahub/utils/constants/notifications';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { DatasetEntity } from '@datahub/data-models/entity/dataset/dataset-entity';
|
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
|
|
|
|
type DeprecationType = Exclude<Com.Linkedin.Dataset.Dataset['deprecation'], undefined>;
|
2018-02-21 09:46:04 -08:00
|
|
|
|
|
|
|
export default class DatasetPropertiesContainer extends Component {
|
|
|
|
/**
|
|
|
|
* The urn identifier for the dataset
|
|
|
|
* @type {string}
|
|
|
|
*/
|
|
|
|
urn: string;
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
/**
|
|
|
|
* DatasetEntity instace passed down from the entity-page container
|
|
|
|
*/
|
|
|
|
entity: DatasetEntity;
|
|
|
|
|
2018-02-21 09:46:04 -08:00
|
|
|
/**
|
|
|
|
* Flag indicating that the dataset is deprecated
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
@alias('entity.deprecated')
|
|
|
|
deprecated: DeprecationType['deprecated'] | undefined;
|
2018-02-21 09:46:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Text string, intended to indicate the reason for deprecation
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
@alias('entity.deprecationNote')
|
|
|
|
deprecationNote: DeprecationType['note'] | undefined = '';
|
2018-02-21 09:46:04 -08:00
|
|
|
|
2018-05-10 17:08:50 -07:00
|
|
|
/**
|
|
|
|
* Time when the dataset will be decommissioned
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
@alias('entity.decommissionTime')
|
|
|
|
decommissionTime: DeprecationType['decommissionTime'] | undefined;
|
2018-05-10 17:08:50 -07:00
|
|
|
|
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
|
|
|
/**
|
|
|
|
* 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}`
|
|
|
|
});
|
|
|
|
}
|
2018-02-21 09:46:04 -08:00
|
|
|
}
|
|
|
|
}
|