ciyidogan commited on
Commit
c467e9b
·
verified ·
1 Parent(s): 1c7c998

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

Browse files
flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.ts CHANGED
@@ -136,32 +136,43 @@ export default class ApiEditDialogComponent implements OnInit {
136
  }
137
 
138
  populateForm(api: any) {
 
 
139
  // Convert headers object to FormArray
140
  const headersArray = this.form.get('headers') as FormArray;
141
  headersArray.clear();
142
-
143
- if (api.headers && typeof api.headers === 'object') {
144
- Object.entries(api.headers).forEach(([key, value]) => {
145
- headersArray.push(this.createHeaderFormGroup(key, value as string));
146
- });
 
 
 
 
 
 
 
 
 
147
  }
148
-
149
  // Convert response_mappings to FormArray
150
  const responseMappingsArray = this.form.get('response_mappings') as FormArray;
151
  responseMappingsArray.clear();
152
-
153
  if (api.response_mappings && Array.isArray(api.response_mappings)) {
154
  api.response_mappings.forEach((mapping: any) => {
155
  responseMappingsArray.push(this.createResponseMappingFormGroup(mapping));
156
  });
157
  }
158
-
159
  // Convert body_template to JSON string if it's an object
160
  if (api.body_template && typeof api.body_template === 'object') {
161
  api.body_template = JSON.stringify(api.body_template, null, 2);
162
  }
163
-
164
- // Convert auth bodies to JSON strings
165
  if (api.auth) {
166
  if (api.auth.token_request_body && typeof api.auth.token_request_body === 'object') {
167
  api.auth.token_request_body = JSON.stringify(api.auth.token_request_body, null, 2);
@@ -170,10 +181,17 @@ export default class ApiEditDialogComponent implements OnInit {
170
  api.auth.token_refresh_body = JSON.stringify(api.auth.token_refresh_body, null, 2);
171
  }
172
  }
173
-
 
 
 
 
 
 
 
174
  // Patch form values
175
- this.form.patchValue(api);
176
-
177
  // Disable name field if editing
178
  if (this.data.mode === 'edit') {
179
  this.form.get('name')?.disable();
 
136
  }
137
 
138
  populateForm(api: any) {
139
+ console.log('Populating form with API:', api); // Debug için
140
+
141
  // Convert headers object to FormArray
142
  const headersArray = this.form.get('headers') as FormArray;
143
  headersArray.clear();
144
+
145
+ if (api.headers) {
146
+ // ✅ Array veya Object olabilir, kontrol edelim
147
+ if (Array.isArray(api.headers)) {
148
+ // Eğer array ise direkt kullan
149
+ api.headers.forEach((header: any) => {
150
+ headersArray.push(this.createHeaderFormGroup(header.key || '', header.value || ''));
151
+ });
152
+ } else if (typeof api.headers === 'object') {
153
+ // Eğer object ise entries ile dönüştür
154
+ Object.entries(api.headers).forEach(([key, value]) => {
155
+ headersArray.push(this.createHeaderFormGroup(key, value as string));
156
+ });
157
+ }
158
  }
159
+
160
  // Convert response_mappings to FormArray
161
  const responseMappingsArray = this.form.get('response_mappings') as FormArray;
162
  responseMappingsArray.clear();
163
+
164
  if (api.response_mappings && Array.isArray(api.response_mappings)) {
165
  api.response_mappings.forEach((mapping: any) => {
166
  responseMappingsArray.push(this.createResponseMappingFormGroup(mapping));
167
  });
168
  }
169
+
170
  // Convert body_template to JSON string if it's an object
171
  if (api.body_template && typeof api.body_template === 'object') {
172
  api.body_template = JSON.stringify(api.body_template, null, 2);
173
  }
174
+
175
+ // Convert auth bodies to JSON strings
176
  if (api.auth) {
177
  if (api.auth.token_request_body && typeof api.auth.token_request_body === 'object') {
178
  api.auth.token_request_body = JSON.stringify(api.auth.token_request_body, null, 2);
 
181
  api.auth.token_refresh_body = JSON.stringify(api.auth.token_refresh_body, null, 2);
182
  }
183
  }
184
+
185
+ // ✅ patchValue'dan önce form değerlerini düzelt
186
+ const formData = { ...api };
187
+
188
+ // headers array'ini kaldır çünkü zaten FormArray'e ekledik
189
+ delete formData.headers;
190
+ delete formData.response_mappings;
191
+
192
  // Patch form values
193
+ this.form.patchValue(formData);
194
+
195
  // Disable name field if editing
196
  if (this.data.mode === 'edit') {
197
  this.form.get('name')?.disable();