Refactor: move getWidgetCode to apiModal folder
This commit is contained in:
parent
69f3b16fb7
commit
5850634c04
3 changed files with 25 additions and 26 deletions
24
src/frontend/src/modals/apiModal/utils/get-widget-code.tsx
Normal file
24
src/frontend/src/modals/apiModal/utils/get-widget-code.tsx
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
* Function to get the widget code for the API
|
||||||
|
* @param {string} flow - The current flow.
|
||||||
|
* @returns {string} - The widget code
|
||||||
|
*/
|
||||||
|
export default function getWidgetCode(
|
||||||
|
flowId: string,
|
||||||
|
flowName: string,
|
||||||
|
isAuth: boolean,
|
||||||
|
): string {
|
||||||
|
return `<script src="https://cdn.jsdelivr.net/gh/langflow-ai/langflow-embedded-chat@1.0_alpha/dist/build/static/js/bundle.min.js"></script>
|
||||||
|
|
||||||
|
<langflow-chat
|
||||||
|
window_title="${flowName}"
|
||||||
|
flow_id="${flowId}"
|
||||||
|
host_url="http://localhost:7860"${
|
||||||
|
!isAuth
|
||||||
|
? `
|
||||||
|
api_key="..."`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
></langflow-chat>`;
|
||||||
|
}
|
||||||
|
|
@ -14,7 +14,6 @@ import { TemplateVariableType } from "../../../types/api";
|
||||||
import { uniqueTweakType } from "../../../types/components";
|
import { uniqueTweakType } from "../../../types/components";
|
||||||
import { FlowType } from "../../../types/flow/index";
|
import { FlowType } from "../../../types/flow/index";
|
||||||
import {
|
import {
|
||||||
getWidgetCode,
|
|
||||||
tabsArray,
|
tabsArray,
|
||||||
} from "../../../utils/utils";
|
} from "../../../utils/utils";
|
||||||
import BaseModal from "../../baseModal";
|
import BaseModal from "../../baseModal";
|
||||||
|
|
@ -27,6 +26,7 @@ import { getValue } from "../utils/get-value";
|
||||||
import getPythonApiCode from "../utils/get-python-api-code";
|
import getPythonApiCode from "../utils/get-python-api-code";
|
||||||
import getCurlCode from "../utils/get-curl-code";
|
import getCurlCode from "../utils/get-curl-code";
|
||||||
import getPythonCode from "../utils/get-python-code";
|
import getPythonCode from "../utils/get-python-code";
|
||||||
|
import getWidgetCode from "../utils/get-widget-code";
|
||||||
|
|
||||||
const ApiModal = forwardRef(
|
const ApiModal = forwardRef(
|
||||||
(
|
(
|
||||||
|
|
|
||||||
|
|
@ -158,31 +158,6 @@ export function getOutputIds(flow) {
|
||||||
return arrayOfOutputsJoin;
|
return arrayOfOutputsJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the widget code for the API
|
|
||||||
* @param {string} flow - The current flow.
|
|
||||||
* @returns {string} - The widget code
|
|
||||||
*/
|
|
||||||
export function getWidgetCode(
|
|
||||||
flowId: string,
|
|
||||||
flowName: string,
|
|
||||||
isAuth: boolean,
|
|
||||||
): string {
|
|
||||||
return `<script src="https://cdn.jsdelivr.net/gh/langflow-ai/langflow-embedded-chat@1.0_alpha/dist/build/static/js/bundle.min.js"></script>
|
|
||||||
|
|
||||||
<langflow-chat
|
|
||||||
window_title="${flowName}"
|
|
||||||
flow_id="${flowId}"
|
|
||||||
host_url="http://localhost:7860"${
|
|
||||||
!isAuth
|
|
||||||
? `
|
|
||||||
api_key="..."`
|
|
||||||
: ""
|
|
||||||
}
|
|
||||||
|
|
||||||
></langflow-chat>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function truncateLongId(id: string): string {
|
export function truncateLongId(id: string): string {
|
||||||
let [componentName, newId] = id.split("-");
|
let [componentName, newId] = id.split("-");
|
||||||
if (componentName.length > 15) {
|
if (componentName.length > 15) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue