fix: 🐛 policy UI bug fix (#2098)

* fix: 🐛 policy UI bug fix
This commit is contained in:
Dharini Jeeva authored and GitHub committed 2024-01-19 14:06:51 -08:00
1 parent 3f2fc63b5b
commit 5a74220f38
15 files changed
+341 -58

No files matched your search

@@ -43,9 +43,13 @@ export default class FormPolicyComponent extends Component {
/**
* Returns policy type
* API doesn't return days for do_not_protect,
* so we set option to do_not_protect when there's no retain days
* @type {string}
*/
get selectRetentionPolicyType() {
if (!this.args.model.retain_for?.days) return 'do_not_protect';
const val = Object.keys(RETENTION_POLICY).find(
(i) => RETENTION_POLICY[i] === this.args.model.retain_for?.days,
);
@@ -15,6 +15,7 @@
name={{@name}}
disabled={{or @disabled this.isDeleteDisable}}
aria-label={{t (concat 'resources.policy.form.' @name '.label')}}
data-select={{@name}}
@width='70%'
{{on 'change' this.handlePolicyTypeSelection}}
as |F|
@@ -35,9 +36,10 @@
</Hds::Form::Select::Field>
{{#if @model.scope.isGlobal}}
<Hds::Form::Toggle::Field
checked={{this.isOverridable}}
disabled={{@disabled}}
name={{@customInputName}}
checked={{this.isOverridable}}
disabled={{this.toggleDisabled}}
data-toggle={{@customInputName}}
{{on 'change' this.handleOverridableToggle}}
as |F|
>
@@ -53,12 +55,12 @@
<F.Control>
<Hds::SegmentedGroup as |S|>
<S.TextInput
name={{@customInputName}}
@value={{@inputValue}}
disabled={{@disabled}}
aria-label={{t 'resources.policy.title'}}
data-input={{@customInputName}}
{{on 'input' this.handleInputChange}}
name={{@customInputName}}
data-input-type={{@customInputName}}
/>
<S.Generic>
<Hds::Badge
@@ -13,52 +13,35 @@ export default class FormPolicySelectionComponent extends Component {
* @type {boolean}
*/
get showCustomInput() {
if (this.args.name === 'retention_policy') {
return this.isCustomRetentionSelected;
} else if (
this.args.name === 'deletion_policy' &&
this.args.model.retain_for?.days >= 0
) {
return this.isCustomDeletionSelected;
} else {
return null;
}
return this.args.selectedOption === 'custom';
}
/**
* Returns true if rentention days are greater than 0
* Disable toggle when the form is disabled and when the retain/delete after days are 0
* @type {boolean}
*/
get isCustomRetentionSelected() {
//no need to show custom input for the below days
const arr = [-1, 0, 2555, 2190];
return arr.includes(this.args.model.retain_for?.days) ? false : true;
get toggleDisabled() {
return (
this.args.disabled || !this.args.model[this.args.customInputName]?.days
);
}
/**
* Returns true if deletion days are greater than 0
* @type {boolean}
*/
get isCustomDeletionSelected() {
return this.args.model.delete_after?.days > 0;
}
/**
* Returns true if the toggle is on
* @type {boolean}
*/
get isOverridable() {
return this.args.model[this.args.customInputName]?.overridable;
return (
this.args.model[this.args.customInputName]?.days &&
this.args.model[this.args.customInputName]?.overridable
);
}
get isDeleteDisable() {
if (
return (
this.args.name === 'deletion_policy' &&
this.args.model.retain_for?.days === -1
) {
return true;
} else {
return false;
}
);
}
//actions
/**
@@ -67,11 +50,13 @@ export default class FormPolicySelectionComponent extends Component {
@action
handleInputChange({ target: { value, name: field } }) {
// Select options return type is string and we want the `days` in integer format
const val = Number(value);
this.args.model[field] = {
...this.args.model[field],
days: val,
};
if (value) {
const val = Number(value);
this.args.model[field] = {
...this.args.model[field],
days: val,
};
}
}
/**
@@ -15,9 +15,7 @@
</page.breadcrumbs>
<page.header>
<Hds::Text::Display @tag='h2'>
{{t 'resources.policy.titles.new'}}
</Hds::Text::Display>
<h2>{{t 'resources.policy.titles.new'}}</h2>
</page.header>
<page.body>