Skip to content

Commit 57dba08

Browse files
authored
Merge pull request #906 from 1AhmedYasser/Bug-Assign-shows-BAD-REQUEST-pills-for-valid-stat.ee
Fix: Assign shows BAD REQUEST pills for valid stat.ee
2 parents ac1372d + e23c889 commit 57dba08

3 files changed

Lines changed: 37 additions & 49 deletions

File tree

GUI/src/components/FlowElementsPopup/index.tsx

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, { useEffect, useMemo, useState } from 'react';
44
import { DndProvider } from 'react-dnd';
55
import { HTML5Backend } from 'react-dnd-html5-backend';
66
import { useTranslation } from 'react-i18next';
7-
import useServiceStore from 'store/new-services.store';
7+
import useServiceStore, { extractMapValues, getEndpointBody } from 'store/new-services.store';
88
import useServiceListStore from 'store/services.store';
99
import useToastStore from 'store/toasts.store';
1010
import { DynamicChoices } from 'types/dynamic-choices';
@@ -318,7 +318,7 @@ const FlowElementsPopup: React.FC = () => {
318318
url: endpoint.url,
319319
method: endpoint.methodType,
320320
headers: extractMapValues(endpoint.headers),
321-
body: extractMapValues(endpoint.body),
321+
body: getEndpointBody(endpoint),
322322
params: extractMapValues(endpoint.params),
323323
},
324324
],
@@ -330,20 +330,6 @@ const FlowElementsPopup: React.FC = () => {
330330
}
331331
};
332332

333-
function extractMapValues(element: any) {
334-
if (element?.rawData && element?.rawData?.length > 0) {
335-
return element.rawData.value;
336-
}
337-
338-
let result: any = {};
339-
if (element?.variables) {
340-
for (const entry of element.variables) {
341-
result = { ...result, [entry.name]: entry.value };
342-
}
343-
}
344-
return result;
345-
}
346-
347333
const getJsonRequestButtonTitle = () => {
348334
if (!isUserDefinedNode || selectedTab === t('serviceFlow.tabs.test')) return '';
349335
if (isJsonRequestVisible) return t('serviceFlow.popup.hideJsonRequest');

GUI/src/store/new-services.store.ts

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ import { saveFlowClick } from 'services/service-builder';
2626
import { EndpointDefinitionJson, Service, ServiceState, Step, StepType } from 'types';
2727
import { Assign } from 'types/assign';
2828
import { Chip } from 'types/chip';
29-
import { EndpointData, EndpointEnv, EndpointTab, PreDefinedEndpointEnvVariables } from 'types/endpoint';
29+
import {
30+
EndpointData,
31+
EndpointDefinition,
32+
EndpointEnv,
33+
EndpointTab,
34+
PreDefinedEndpointEnvVariables,
35+
} from 'types/endpoint';
3036
import { EndpointResponseVariable } from 'types/endpoint/endpoint-response-variables';
3137
import { EndpointType } from 'types/endpoint/endpoint-type';
3238
import { RequestVariablesTabsRawData, RequestVariablesTabsRowsData } from 'types/request-variables';
@@ -259,7 +265,7 @@ const useServiceStore = create<ServiceStoreState>((set, get) => ({
259265
url: endpoint.url,
260266
method: endpoint.methodType,
261267
headers: extractMapValues(endpoint.headers),
262-
body: extractMapValues(endpoint.body),
268+
body: getEndpointBody(endpoint),
263269
params: extractMapValues(endpoint.params),
264270
})),
265271
);
@@ -282,6 +288,12 @@ const useServiceStore = create<ServiceStoreState>((set, get) => ({
282288
});
283289
}
284290

291+
chips.push({
292+
name: 'Base Response',
293+
value: `${endpoint?.name.replaceAll(' ', '_')}_res.response.body`,
294+
data: `${endpoint?.name.replaceAll(' ', '_')}_res.response.body`,
295+
});
296+
285297
chips.push({
286298
name: 'Status Code',
287299
value: `${endpoint?.name.replaceAll(' ', '_')}_res.response.statusCodeValue`,
@@ -915,7 +927,24 @@ const useServiceStore = create<ServiceStoreState>((set, get) => ({
915927
canRedo: () => get().historyIndex < get().history.length - 1,
916928
}));
917929

918-
function extractMapValues(element: any) {
930+
export function getEndpointBody(endpoint: EndpointDefinition): any {
931+
const isRawBodySelected = endpoint?.body?.isRawSelected ?? false;
932+
const rawBody = endpoint?.body?.rawData ?? {};
933+
let body: any = extractMapValues(endpoint.body);
934+
935+
if (isRawBodySelected) {
936+
try {
937+
const rawJson = JSON.parse(rawBody?.value ?? '');
938+
body = rawJson;
939+
} catch (e: any) {
940+
body = extractMapValues(endpoint.body);
941+
console.log(`Unable to save JSON to Yaml. ${e.message}`);
942+
}
943+
}
944+
return body;
945+
}
946+
947+
export function extractMapValues(element: any) {
919948
if (!element) return {};
920949

921950
if (element.rawData && element.rawData.length > 0) {

GUI/src/utils/json-request-utils.ts

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,18 @@
1+
import { extractMapValues, getEndpointBody } from 'store/new-services.store';
2+
13
import { servicesRequestsExplain } from '../resources/api-constants';
24
import api from '../services/api-dev';
35
import { EndpointDefinition } from '../types/endpoint';
46

5-
export const extractMapValues = (element: any) => {
6-
if (element?.rawData && element?.rawData?.length > 0) {
7-
return element.rawData.value;
8-
}
9-
10-
let result: any = {};
11-
if (element?.variables) {
12-
for (const entry of element.variables) {
13-
result = { ...result, [entry.name]: entry.value };
14-
}
15-
}
16-
return result;
17-
};
18-
197
export const generateJsonRequest = async (endpoint: EndpointDefinition) => {
208
try {
21-
console.log('Generating JSON request for endpoint: ', endpoint);
22-
const isRawBodySelected = endpoint?.body?.isRawSelected ?? false;
23-
const rawBody = endpoint?.body?.rawData ?? {};
24-
let body: any = extractMapValues(endpoint.body);
25-
26-
if (isRawBodySelected) {
27-
try {
28-
const rawJson = JSON.parse(rawBody?.value ?? '');
29-
body = rawJson;
30-
} catch (e: any) {
31-
body = extractMapValues(endpoint.body);
32-
console.log(`Unable to save JSON to Yaml. ${e.message}`);
33-
}
34-
}
35-
369
const response = await api.post(servicesRequestsExplain(), {
3710
requests: [
3811
{
3912
url: endpoint.url,
4013
method: endpoint.methodType,
4114
headers: extractMapValues(endpoint.headers),
42-
body: body,
15+
body: getEndpointBody(endpoint),
4316
params: extractMapValues(endpoint.params),
4417
},
4518
],

0 commit comments

Comments
 (0)