Skip to content

Commit 33a7471

Browse files
committed
refactor: address Gemini and CodeRabbit reviews by hoisting constants and using nullish checks
1 parent 6b48f69 commit 33a7471

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

packages/ui/src/utils/exportImport.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ const sanitizeTool = (Tool) => {
1919
}
2020
}
2121

22+
const CHATFLOW_FIELDS_TO_PRESERVE = [
23+
'chatbotConfig',
24+
'category',
25+
'speechToText',
26+
'textToSpeech',
27+
'followUpPrompts',
28+
'apiConfig',
29+
'analytic',
30+
'isPublic',
31+
'apikeyid',
32+
'mcpServerConfig'
33+
]
34+
2235
const sanitizeChatflow = (ChatFlow) => {
2336
try {
2437
return ChatFlow.map((chatFlow) => {
@@ -29,15 +42,13 @@ const sanitizeChatflow = (ChatFlow) => {
2942
flowData: stringify(sanitizeFlowData),
3043
type: chatFlow.type
3144
}
32-
if (chatFlow.chatbotConfig) sanitized.chatbotConfig = chatFlow.chatbotConfig
33-
if (chatFlow.category) sanitized.category = chatFlow.category
34-
if (chatFlow.speechToText) sanitized.speechToText = chatFlow.speechToText
35-
if (chatFlow.textToSpeech) sanitized.textToSpeech = chatFlow.textToSpeech
36-
if (chatFlow.followUpPrompts) sanitized.followUpPrompts = chatFlow.followUpPrompts
37-
if (chatFlow.apiConfig) sanitized.apiConfig = chatFlow.apiConfig
38-
if (chatFlow.analytic) sanitized.analytic = chatFlow.analytic
39-
if (chatFlow.isPublic !== undefined) sanitized.isPublic = chatFlow.isPublic
40-
if (chatFlow.apikeyid) sanitized.apikeyid = chatFlow.apikeyid
45+
46+
CHATFLOW_FIELDS_TO_PRESERVE.forEach((field) => {
47+
if (chatFlow[field] != null) {
48+
sanitized[field] = chatFlow[field]
49+
}
50+
})
51+
4152
return sanitized
4253
})
4354
} catch (error) {

0 commit comments

Comments
 (0)