Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ui/src/components/ai-chat/component/chat-input-operate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -765,21 +765,21 @@ const stopTimer = () => {

const getQuestion = () => {
if (!inputValue.value.trim()) {
const fileLenth = [
const fileLength = [
uploadImageList.value.length > 0,
uploadDocumentList.value.length > 0,
uploadAudioList.value.length > 0,
uploadOtherList.value.length > 0,
]
if (fileLenth.filter((f) => f).length > 1) {
if (fileLength.filter((f) => f).length > 1) {
return t('chat.uploadFile.otherMessage')
} else if (fileLenth[0]) {
} else if (fileLength[0]) {
return t('chat.uploadFile.imageMessage')
} else if (fileLenth[1]) {
} else if (fileLength[1]) {
return t('chat.uploadFile.documentMessage')
} else if (fileLenth[2]) {
} else if (fileLength[2]) {
return t('chat.uploadFile.audioMessage')
} else if (fileLenth[3]) {
} else if (fileLength[3]) {
return t('chat.uploadFile.otherMessage')
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code looks generally correct for selecting a message based on the presence of uploaded files. However, there are minor improvements that can be made:

  1. Consistence: Ensure that all conditions use consistent syntax for checking truthy values, either || !value or just !value. This improves clarity.

  2. Avoiding Index Access: Directly filter the array to avoid accessing elements by index.

Here's an optimized version of your function:

const getQuestion = () => {
  const fileList = [
    uploadImageList && uploadImageList.length > 0,
    uploadDocumentList && uploadDocumentList.length > 0,
    uploadAudioList && uploadAudioList.length > 0,
    uploadOtherList && uploadOtherList.length > 0,
  ];

  switch (fileList.filter(Boolean).length) {
    case 4:
      return t('chat.uploadFile.otherMessage');
    case 3:
      return t('chat.uploadFile.imageMessage') ||
             t('chat.uploadFile.documentMessage') ||
             t('chat.uploadFile.audioMessage');
    default:
      // Handle other cases if necessary
      return '';
  }
};

Key Changes:

  • Used && with numbers instead of .length > 0 for consistency.
  • Simplified boolean filtering using filter(Boolean) which automatically checks for truthy and falsy values.
  • Replaced conditional statements with a switch statement for clarity when more than one condition matches.

Expand Down
Loading