Spaces:
Running
Running
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
@@ -47,6 +47,7 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
47 |
testRequestJson = '{}';
|
48 |
allIntentParameters: { name: string; type: string }[] = [];
|
49 |
responseMappingVariables: { name: string; type: string }[] = [];
|
|
|
50 |
|
51 |
httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
52 |
retryStrategies = ['static', 'exponential'];
|
@@ -67,7 +68,12 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
67 |
this.initializeForm();
|
68 |
this.loadIntentParameters();
|
69 |
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
this.populateForm(this.data.api);
|
72 |
} else if (this.data.mode === 'duplicate' && this.data.api) {
|
73 |
const duplicateData = { ...this.data.api };
|
@@ -76,12 +82,82 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
76 |
this.populateForm(duplicateData);
|
77 |
}
|
78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
// Watch response mappings changes
|
80 |
this.form.get('response_mappings')?.valueChanges.subscribe(() => {
|
81 |
this.updateResponseMappingVariables();
|
82 |
});
|
83 |
}
|
84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
initializeForm() {
|
86 |
this.form = this.fb.group({
|
87 |
// General Tab
|
@@ -598,6 +674,11 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
598 |
}
|
599 |
|
600 |
async save() {
|
|
|
|
|
|
|
|
|
|
|
601 |
if (this.form.invalid) {
|
602 |
// Mark all fields as touched to show validation errors
|
603 |
Object.keys(this.form.controls).forEach(key => {
|
|
|
47 |
testRequestJson = '{}';
|
48 |
allIntentParameters: { name: string; type: string }[] = [];
|
49 |
responseMappingVariables: { name: string; type: string }[] = [];
|
50 |
+
activeTabIndex = 0;
|
51 |
|
52 |
httpMethods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];
|
53 |
retryStrategies = ['static', 'exponential'];
|
|
|
68 |
this.initializeForm();
|
69 |
this.loadIntentParameters();
|
70 |
|
71 |
+
// Aktif tab'ı ayarla
|
72 |
+
if (this.data.activeTab !== undefined) {
|
73 |
+
this.activeTabIndex = this.data.activeTab;
|
74 |
+
}
|
75 |
+
|
76 |
+
if ((this.data.mode === 'edit' || this.data.mode === 'test') && this.data.api) {
|
77 |
this.populateForm(this.data.api);
|
78 |
} else if (this.data.mode === 'duplicate' && this.data.api) {
|
79 |
const duplicateData = { ...this.data.api };
|
|
|
82 |
this.populateForm(duplicateData);
|
83 |
}
|
84 |
|
85 |
+
// Test modunda açıldıysa test JSON'ını hazırla
|
86 |
+
if (this.data.mode === 'test') {
|
87 |
+
setTimeout(() => {
|
88 |
+
this.updateTestRequestJson();
|
89 |
+
}, 100);
|
90 |
+
}
|
91 |
+
|
92 |
// Watch response mappings changes
|
93 |
this.form.get('response_mappings')?.valueChanges.subscribe(() => {
|
94 |
this.updateResponseMappingVariables();
|
95 |
});
|
96 |
}
|
97 |
|
98 |
+
populateForm(api: any) {
|
99 |
+
console.log('Populating form with API:', api); // Debug için
|
100 |
+
|
101 |
+
// Convert headers object to FormArray
|
102 |
+
const headersArray = this.form.get('headers') as FormArray;
|
103 |
+
headersArray.clear();
|
104 |
+
|
105 |
+
if (api.headers) {
|
106 |
+
// ✅ Array veya Object olabilir, kontrol edelim
|
107 |
+
if (Array.isArray(api.headers)) {
|
108 |
+
// Eğer array ise direkt kullan
|
109 |
+
api.headers.forEach((header: any) => {
|
110 |
+
headersArray.push(this.createHeaderFormGroup(header.key || '', header.value || ''));
|
111 |
+
});
|
112 |
+
} else if (typeof api.headers === 'object') {
|
113 |
+
// Eğer object ise entries ile dönüştür
|
114 |
+
Object.entries(api.headers).forEach(([key, value]) => {
|
115 |
+
headersArray.push(this.createHeaderFormGroup(key, value as string));
|
116 |
+
});
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
// Convert response_mappings to FormArray
|
121 |
+
const responseMappingsArray = this.form.get('response_mappings') as FormArray;
|
122 |
+
responseMappingsArray.clear();
|
123 |
+
|
124 |
+
if (api.response_mappings && Array.isArray(api.response_mappings)) {
|
125 |
+
api.response_mappings.forEach((mapping: any) => {
|
126 |
+
responseMappingsArray.push(this.createResponseMappingFormGroup(mapping));
|
127 |
+
});
|
128 |
+
}
|
129 |
+
|
130 |
+
// Convert body_template to JSON string if it's an object
|
131 |
+
if (api.body_template && typeof api.body_template === 'object') {
|
132 |
+
api.body_template = JSON.stringify(api.body_template, null, 2);
|
133 |
+
}
|
134 |
+
|
135 |
+
// Convert auth bodies to JSON strings
|
136 |
+
if (api.auth) {
|
137 |
+
if (api.auth.token_request_body && typeof api.auth.token_request_body === 'object') {
|
138 |
+
api.auth.token_request_body = JSON.stringify(api.auth.token_request_body, null, 2);
|
139 |
+
}
|
140 |
+
if (api.auth.token_refresh_body && typeof api.auth.token_refresh_body === 'object') {
|
141 |
+
api.auth.token_refresh_body = JSON.stringify(api.auth.token_refresh_body, null, 2);
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
// ✅ patchValue'dan önce form değerlerini düzelt
|
146 |
+
const formData = { ...api };
|
147 |
+
|
148 |
+
// headers array'ini kaldır çünkü zaten FormArray'e ekledik
|
149 |
+
delete formData.headers;
|
150 |
+
delete formData.response_mappings;
|
151 |
+
|
152 |
+
// Patch form values
|
153 |
+
this.form.patchValue(formData);
|
154 |
+
|
155 |
+
// Disable name field if editing or testing
|
156 |
+
if (this.data.mode === 'edit' || this.data.mode === 'test') {
|
157 |
+
this.form.get('name')?.disable();
|
158 |
+
}
|
159 |
+
}
|
160 |
+
|
161 |
initializeForm() {
|
162 |
this.form = this.fb.group({
|
163 |
// General Tab
|
|
|
674 |
}
|
675 |
|
676 |
async save() {
|
677 |
+
if (this.data.mode === 'test') {
|
678 |
+
this.cancel();
|
679 |
+
return;
|
680 |
+
}
|
681 |
+
|
682 |
if (this.form.invalid) {
|
683 |
// Mark all fields as touched to show validation errors
|
684 |
Object.keys(this.form.controls).forEach(key => {
|