Merge branch 'dev' into cherry_pick_tracer
This commit is contained in:
commit
a2404628f0
9 changed files with 104 additions and 18 deletions
|
|
@ -863,3 +863,11 @@ export const TITLE_ERROR_UPDATING_COMPONENT =
|
||||||
"Error while updating the Component";
|
"Error while updating the Component";
|
||||||
|
|
||||||
export const EMPTY_INPUT_SEND_MESSAGE = "No input message provided.";
|
export const EMPTY_INPUT_SEND_MESSAGE = "No input message provided.";
|
||||||
|
|
||||||
|
export const TABS_ORDER = [
|
||||||
|
"run curl",
|
||||||
|
"python api",
|
||||||
|
"js api",
|
||||||
|
"python code",
|
||||||
|
"chat widget html",
|
||||||
|
];
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,13 @@ import { buildContent } from "./utils/build-content";
|
||||||
import { buildTweaks } from "./utils/build-tweaks";
|
import { buildTweaks } from "./utils/build-tweaks";
|
||||||
import { checkCanBuildTweakObject } from "./utils/check-can-build-tweak-object";
|
import { checkCanBuildTweakObject } from "./utils/check-can-build-tweak-object";
|
||||||
import { getChangesType } from "./utils/get-changes-types";
|
import { getChangesType } from "./utils/get-changes-types";
|
||||||
|
import getCodesObj from "./utils/get-codes-obj";
|
||||||
import { getCurlRunCode, getCurlWebhookCode } from "./utils/get-curl-code";
|
import { getCurlRunCode, getCurlWebhookCode } from "./utils/get-curl-code";
|
||||||
import getJsApiCode from "./utils/get-js-api-code";
|
import getJsApiCode from "./utils/get-js-api-code";
|
||||||
import { getNodesWithDefaultValue } from "./utils/get-nodes-with-default-value";
|
import { getNodesWithDefaultValue } from "./utils/get-nodes-with-default-value";
|
||||||
import getPythonApiCode from "./utils/get-python-api-code";
|
import getPythonApiCode from "./utils/get-python-api-code";
|
||||||
import getPythonCode from "./utils/get-python-code";
|
import getPythonCode from "./utils/get-python-code";
|
||||||
|
import getTabsOrder from "./utils/get-tabs-order";
|
||||||
import { getValue } from "./utils/get-value";
|
import { getValue } from "./utils/get-value";
|
||||||
import getWidgetCode from "./utils/get-widget-code";
|
import getWidgetCode from "./utils/get-widget-code";
|
||||||
import { createTabsArray } from "./utils/tabs-array";
|
import { createTabsArray } from "./utils/tabs-array";
|
||||||
|
|
@ -213,21 +215,26 @@ const ApiModal = forwardRef(
|
||||||
);
|
);
|
||||||
const pythonCode = getPythonCode(flow?.name, cloneTweak);
|
const pythonCode = getPythonCode(flow?.name, cloneTweak);
|
||||||
const widgetCode = getWidgetCode(flow?.id, flow?.name, autoLogin);
|
const widgetCode = getWidgetCode(flow?.id, flow?.name, autoLogin);
|
||||||
|
const isThereTweaks = Object.keys(tweaksCode).length > 0;
|
||||||
|
const codesObj = getCodesObj({
|
||||||
|
runCurlCode,
|
||||||
|
webhookCurlCode,
|
||||||
|
pythonApiCode,
|
||||||
|
jsApiCode,
|
||||||
|
pythonCode,
|
||||||
|
widgetCode,
|
||||||
|
});
|
||||||
|
const tabsOrder = getTabsOrder(includeWebhook, isThereTweaks);
|
||||||
if (tabs && tabs?.length > 0) {
|
if (tabs && tabs?.length > 0) {
|
||||||
let i = 0;
|
tabs.forEach((tab, idx) => {
|
||||||
tabs![i].code = runCurlCode;
|
const order = tabsOrder[idx];
|
||||||
i++;
|
if (order && order.toLowerCase() === tab.name.toLowerCase()) {
|
||||||
if (includeWebhook) {
|
const codeToFind = codesObj.find(
|
||||||
tabs![i].code = webhookCurlCode;
|
(c) => c.name.toLowerCase() === tab.name.toLowerCase(),
|
||||||
i++;
|
);
|
||||||
|
tab.code = codeToFind?.code;
|
||||||
}
|
}
|
||||||
tabs![i].code = pythonApiCode;
|
});
|
||||||
i++;
|
|
||||||
tabs![i].code = jsApiCode;
|
|
||||||
i++;
|
|
||||||
tabs![i].code = pythonCode;
|
|
||||||
i++;
|
|
||||||
tabs![i].code = widgetCode;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
40
src/frontend/src/modals/apiModal/utils/get-codes-obj.tsx
Normal file
40
src/frontend/src/modals/apiModal/utils/get-codes-obj.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
import {
|
||||||
|
getCodesObjProps,
|
||||||
|
getCodesObjReturn,
|
||||||
|
} from "../../../types/utils/functions";
|
||||||
|
|
||||||
|
export default function getCodesObj({
|
||||||
|
runCurlCode,
|
||||||
|
webhookCurlCode,
|
||||||
|
pythonApiCode,
|
||||||
|
jsApiCode,
|
||||||
|
pythonCode,
|
||||||
|
widgetCode,
|
||||||
|
}: getCodesObjProps): getCodesObjReturn {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
name: "run curl",
|
||||||
|
code: runCurlCode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "webhook curl",
|
||||||
|
code: webhookCurlCode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "python api",
|
||||||
|
code: pythonApiCode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "js api",
|
||||||
|
code: jsApiCode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "python code",
|
||||||
|
code: pythonCode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "chat widget html",
|
||||||
|
code: widgetCode,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -8,7 +8,7 @@ export function getCurlRunCode(
|
||||||
flowId: string,
|
flowId: string,
|
||||||
isAuth: boolean,
|
isAuth: boolean,
|
||||||
tweaksBuildedObject,
|
tweaksBuildedObject,
|
||||||
endpointName?: string,
|
endpointName?: string | null,
|
||||||
): string {
|
): string {
|
||||||
const tweaksObject = tweaksBuildedObject[0];
|
const tweaksObject = tweaksBuildedObject[0];
|
||||||
// show the endpoint name in the curl command if it exists
|
// show the endpoint name in the curl command if it exists
|
||||||
|
|
@ -35,7 +35,11 @@ export function getCurlRunCode(
|
||||||
* @param {string} options.endpointName - The name of the webhook endpoint.
|
* @param {string} options.endpointName - The name of the webhook endpoint.
|
||||||
* @returns {string} The cURL command.
|
* @returns {string} The cURL command.
|
||||||
*/
|
*/
|
||||||
export function getCurlWebhookCode(flowId, isAuth, endpointName?: string) {
|
export function getCurlWebhookCode(
|
||||||
|
flowId,
|
||||||
|
isAuth,
|
||||||
|
endpointName?: string | null,
|
||||||
|
) {
|
||||||
return `curl -X POST \\
|
return `curl -X POST \\
|
||||||
"${window.location.protocol}//${window.location.host}/api/v1/webhook/${
|
"${window.location.protocol}//${window.location.host}/api/v1/webhook/${
|
||||||
endpointName || flowId
|
endpointName || flowId
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export default function getJsApiCode(
|
||||||
flowId: string,
|
flowId: string,
|
||||||
isAuth: boolean,
|
isAuth: boolean,
|
||||||
tweaksBuildedObject: any[],
|
tweaksBuildedObject: any[],
|
||||||
endpointName?: string,
|
endpointName?: string | null,
|
||||||
): string {
|
): string {
|
||||||
let tweaksString = "{}";
|
let tweaksString = "{}";
|
||||||
if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
|
if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ export default function getPythonApiCode(
|
||||||
flowId: string,
|
flowId: string,
|
||||||
isAuth: boolean,
|
isAuth: boolean,
|
||||||
tweaksBuildedObject: any[],
|
tweaksBuildedObject: any[],
|
||||||
endpointName?: string,
|
endpointName?: string | null,
|
||||||
): string {
|
): string {
|
||||||
let tweaksString = "{}";
|
let tweaksString = "{}";
|
||||||
if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
|
if (tweaksBuildedObject && tweaksBuildedObject.length > 0) {
|
||||||
|
|
|
||||||
15
src/frontend/src/modals/apiModal/utils/get-tabs-order.tsx
Normal file
15
src/frontend/src/modals/apiModal/utils/get-tabs-order.tsx
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { TABS_ORDER } from "../../../constants/constants";
|
||||||
|
|
||||||
|
export default function getTabsOrder(
|
||||||
|
isThereWH: boolean = false,
|
||||||
|
isThereTweaks: boolean = false,
|
||||||
|
): string[] {
|
||||||
|
const defaultOrder = TABS_ORDER;
|
||||||
|
if (isThereTweaks) {
|
||||||
|
defaultOrder.push("tweaks");
|
||||||
|
}
|
||||||
|
if (isThereWH) {
|
||||||
|
defaultOrder.splice(1, 0, "webhook curl");
|
||||||
|
}
|
||||||
|
return defaultOrder;
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,8 @@ export function createTabsArray(
|
||||||
includeWebhookCurl = false,
|
includeWebhookCurl = false,
|
||||||
includeTweaks = false,
|
includeTweaks = false,
|
||||||
) {
|
) {
|
||||||
|
// console.log(includeTweaks)
|
||||||
|
console.log(includeWebhookCurl);
|
||||||
const tabs = [
|
const tabs = [
|
||||||
{
|
{
|
||||||
name: "Run cURL",
|
name: "Run cURL",
|
||||||
|
|
|
||||||
10
src/frontend/src/types/utils/functions.ts
Normal file
10
src/frontend/src/types/utils/functions.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
export type getCodesObjProps = {
|
||||||
|
runCurlCode: string;
|
||||||
|
webhookCurlCode: string;
|
||||||
|
pythonApiCode: string;
|
||||||
|
jsApiCode: string;
|
||||||
|
pythonCode: string;
|
||||||
|
widgetCode: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type getCodesObjReturn = Array<{ name: string; code: string }>;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue