Repository navigation
feat: system application to chat - #7926
Conversation
| <el-button text type="primary" @click="toChat(row)"> | ||
| <MkIcon name="icon_new-chat_outlined" /> | ||
| </el-button> | ||
| </MkTooltip> |
There was a problem hiding this comment.
Here are the issues and suggestions:
1. Potential runtime crash in apiQuery
application?.work_flow?.nodes?.find(...)?.properties?.api_input_field_list.map(...)The optional chaining stops at .find(...), but then .properties is accessed without ?., and .api_input_field_list.map(...) also lacks ?.. If the node isn't found, or properties / api_input_field_list are undefined, this throws. Fix:
const query = application?.work_flow?.nodes
?.find(n => n.id === 'base-node')
?.properties?.api_input_field_list
?.map((f: any) => `${f.variable}=${f.default_value}`)
.join('&')2. Values not URL-encoded
default_value (and variable) may contain spaces, &, =, #, etc., corrupting the query string. Use encodeURIComponent:
`${encodeURIComponent(f.variable)}=${encodeURIComponent(f.default_value ?? '')}`3. Double slash in the URL when no query params
`${origin}${chatBasePath}/${token}/${apiQuery(application)}`apiQuery returns '' when empty, so you get .../{token}/ with a trailing slash (or /{token}/?a=b). Compare the concatenation carefully — you likely want .../${token} and append apiQuery directly (since it already includes the leading ?), or strip the trailing /.
4. window.open with an empty URL
When access_token is falsy, accessUrl is '' and window.open('', '_blank') opens a blank tab. Guard against it or show an error message:
if (!ok.access_token) { /* show toast */ return }5. Unused parameter / typing
ApplicationDetail is imported as a type, good. But f: any weakens typing — define an interface for the api field list if available.
6. Naming
apiQuery returns a query string (with leading ?); consider renaming to buildApiQuery / getApiQueryString for clarity.
7. Error handling in toChat
The .then chain has no .catch; a failed token request produces an unhandled rejection. Add .catch (or use async/await with try/catch).
8. Re-entrancy on button click
No loading state preventing multiple rapid clicks → multiple tabs. Consider disabling/spinner while the request is in-flight.
9. auth from store appears unused in this snippet — unrelated to this diff but verify it's still needed after the import changes.
10. Global state mutation via window.open — popup blockers may block window.open if called after an async call (browser loses the "user gesture" context). Calling window.open synchronously and setting location afterwards is safer:
const win = window.open('', '_blank')
// ...after await...
win.location.href = accessUrl
feat: system application to chat