{
const [edges, setEdges, onEdgesChange] = useEdgesState()
const [selectedNode, setSelectedNode] = useState(null)
+ const [isUpsertButtonEnabled, setIsUpsertButtonEnabled] = useState(false)
const reactFlowWrapper = useRef(null)
@@ -167,6 +169,7 @@ const Canvas = () => {
if (isConfirmed) {
try {
await chatflowsApi.deleteChatflow(chatflow.id)
+ localStorage.removeItem(`${chatflow.id}_INTERNAL`)
navigate(-1)
} catch (error) {
const errorData = error.response.data || `${error.response.status}: ${error.response.statusText}`
@@ -339,6 +342,12 @@ const Canvas = () => {
dispatch({ type: SET_DIRTY })
}
+ const checkIfUpsertAvailable = (nodes, edges) => {
+ const upsertNodeDetails = getUpsertDetails(nodes, edges)
+ if (upsertNodeDetails.length) setIsUpsertButtonEnabled(true)
+ else setIsUpsertButtonEnabled(false)
+ }
+
// ==============================|| useEffect ||============================== //
// Get specific chatflow successful
@@ -409,7 +418,13 @@ const Canvas = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [testChatflowApi.error])
- useEffect(() => setChatflow(canvasDataStore.chatflow), [canvasDataStore.chatflow])
+ useEffect(() => {
+ setChatflow(canvasDataStore.chatflow)
+ if (canvasDataStore.chatflow) {
+ const flowData = canvasDataStore.chatflow.flowData ? JSON.parse(canvasDataStore.chatflow.flowData) : []
+ checkIfUpsertAvailable(flowData.nodes || [], flowData.edges || [])
+ }
+ }, [canvasDataStore.chatflow])
// Initialization
useEffect(() => {
@@ -524,6 +539,7 @@ const Canvas = () => {
/>
+ {isUpsertButtonEnabled &&
}
diff --git a/packages/ui/src/views/chatflows/APICodeDialog.js b/packages/ui/src/views/chatflows/APICodeDialog.js
index 49c718cc..34c2281f 100644
--- a/packages/ui/src/views/chatflows/APICodeDialog.js
+++ b/packages/ui/src/views/chatflows/APICodeDialog.js
@@ -23,6 +23,7 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
import { Dropdown } from 'ui-component/dropdown/Dropdown'
import ShareChatbot from './ShareChatbot'
import EmbedChat from './EmbedChat'
+import Configuration from './Configuration'
// Const
import { baseURL } from 'store/constant'
@@ -35,6 +36,7 @@ import cURLSVG from 'assets/images/cURL.svg'
import EmbedSVG from 'assets/images/embed.svg'
import ShareChatbotSVG from 'assets/images/sharing.png'
import settingsSVG from 'assets/images/settings.svg'
+import { IconBulb } from '@tabler/icons'
// API
import apiKeyApi from 'api/apikey'
@@ -46,8 +48,8 @@ import useApi from 'hooks/useApi'
import { CheckboxInput } from 'ui-component/checkbox/Checkbox'
import { TableViewOnly } from 'ui-component/table/Table'
-import { IconBulb } from '@tabler/icons'
-import Configuration from './Configuration'
+// Helpers
+import { unshiftFiles, getConfigExamplesForJS, getConfigExamplesForPython, getConfigExamplesForCurl } from 'utils/genericHelper'
function TabPanel(props) {
const { children, value, index, ...other } = props
@@ -77,67 +79,6 @@ function a11yProps(index) {
}
}
-const unshiftFiles = (configData) => {
- const filesConfig = configData.find((config) => config.name === 'files')
- if (filesConfig) {
- configData = configData.filter((config) => config.name !== 'files')
- configData.unshift(filesConfig)
- }
- return configData
-}
-
-const getConfigExamplesForJS = (configData, bodyType) => {
- let finalStr = ''
- configData = unshiftFiles(configData)
- const loop = Math.min(configData.length, 4)
- for (let i = 0; i < loop; i += 1) {
- const config = configData[i]
- let exampleVal = `"example"`
- if (config.type === 'string') exampleVal = `"example"`
- else if (config.type === 'boolean') exampleVal = `true`
- else if (config.type === 'number') exampleVal = `1`
- else if (config.name === 'files') exampleVal = `input.files[0]`
- finalStr += bodyType === 'json' ? `\n "${config.name}": ${exampleVal},` : `formData.append("${config.name}", ${exampleVal})\n`
- if (i === loop - 1 && bodyType !== 'json') finalStr += `formData.append("question", "Hey, how are you?")\n`
- }
- return finalStr
-}
-
-const getConfigExamplesForPython = (configData, bodyType) => {
- let finalStr = ''
- configData = unshiftFiles(configData)
- const loop = Math.min(configData.length, 4)
- for (let i = 0; i < loop; i += 1) {
- const config = configData[i]
- let exampleVal = `"example"`
- if (config.type === 'string') exampleVal = `"example"`
- else if (config.type === 'boolean') exampleVal = `true`
- else if (config.type === 'number') exampleVal = `1`
- else if (config.name === 'files') continue
- finalStr += bodyType === 'json' ? `\n "${config.name}": ${exampleVal},` : `\n "${config.name}": ${exampleVal},`
- if (i === loop - 1 && bodyType !== 'json') finalStr += `\n "question": "Hey, how are you?"\n`
- }
- return finalStr
-}
-
-const getConfigExamplesForCurl = (configData, bodyType) => {
- let finalStr = ''
- configData = unshiftFiles(configData)
- const loop = Math.min(configData.length, 4)
- for (let i = 0; i < loop; i += 1) {
- const config = configData[i]
- let exampleVal = `example`
- if (config.type === 'string') exampleVal = bodyType === 'json' ? `"example"` : `example`
- else if (config.type === 'boolean') exampleVal = `true`
- else if (config.type === 'number') exampleVal = `1`
- else if (config.name === 'files') exampleVal = `@/home/user1/Desktop/example${config.type}`
- finalStr += bodyType === 'json' ? `"${config.name}": ${exampleVal}` : `\n -F "${config.name}=${exampleVal}"`
- if (i === loop - 1) finalStr += bodyType === 'json' ? ` }` : ` \\\n -F "question=Hey, how are you?"`
- else finalStr += bodyType === 'json' ? `, ` : ` \\`
- }
- return finalStr
-}
-
const APICodeDialog = ({ show, dialogProps, onCancel }) => {
const portalElement = document.getElementById('portal')
const navigate = useNavigate()
@@ -334,7 +275,8 @@ query({"question": "Hey, how are you?"}).then((response) => {
const getConfigCodeWithFormData = (codeLang, configData) => {
if (codeLang === 'Python') {
configData = unshiftFiles(configData)
- const fileType = configData[0].type
+ let fileType = configData[0].type
+ if (fileType.includes(',')) fileType = fileType.split(',')[0]
return `import requests
API_URL = "${baseURL}/api/v1/prediction/${dialogProps.chatflowid}"
@@ -384,7 +326,8 @@ query(formData).then((response) => {
const getConfigCodeWithFormDataWithAuth = (codeLang, configData) => {
if (codeLang === 'Python') {
configData = unshiftFiles(configData)
- const fileType = configData[0].type
+ let fileType = configData[0].type
+ if (fileType.includes(',')) fileType = fileType.split(',')[0]
return `import requests
API_URL = "${baseURL}/api/v1/prediction/${dialogProps.chatflowid}"
@@ -700,7 +643,11 @@ formData.append("openAIApiKey[openAIEmbeddings_0]", "sk-my-openai-2nd-key")`