ciyidogan commited on
Commit
59136fb
·
verified ·
1 Parent(s): 10bd24c

Update flare-ui/src/app/dialogs/version-edit-dialog/version-edit-dialog.component.ts

Browse files
flare-ui/src/app/dialogs/version-edit-dialog/version-edit-dialog.component.ts CHANGED
@@ -122,13 +122,10 @@ export default class VersionEditDialogComponent implements OnInit {
122
  loadVersion(version: Version) {
123
  this.selectedVersion = version;
124
 
125
- // Clear intents array
126
- const intentsArray = this.versionForm.get('intents') as FormArray;
127
- while (intentsArray.length !== 0) {
128
- intentsArray.removeAt(0);
129
- }
130
-
131
- // Populate form
132
  this.versionForm.patchValue({
133
  id: version.id,
134
  caption: version.caption,
@@ -149,9 +146,17 @@ export default class VersionEditDialogComponent implements OnInit {
149
  });
150
 
151
  // Populate intents
 
152
  if (version.intents) {
153
  version.intents.forEach(intent => {
154
- intentsArray.push(this.createIntentFormGroup(intent));
 
 
 
 
 
 
 
155
  });
156
  }
157
 
@@ -167,33 +172,26 @@ export default class VersionEditDialogComponent implements OnInit {
167
  }
168
 
169
  createIntentFormGroup(intent: any = {}): FormGroup {
170
- // Examples için FormControl array oluştur
171
- const examplesArray = this.fb.array(
172
- (intent.examples || []).map((example: string) => this.fb.control(example))
173
- );
174
-
175
- // Parameters için ayrı FormGroup'lar oluştur
176
- const parametersArray = this.fb.array([]);
177
-
178
- if (intent.parameters) {
179
- intent.parameters.forEach((param: any) => {
180
- parametersArray.push(this.createParameterFormGroup(param));
181
- });
182
- }
183
-
184
  return this.fb.group({
185
  name: [intent.name || '', [Validators.required, Validators.pattern(/^[a-zA-Z0-9-]+$/)]],
186
  caption: [intent.caption || ''],
187
  locale: [intent.locale || 'tr-TR'],
188
  detection_prompt: [intent.detection_prompt || '', Validators.required],
189
- examples: examplesArray,
190
- parameters: parametersArray,
191
  action: [intent.action || '', Validators.required],
192
  fallback_timeout_prompt: [intent.fallback_timeout_prompt || ''],
193
  fallback_error_prompt: [intent.fallback_error_prompt || '']
194
  });
195
  }
196
 
 
 
 
 
 
 
 
197
  createParameterFormGroup(param: any = {}): FormGroup {
198
  return this.fb.group({
199
  name: [param.name || '', [Validators.required, Validators.pattern(/^[a-zA-Z0-9_]+$/)]],
 
122
  loadVersion(version: Version) {
123
  this.selectedVersion = version;
124
 
125
+ // Reset form to initial state
126
+ this.initializeForm();
127
+
128
+ // Populate basic fields
 
 
 
129
  this.versionForm.patchValue({
130
  id: version.id,
131
  caption: version.caption,
 
146
  });
147
 
148
  // Populate intents
149
+ const intentsArray = this.versionForm.get('intents') as FormArray;
150
  if (version.intents) {
151
  version.intents.forEach(intent => {
152
+ const intentFormGroup = this.createIntentFormGroup(intent);
153
+
154
+ // Parameters'ı ayrı olarak ekle
155
+ if (intent.parameters) {
156
+ this.populateIntentParameters(intentFormGroup, intent.parameters);
157
+ }
158
+
159
+ intentsArray.push(intentFormGroup);
160
  });
161
  }
162
 
 
172
  }
173
 
174
  createIntentFormGroup(intent: any = {}): FormGroup {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  return this.fb.group({
176
  name: [intent.name || '', [Validators.required, Validators.pattern(/^[a-zA-Z0-9-]+$/)]],
177
  caption: [intent.caption || ''],
178
  locale: [intent.locale || 'tr-TR'],
179
  detection_prompt: [intent.detection_prompt || '', Validators.required],
180
+ examples: this.fb.array(intent.examples || []),
181
+ parameters: this.fb.array([]), // Boş array ile başla
182
  action: [intent.action || '', Validators.required],
183
  fallback_timeout_prompt: [intent.fallback_timeout_prompt || ''],
184
  fallback_error_prompt: [intent.fallback_error_prompt || '']
185
  });
186
  }
187
 
188
+ private populateIntentParameters(intentFormGroup: FormGroup, parameters: any[]) {
189
+ const parametersArray = intentFormGroup.get('parameters') as FormArray;
190
+ parameters.forEach(param => {
191
+ parametersArray.push(this.createParameterFormGroup(param));
192
+ });
193
+ }
194
+
195
  createParameterFormGroup(param: any = {}): FormGroup {
196
  return this.fb.group({
197
  name: [param.name || '', [Validators.required, Validators.pattern(/^[a-zA-Z0-9_]+$/)]],