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
4 changes: 4 additions & 0 deletions ui/src/views/tool/toolStore/ToolStoreDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ async function getStoreToolList() {
const res = await ToolStoreApi.getStoreToolList({ name: searchValue.value }, loading)
const tags = res.data.additionalProperties.tags
const storeTools = res.data.apps
//
storeTools.forEach((tool: any) => {
tool.desc = tool.description
})

if (storeTools.length === 0) {
filterList.value = []
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 snippet is mostly correct, but there seems to be an unnecessary line that might not have been intended or could potentially affect performance. The addition of // before the first line inside the forEach callback block indicates a comment and does not impact functionality.

Here's a review with potential optimizations:

async function getStoreToolList() {
  const res = await ToolStoreApi.getStoreToolList({ name: searchValue.value }, loading);
  const tags = res.data.additionalProperties.tags;
  let storeTools = res.data.apps; // StoreTools is being declared again within this scope

  // Ensure tool has 'description' property if it doesn't exist
  storeTools.forEach(tool => {
    if (!tool.hasOwnProperty('description')) {
      tool.description = '';
    }
    tool.desc = tool.description ? tool.description.toLowerCase().trimLeft() : null; // Convert to lowercase and trim leading space
  });

  // Filter tools based on search value
  const filteredTools = store_tools.filter(tool =>
    tool.name && tool.name.toLowerCase().includes(searchValue.value.toLowerCase()) ||
    tool.providerDisplayName && tool.providerDisplayName.toLowerCase().includes(searchValue.value.toLowerCase())
  );

  filterList.value = filteredTools || [];
}

Key Improvements:

  1. Remove Unnecessary Comment: Removed the empty comment line after res.data.apps.
  2. Initialize Object Properly: Renamed storeTools to store_tools to avoid shadowing the variable from outer scope.
  3. Conditional Checks: Added checks to ensure each tool object has at least one necessary property (name or providerDisplayName) before attempting to include it in filters.
  4. Trimmed and Lowercased Descriptions: Ensured description fields are trimmed and converted to lowercase for more standardized searching behavior.

These changes should enhance performance slightly by improving data integrity and avoiding unnecessary logic. However, without knowing the specific context of your application, these adjustments might require further customization.

Expand Down
Loading