diff --git a/wherehows-web/app/components/datasets/schemaless-tagging.ts b/wherehows-web/app/components/datasets/schemaless-tagging.ts index a85a51d67d..39cf89bb90 100644 --- a/wherehows-web/app/components/datasets/schemaless-tagging.ts +++ b/wherehows-web/app/components/datasets/schemaless-tagging.ts @@ -2,7 +2,8 @@ import Component from '@ember/component'; import { get, computed } from '@ember/object'; import { action } from '@ember-decorators/object'; import { ISecurityClassificationOption } from 'wherehows-web/typings/app/dataset-compliance'; -import { getSecurityClassificationDropDownOptions } from 'wherehows-web/constants'; +import { getSecurityClassificationDropDownOptions, ComplianceEdit } from 'wherehows-web/constants'; +import { noop } from 'wherehows-web/utils/helpers/functions'; export default class SchemalessTagging extends Component { classNames = ['schemaless-tagging']; @@ -21,6 +22,11 @@ export default class SchemalessTagging extends Component { securityClassification: ISecurityClassificationOption['value'] ) => ISecurityClassificationOption['value']; + /** + * Used to pass around constants in the component or template + */ + ComplianceEdit = ComplianceEdit; + /** * Flag indicating that the dataset contains personally identifiable data * @type {boolean} @@ -28,6 +34,13 @@ export default class SchemalessTagging extends Component { */ containsPersonalData: boolean; + /** + * Passed through flag that determines whether or not we are in an editing state for this + * component + * @type {boolean} + */ + isEditing: boolean; + /** * List of drop down options for classifying the dataset * @type {Array} @@ -39,13 +52,6 @@ export default class SchemalessTagging extends Component { return getSecurityClassificationDropDownOptions(get(this, 'containsPersonalData')); }); - /** - * Flag indicating if this component should be in edit mode or readonly - * @type {boolean} - * @memberof SchemalessTagging - */ - isEditable: boolean; - /** * The current dataset classification value * @type { ISecurityClassificationOption.value} @@ -53,6 +59,55 @@ export default class SchemalessTagging extends Component { */ classification: ISecurityClassificationOption['value']; + /** + * Passed through action from the parent dataset-compliance component that toggles editing + * at the container level + * @type {(e: boolean) => void} + */ + toggleEditing: (edit: boolean) => void; + + /** + * Passed through action from the parent dataset-compliance component that triggers a save + * action for the compliance information + * @type {() => Promise} + */ + onSaveCompliance: () => Promise; + + /** + * Passed through action from the parent dataset-compliance component that triggers a reset + * for our compliance information, effectively rolling us back to the server state + * @type {() => void} + */ + resetCompliance: () => void; + + constructor() { + super(...arguments); + + typeof this.isEditing === 'boolean' || (this.isEditing = false); + this.toggleEditing || (this.toggleEditing = noop); + this.onSaveCompliance || (this.onSaveCompliance = noop); + this.resetCompliance || (this.resetCompliance = noop); + } + + /** + * Action in the template action bar that the user clicks to save their changes to the dataset + * level classification + */ + @action + saveCompliance() { + this.onSaveCompliance(); + } + + /** + * Action in the template action bar that the user clicks to cancel their changes. It sets our + * editing flag to false and re-fetches information from the server to "roll back" our changes + */ + @action + onCancel() { + this.toggleEditing(false); + this.resetCompliance(); + } + /** * Invokes the closure action onPersonaDataChange when the flag is toggled * @param {boolean} containsPersonalDataTag flag indicating that the dataset contains personal data diff --git a/wherehows-web/app/templates/components/dataset-compliance.hbs b/wherehows-web/app/templates/components/dataset-compliance.hbs index 7974e48b63..60c6a8b5ed 100644 --- a/wherehows-web/app/templates/components/dataset-compliance.hbs +++ b/wherehows-web/app/templates/components/dataset-compliance.hbs @@ -98,6 +98,7 @@ {{datasets/compliance/export-policy exportPolicyData=exportPolicy isEditing=isEditing + wikiLinks=@wikiLinks toggleEditing=(action toggleEditing) onSaveExportPolicy=(action "saveExportPolicy")}} {{/if}} @@ -166,14 +167,17 @@ {{#if schemaless}} - {{#if (or isReadOnly (eq editTarget ComplianceEdit.CompliancePolicy))}} + {{#if (or isReadOnly (eq editTarget ComplianceEdit.DatasetLevelPolicy))}} {{datasets/schemaless-tagging classificationHelpLink=@wikiLinks.dht - isEditable=(not isReadOnly) + isEditing=isEditing classification=(readonly complianceInfo.confidentiality) containsPersonalData=(readonly complianceInfo.containingPersonalData) + toggleEditing=(action toggleEditing) onClassificationChange=(action "onDatasetSecurityClassificationChange") onPersonalDataChange=(action "onDatasetLevelPolicyChange") + onSaveCompliance=(action "saveCompliance") + resetCompliance=(action "resetCompliance") }} {{/if}} diff --git a/wherehows-web/app/templates/components/datasets/schemaless-tagging.hbs b/wherehows-web/app/templates/components/datasets/schemaless-tagging.hbs index dfdd852b1a..4e05eb4d47 100644 --- a/wherehows-web/app/templates/components/datasets/schemaless-tagging.hbs +++ b/wherehows-web/app/templates/components/datasets/schemaless-tagging.hbs @@ -2,10 +2,24 @@ +{{#if isEditing}} + {{partial "datasets/dataset-compliance/action-bar"}} +{{/if}} +

Dataset contains personally identifiable information? @@ -16,7 +30,7 @@ id=(concat elementId '-schemaless-checkbox') type="checkbox" class="toggle-switch toggle-switch--light" - disabled=(not isEditable) + disabled=(not isEditing) checked=(readonly containsPersonalData) change=(action "onPersonalDataToggle" value="target.checked") }} @@ -39,7 +53,7 @@ {{ember-selector values=classifiers selected=classification - disabled=(not isEditable) + disabled=(not isEditing) selectionDidChange=(action "onSecurityClassificationChange") }}