2017-10-23 16:50:48 -07:00
|
|
|
import Component from '@ember/component';
|
2018-01-17 09:08:27 -08:00
|
|
|
import { get, set } from '@ember/object';
|
2018-02-21 17:20:12 -08:00
|
|
|
import { run, next } from '@ember/runloop';
|
2018-01-17 09:08:27 -08:00
|
|
|
import DatasetCompliance from 'wherehows-web/components/dataset-compliance';
|
2017-10-20 21:34:58 -07:00
|
|
|
import {
|
|
|
|
baseCommentEditorOptions,
|
2018-01-10 08:21:20 -08:00
|
|
|
DatasetPlatform,
|
2017-10-20 21:34:58 -07:00
|
|
|
exemptPolicy,
|
|
|
|
isExempt,
|
2017-12-01 17:22:24 -08:00
|
|
|
missingPolicyText,
|
2017-10-20 21:34:58 -07:00
|
|
|
PurgePolicy,
|
|
|
|
purgePolicyProps
|
|
|
|
} from 'wherehows-web/constants';
|
2018-01-10 08:21:20 -08:00
|
|
|
import { IComplianceInfo } from 'wherehows-web/typings/api/datasets/compliance';
|
2017-10-19 18:17:16 -07:00
|
|
|
|
2018-01-10 08:21:20 -08:00
|
|
|
export default class PurgePolicyComponent extends Component {
|
2017-12-01 17:22:24 -08:00
|
|
|
/**
|
|
|
|
* Reference to the purge exempt policy
|
2018-01-10 08:21:20 -08:00
|
|
|
* @type {PurgePolicy}
|
2017-12-01 17:22:24 -08:00
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
exemptPolicy = exemptPolicy;
|
2017-10-19 18:17:16 -07:00
|
|
|
|
2017-12-01 17:22:24 -08:00
|
|
|
/**
|
|
|
|
* Reference to the informational text if the dataset does not have a saved purge policy
|
|
|
|
* @type {string}
|
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
missingPolicyText = missingPolicyText;
|
2017-12-01 17:22:24 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to client options for each purge policy
|
|
|
|
* @type {PurgePolicyProperties}
|
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
purgePolicyProps = purgePolicyProps;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The list of supported purge policies for the related platform
|
|
|
|
* @type {Array<PurgePolicy>}
|
|
|
|
* @memberof PurgePolicyComponent
|
|
|
|
*/
|
2018-01-17 09:08:27 -08:00
|
|
|
supportedPurgePolicies: DatasetCompliance['supportedPurgePolicies'];
|
2017-10-19 18:17:16 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The dataset's platform
|
2018-01-10 08:21:20 -08:00
|
|
|
* @type {DatasetPlatform}
|
|
|
|
* @memberof PurgePolicyComponent
|
2017-10-19 18:17:16 -07:00
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
platform: DatasetPlatform;
|
2017-10-19 18:17:16 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The currently save policy for the dataset purge
|
2018-01-10 08:21:20 -08:00
|
|
|
* @type {PurgePolicy}
|
|
|
|
* @memberof PurgePolicyComponent
|
2017-10-19 18:17:16 -07:00
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
purgePolicy: PurgePolicy;
|
2017-10-23 16:50:48 -07:00
|
|
|
|
2018-01-10 08:21:20 -08:00
|
|
|
/**
|
|
|
|
* Flag indication that policy has a request exemption reason
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
2018-02-21 17:20:12 -08:00
|
|
|
requestExemptionReason: boolean;
|
2017-10-19 18:17:16 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An options hash for the purge exempt reason text editor
|
|
|
|
* @type {}
|
2018-01-10 08:21:20 -08:00
|
|
|
* @memberof PurgePolicyComponent
|
2017-10-19 18:17:16 -07:00
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
editorOptions = {
|
2017-10-19 18:17:16 -07:00
|
|
|
...baseCommentEditorOptions,
|
|
|
|
placeholder: {
|
2017-11-01 09:10:42 -07:00
|
|
|
text: 'Please provide an explanation for why this dataset is marked "Purge Exempt" status',
|
|
|
|
hideOnClick: false
|
2017-10-19 18:17:16 -07:00
|
|
|
}
|
2018-01-10 08:21:20 -08:00
|
|
|
};
|
2017-10-19 18:17:16 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to handle policy change, by default a no-op function
|
2018-01-10 08:21:20 -08:00
|
|
|
* @type {(purgePolicy: PurgePolicy) => IComplianceInfo['complianceType'] | null}
|
|
|
|
* @memberof PurgePolicyComponent
|
2017-10-19 18:17:16 -07:00
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
onPolicyChange: (purgePolicy: PurgePolicy) => IComplianceInfo['complianceType'] | null;
|
2017-10-19 18:17:16 -07:00
|
|
|
|
2018-02-21 17:20:12 -08:00
|
|
|
constructor() {
|
|
|
|
super(...arguments);
|
|
|
|
|
|
|
|
this.requestExemptionReason || (this.requestExemptionReason = false);
|
|
|
|
}
|
|
|
|
|
2018-01-20 00:46:47 -08:00
|
|
|
didReceiveAttrs(this: PurgePolicyComponent) {
|
2017-10-19 18:17:16 -07:00
|
|
|
this._super(...arguments);
|
|
|
|
this.checkExemption(get(this, 'purgePolicy'));
|
2018-01-10 08:21:20 -08:00
|
|
|
}
|
|
|
|
|
2017-10-19 18:17:16 -07:00
|
|
|
/**
|
|
|
|
* Checks that the selected purge policy is exempt, if so, set the
|
|
|
|
* flag to request the exemption to true
|
|
|
|
* @param {PurgePolicy} purgePolicy
|
|
|
|
*/
|
2018-01-20 00:46:47 -08:00
|
|
|
checkExemption(this: PurgePolicyComponent, purgePolicy: PurgePolicy) {
|
2017-10-19 18:17:16 -07:00
|
|
|
const exemptionReasonRequested = isExempt(purgePolicy);
|
|
|
|
set(this, 'requestExemptionReason', exemptionReasonRequested);
|
2017-11-01 09:10:42 -07:00
|
|
|
|
|
|
|
if (exemptionReasonRequested) {
|
|
|
|
// schedule for a future queue, 'likely' post render
|
|
|
|
// this allows us to ensure that editor it visible after the set above has been performed
|
2018-02-21 17:20:12 -08:00
|
|
|
run(() => next(this, 'focusEditor'));
|
2017-11-01 09:10:42 -07:00
|
|
|
}
|
2018-01-10 08:21:20 -08:00
|
|
|
}
|
2017-11-01 09:10:42 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Applies cursor / document focus to the purge note text editor
|
|
|
|
*/
|
2018-01-20 00:46:47 -08:00
|
|
|
focusEditor(this: PurgePolicyComponent) {
|
2018-02-21 17:20:12 -08:00
|
|
|
const element = get(this, 'element');
|
2018-02-21 16:32:31 -08:00
|
|
|
const exemptionReasonElement: HTMLElement | null = element && element.querySelector('.comment-new__content');
|
2017-11-01 09:10:42 -07:00
|
|
|
|
|
|
|
if (exemptionReasonElement) {
|
|
|
|
exemptionReasonElement.focus();
|
|
|
|
}
|
2018-01-10 08:21:20 -08:00
|
|
|
}
|
2017-10-19 18:17:16 -07:00
|
|
|
|
2018-01-10 08:21:20 -08:00
|
|
|
actions = {
|
2017-10-19 18:17:16 -07:00
|
|
|
/**
|
|
|
|
* Handles the change to the currently selected purge policy
|
|
|
|
* @param {string} _name unused name for the radio group
|
|
|
|
* @param {PurgePolicy} purgePolicy the selected purge policy
|
|
|
|
*/
|
2018-01-10 08:21:20 -08:00
|
|
|
onChange(this: PurgePolicyComponent, _name: string, purgePolicy: PurgePolicy) {
|
2017-10-19 18:17:16 -07:00
|
|
|
return get(this, 'onPolicyChange')(purgePolicy);
|
|
|
|
}
|
2018-01-10 08:21:20 -08:00
|
|
|
};
|
|
|
|
}
|