format code

This commit is contained in:
anovazzi1 2024-06-27 12:28:54 -03:00 • committed by Gabriel Luiz Freitas Almeida
commit b0e7be8de4
9 changed files with 41 additions and 24 deletions

View file

@ -864,4 +864,10 @@ export const TITLE_ERROR_UPDATING_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"] export const TABS_ORDER = [
"run curl",
"python api",
"js api",
"python code",
"chat widget html",
];

View file

@ -18,16 +18,16 @@ 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";
import getTabsOrder from "./utils/get-tabs-order";
import getCodesObj from "./utils/get-codes-obj";
const ApiModal = forwardRef( const ApiModal = forwardRef(
( (
@ -222,17 +222,19 @@ const ApiModal = forwardRef(
pythonApiCode, pythonApiCode,
jsApiCode, jsApiCode,
pythonCode, pythonCode,
widgetCode widgetCode,
}) });
const tabsOrder = getTabsOrder(includeWebhook, isThereTweaks); const tabsOrder = getTabsOrder(includeWebhook, isThereTweaks);
if (tabs && tabs?.length > 0) { if (tabs && tabs?.length > 0) {
tabs.forEach((tab, idx) => { tabs.forEach((tab, idx) => {
const order = tabsOrder[idx]; const order = tabsOrder[idx];
if (order && order.toLowerCase() === tab.name.toLowerCase()) { if (order && order.toLowerCase() === tab.name.toLowerCase()) {
const codeToFind = codesObj.find(c => c.name.toLowerCase() === tab.name.toLowerCase()); const codeToFind = codesObj.find(
(c) => c.name.toLowerCase() === tab.name.toLowerCase(),
);
tab.code = codeToFind?.code; tab.code = codeToFind?.code;
} }
}) });
} }
}; };

View file

@ -1,4 +1,7 @@
import { getCodesObjProps, getCodesObjReturn } from "../../../types/utils/functions"; import {
getCodesObjProps,
getCodesObjReturn,
} from "../../../types/utils/functions";
export default function getCodesObj({ export default function getCodesObj({
runCurlCode, runCurlCode,
@ -33,5 +36,5 @@ export default function getCodesObj({
name: "chat widget html", name: "chat widget html",
code: widgetCode, code: widgetCode,
}, },
] ];
} }

View file

@ -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|null) { 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

View file

@ -1,6 +1,9 @@
import { TABS_ORDER } from "../../../constants/constants"; import { TABS_ORDER } from "../../../constants/constants";
export default function getTabsOrder(isThereWH: boolean = false, isThereTweaks: boolean = false): string[] { export default function getTabsOrder(
isThereWH: boolean = false,
isThereTweaks: boolean = false,
): string[] {
const defaultOrder = TABS_ORDER; const defaultOrder = TABS_ORDER;
if (isThereTweaks) { if (isThereTweaks) {
defaultOrder.push("tweaks"); defaultOrder.push("tweaks");

View file

@ -1,11 +1,10 @@
export function export function createTabsArray(
createTabsArray(
codes, codes,
includeWebhookCurl = false, includeWebhookCurl = false,
includeTweaks = false, includeTweaks = false,
) { ) {
// console.log(includeTweaks) // console.log(includeTweaks)
console.log(includeWebhookCurl) console.log(includeWebhookCurl);
const tabs = [ const tabs = [
{ {
name: "Run cURL", name: "Run cURL",

View file

@ -1,10 +1,10 @@
export type getCodesObjProps = { export type getCodesObjProps = {
runCurlCode: string, runCurlCode: string;
webhookCurlCode: string, webhookCurlCode: string;
pythonApiCode: string, pythonApiCode: string;
jsApiCode: string, jsApiCode: string;
pythonCode: string, pythonCode: string;
widgetCode: string, widgetCode: string;
}; };
export type getCodesObjReturn = Array<{name: string; code: string;}> export type getCodesObjReturn = Array<{ name: string; code: string }>;