From 29a142dee4efd6910a444eaf5ce6aa76f961572c Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Fri, 5 Jul 2024 22:05:30 -0700
Subject: [PATCH] Retain options for edit
---
src-ui/messages.xlf | 4 ++--
.../custom-field-edit-dialog.component.spec.ts | 18 ++++++++++++++++++
.../custom-field-edit-dialog.component.ts | 5 +++++
3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/src-ui/messages.xlf b/src-ui/messages.xlf
index dc25ca462..5f5393e6a 100644
--- a/src-ui/messages.xlf
+++ b/src-ui/messages.xlf
@@ -3460,14 +3460,14 @@
Create new custom field
src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts
- 44
+ 52
Edit custom field
src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts
- 48
+ 56
diff --git a/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.spec.ts b/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.spec.ts
index 03a93b3f5..6e56b2929 100644
--- a/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.spec.ts
+++ b/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.spec.ts
@@ -13,6 +13,7 @@ import { SelectComponent } from '../../input/select/select.component'
import { TextComponent } from '../../input/text/text.component'
import { EditDialogMode } from '../edit-dialog.component'
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
+import { CustomFieldDataType } from 'src/app/data/custom-field'
describe('CustomFieldEditDialogComponent', () => {
let component: CustomFieldEditDialogComponent
@@ -64,6 +65,23 @@ describe('CustomFieldEditDialogComponent', () => {
expect(component.objectForm.get('data_type').disabled).toBeTruthy()
})
+ it('should initialize select options on edit', () => {
+ component.dialogMode = EditDialogMode.EDIT
+ component.object = {
+ id: 1,
+ name: 'Field 1',
+ data_type: CustomFieldDataType.Select,
+ extra_data: {
+ select_options: ['Option 1', 'Option 2', 'Option 3'],
+ },
+ }
+ fixture.detectChanges()
+ component.ngOnInit()
+ expect(
+ component.objectForm.get('extra_data').get('select_options').value.length
+ ).toBe(3)
+ })
+
it('should support add / remove select options', () => {
component.dialogMode = EditDialogMode.CREATE
fixture.detectChanges()
diff --git a/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts b/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts
index e31c089b1..24e7c57ca 100644
--- a/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts
+++ b/src-ui/src/app/components/common/edit-dialog/custom-field-edit-dialog/custom-field-edit-dialog.component.ts
@@ -41,6 +41,11 @@ export class CustomFieldEditDialogComponent
if (this.typeFieldDisabled) {
this.objectForm.get('data_type').disable()
}
+ if (this.object?.data_type === CustomFieldDataType.Select) {
+ this.object.extra_data.select_options.forEach((option) =>
+ this.selectOptions.push(new FormControl(option))
+ )
+ }
}
getCreateTitle() {