mirror of
https://github.com/datahub-project/datahub.git
synced 2025-09-26 17:45:30 +00:00
Code cleanup for export policy on the UI
This commit is contained in:
parent
00a8781d5a
commit
c01034191e
@ -144,9 +144,9 @@ export default class DatasetCompliance extends Component {
|
|||||||
/**
|
/**
|
||||||
* Pass through value for the dataset export policy, to be used by one of our child components on
|
* Pass through value for the dataset export policy, to be used by one of our child components on
|
||||||
* this page
|
* this page
|
||||||
* @type {IDatasetClassificationOption}
|
* @type {IDatasetExportPolicy}
|
||||||
*/
|
*/
|
||||||
exportPolicy: IDatasetExportPolicy;
|
exportPolicy: IDatasetExportPolicy | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confidence percentage number used to filter high quality suggestions versus lower quality
|
* Confidence percentage number used to filter high quality suggestions versus lower quality
|
||||||
@ -167,7 +167,7 @@ export default class DatasetCompliance extends Component {
|
|||||||
* @type {ComplianceEdit}
|
* @type {ComplianceEdit}
|
||||||
* @memberof DatasetCompliance
|
* @memberof DatasetCompliance
|
||||||
*/
|
*/
|
||||||
editTarget: ComplianceEdit;
|
editTarget: ComplianceEdit | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag determining whether or not we are in an editing state. Triggered by an action connected to the
|
* Flag determining whether or not we are in an editing state. Triggered by an action connected to the
|
||||||
@ -1107,7 +1107,7 @@ export default class DatasetCompliance extends Component {
|
|||||||
* @param isEditing - Whether or not we are entering or exiting the editing mode
|
* @param isEditing - Whether or not we are entering or exiting the editing mode
|
||||||
* @param editTarget - Which component/section is going into editing mode
|
* @param editTarget - Which component/section is going into editing mode
|
||||||
*/
|
*/
|
||||||
toggleEditing(this: DatasetCompliance, isEditing: boolean = false, editTarget: ComplianceEdit): void {
|
toggleEditing(this: DatasetCompliance, isEditing: boolean = false, editTarget?: ComplianceEdit): void {
|
||||||
setProperties(this, { isEditing, editTarget });
|
setProperties(this, { isEditing, editTarget });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1115,7 +1115,7 @@ export default class DatasetCompliance extends Component {
|
|||||||
* Handler that processes actions to be called before the save process
|
* Handler that processes actions to be called before the save process
|
||||||
* @param editTarget - The current edit target being saved
|
* @param editTarget - The current edit target being saved
|
||||||
*/
|
*/
|
||||||
async beforeSaveCompliance(editTarget: ComplianceEdit): Promise<void> {
|
async beforeSaveCompliance(editTarget?: ComplianceEdit): Promise<void> {
|
||||||
switch (editTarget) {
|
switch (editTarget) {
|
||||||
case ComplianceEdit.CompliancePolicy:
|
case ComplianceEdit.CompliancePolicy:
|
||||||
await this.actions.didEditCompliancePolicy.call(this);
|
await this.actions.didEditCompliancePolicy.call(this);
|
||||||
|
@ -3,9 +3,10 @@ import { ComplianceEdit, ExportPolicyKeys } from 'wherehows-web/constants';
|
|||||||
import { noop } from 'wherehows-web/utils/helpers/functions';
|
import { noop } from 'wherehows-web/utils/helpers/functions';
|
||||||
import { IDatasetExportPolicy } from 'wherehows-web/typings/api/datasets/compliance';
|
import { IDatasetExportPolicy } from 'wherehows-web/typings/api/datasets/compliance';
|
||||||
import { IExportPolicyTable } from 'wherehows-web/typings/app/datasets/export-policy';
|
import { IExportPolicyTable } from 'wherehows-web/typings/app/datasets/export-policy';
|
||||||
import { computed, getWithDefault, get, set } from '@ember/object';
|
import { get, set } from '@ember/object';
|
||||||
import { action } from '@ember-decorators/object';
|
import { action, computed } from '@ember-decorators/object';
|
||||||
import { or } from '@ember/object/computed';
|
import { or } from '@ember-decorators/object/computed';
|
||||||
|
import ComputedProperty from '@ember/object/computed';
|
||||||
|
|
||||||
enum ExportPolicyLabels {
|
enum ExportPolicyLabels {
|
||||||
UGC = 'User Generated Content - data directly created by the member',
|
UGC = 'User Generated Content - data directly created by the member',
|
||||||
@ -17,22 +18,16 @@ enum ExportPolicyLabels {
|
|||||||
* Creates an array from the ExportPolicyKeys enum
|
* Creates an array from the ExportPolicyKeys enum
|
||||||
*/
|
*/
|
||||||
const policyKeys = <Array<keyof typeof ExportPolicyKeys>>Object.keys(ExportPolicyKeys);
|
const policyKeys = <Array<keyof typeof ExportPolicyKeys>>Object.keys(ExportPolicyKeys);
|
||||||
|
// Values in the same order as our keys
|
||||||
const policyValues = <Array<ExportPolicyKeys>>policyKeys.map(key => ExportPolicyKeys[key]);
|
const policyValues = <Array<ExportPolicyKeys>>policyKeys.map(key => ExportPolicyKeys[key]);
|
||||||
|
|
||||||
export default class ComplianceExportPolicy extends Component {
|
export default class ComplianceExportPolicy extends Component.extend({
|
||||||
/**
|
/**
|
||||||
* Sets the tag for the html element rendered by our component
|
* Sets the tag for the html element rendered by our component
|
||||||
* @type {string}
|
* @type {string}
|
||||||
*/
|
*/
|
||||||
tagName = '';
|
tagName: ''
|
||||||
|
}) {
|
||||||
/**
|
|
||||||
* Sets the id of the html element rendered by our component. Removing it here so we avoid
|
|
||||||
* errors that occur because our component is tagless
|
|
||||||
* @type {string}
|
|
||||||
*/
|
|
||||||
elementId = <any>undefined;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows us to use our constants set in this enum inside our hbs template
|
* Allows us to use our constants set in this enum inside our hbs template
|
||||||
* @type {ComplianceEdit}
|
* @type {ComplianceEdit}
|
||||||
@ -46,16 +41,16 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
isEditing: boolean;
|
isEditing: boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Passed in from the parent component, this function acts as an action to trigger edit mode on
|
* Passed through ation from the parent component, this function acts as an action to trigger edit mode
|
||||||
* this component
|
* on this component
|
||||||
* @type {Ember.ActionHandler}
|
* @type {(edit: boolean, target: ComplianceEdit) => void}
|
||||||
*/
|
*/
|
||||||
toggleEditing: (edit: boolean, target: ComplianceEdit) => void;
|
toggleEditing: (edit: boolean, target?: ComplianceEdit) => void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Passed in from the parent component, this function triggers the saving logic and subsequent POST
|
* Passed through action from the parent component, this function triggers the saving logic and subsequent
|
||||||
* request to persist the export policy edits
|
* POST request to persist the export policy edits
|
||||||
* @type {Ember.ActionHandler}
|
* @type {(policy: IDatasetExportPolicy) => void}
|
||||||
*/
|
*/
|
||||||
onSaveExportPolicy: (policy: IDatasetExportPolicy) => void;
|
onSaveExportPolicy: (policy: IDatasetExportPolicy) => void;
|
||||||
|
|
||||||
@ -72,7 +67,8 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
* @memberof ComplianceExportPolicy
|
* @memberof ComplianceExportPolicy
|
||||||
*/
|
*/
|
||||||
shouldShowAllExportPolicyData = or('isEditing', 'shouldShowMorePolicyData');
|
@or('isEditing', 'shouldShowMorePolicyData')
|
||||||
|
shouldShowAllExportPolicyData: ComputedProperty<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The export policy data extracted directly from the api response, passed in from the dataset-compliance
|
* The export policy data extracted directly from the api response, passed in from the dataset-compliance
|
||||||
@ -80,7 +76,7 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
* @type {IDatasetExportPolicy}
|
* @type {IDatasetExportPolicy}
|
||||||
* @memberof ComplianceExportPolicy
|
* @memberof ComplianceExportPolicy
|
||||||
*/
|
*/
|
||||||
exportPolicyData: IDatasetExportPolicy;
|
exportPolicyData: IDatasetExportPolicy | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the table for the export policy questions with seeded information based on the api response
|
* Calculates the table for the export policy questions with seeded information based on the api response
|
||||||
@ -88,8 +84,13 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
* @type {ComputedProperty<Array<IExportPolicyTable>>}
|
* @type {ComputedProperty<Array<IExportPolicyTable>>}
|
||||||
* @memberof ComplianceExportPolicy
|
* @memberof ComplianceExportPolicy
|
||||||
*/
|
*/
|
||||||
datasetExportPolicy = computed('exportPolicyData', 'isEditing', function(): Array<IExportPolicyTable> {
|
@computed('exportPolicyData', 'isEditing')
|
||||||
const exportPolicyData: IDatasetExportPolicy = getWithDefault(this, 'exportPolicyData', {});
|
get datasetExportPolicy(): Array<IExportPolicyTable> {
|
||||||
|
const exportPolicyData = get(this, 'exportPolicyData');
|
||||||
|
|
||||||
|
if (!exportPolicyData) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return policyKeys.map(key => {
|
return policyKeys.map(key => {
|
||||||
const dataType = ExportPolicyKeys[key];
|
const dataType = ExportPolicyKeys[key];
|
||||||
@ -100,7 +101,7 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
label: ExportPolicyLabels[key]
|
label: ExportPolicyLabels[key]
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
@ -149,13 +150,9 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
@action
|
@action
|
||||||
saveCompliance(): void {
|
saveCompliance(): void {
|
||||||
const datasetExportPolicy = get(this, 'datasetExportPolicy');
|
const datasetExportPolicy = get(this, 'datasetExportPolicy');
|
||||||
const exportPolicy = datasetExportPolicy.reduce(
|
const exportPolicy = datasetExportPolicy.reduce((policy, datum) => ({ ...policy, [datum.dataType]: datum.value }), <
|
||||||
(policy, datum) => {
|
IDatasetExportPolicy
|
||||||
policy[datum.dataType] = datum.value;
|
>{});
|
||||||
return policy;
|
|
||||||
},
|
|
||||||
<IDatasetExportPolicy>{}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.onSaveExportPolicy(exportPolicy);
|
this.onSaveExportPolicy(exportPolicy);
|
||||||
}
|
}
|
||||||
@ -167,6 +164,6 @@ export default class ComplianceExportPolicy extends Component {
|
|||||||
*/
|
*/
|
||||||
@action
|
@action
|
||||||
onCancel(): void {
|
onCancel(): void {
|
||||||
this.toggleEditing(false, <any>undefined);
|
this.toggleEditing(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ export default class DatasetComplianceContainer extends Component {
|
|||||||
* Object containing the fields for the export policy for this dataset
|
* Object containing the fields for the export policy for this dataset
|
||||||
* @type {IDatasetExportPolicy}
|
* @type {IDatasetExportPolicy}
|
||||||
*/
|
*/
|
||||||
exportPolicy: IDatasetExportPolicy;
|
exportPolicy: IDatasetExportPolicy | undefined;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The platform / db that the dataset is persisted
|
* The platform / db that the dataset is persisted
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
{{#if isEditing}}
|
{{#if isEditing}}
|
||||||
|
|
||||||
<div class="container action-bar__content">
|
<div class="container action-bar__content">
|
||||||
|
|
||||||
{{#track-ui-event category=trackableCategory.Compliance
|
|
||||||
action=trackableEvent.Compliance.Save as |metrics|}}
|
|
||||||
<button
|
<button
|
||||||
class="nacho-button nacho-button--large-inverse action-bar__item"
|
class="nacho-button nacho-button--large-inverse action-bar__item"
|
||||||
title="{{unless isDatasetFullyClassified
|
title="{{unless isDatasetFullyClassified
|
||||||
@ -13,17 +10,12 @@
|
|||||||
onclick={{action metrics.trackOnAction (action "saveCompliance")}} disabled={{shouldDisableEditSaving}}>
|
onclick={{action metrics.trackOnAction (action "saveCompliance")}} disabled={{shouldDisableEditSaving}}>
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
{{/track-ui-event}}
|
|
||||||
|
|
||||||
{{#track-ui-event category=trackableCategory.Compliance
|
|
||||||
action=trackableEvent.Compliance.Cancel as |metrics|}}
|
|
||||||
<button
|
<button
|
||||||
class="nacho-button nacho-button--large nacho-button--secondary action-bar__item"
|
class="nacho-button nacho-button--large nacho-button--secondary action-bar__item"
|
||||||
onclick={{action metrics.trackOnAction (action "onCancel")}}>
|
onclick={{action metrics.trackOnAction (action "onCancel")}}>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
{{/track-ui-event}}
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user