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: 2 additions & 10 deletions ui/src/views/model/component/CreateModelDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@
<el-empty
v-else-if="
base_form_data.model_type === 'RERANKER' ||
base_form_data.model_type === 'EMBEDDING' ||
base_form_data.model_type === 'STT'
base_form_data.model_type === 'EMBEDDING'
"
:description="$t('views.model.tip.emptyMessage2')"
/>
Expand All @@ -149,14 +148,7 @@
<el-button
type="text"
@click.stop="openAddDrawer()"
:disabled="
base_form_data.model_type !== 'TTS' &&
base_form_data.model_type !== 'LLM' &&
base_form_data.model_type !== 'IMAGE' &&
base_form_data.model_type !== 'TTI' &&
base_form_data.model_type !== 'TTV' &&
base_form_data.model_type !== 'ITV'
"
:disabled="!['TTS', 'LLM', 'IMAGE', 'TTI', 'TTV', 'ITV','STT'].includes(base_form_data.model_type)"
>
<AppIcon iconName="app-add-outlined" class="mr-4"/> {{ $t('common.add') }}
</el-button>
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 code you provided is generally clean and well-formed, but there are a few small improvements that could be made for clarity and efficiency:

Improvements

  1. Consistent Conditional Checks: Ensure consistency in how conditionals are checked. Here, it's good to use the includes method consistently.

  2. Remove Unnecessary Disables: If an action should always be enabled (like adding), it might not need to be disabled under certain conditions.

Here's the updated code with these considerations:

<template>
  <div v-if="base_form_data.model_type === 'RERANKER'">
    <!-- Reranker specific content -->
  </div>
  <el-empty v-else-if="['EMBEDDING','STT'].some(type => type === base_form_data.model_type)">
    :description="$t('views.model.tip.emptyMessage2')"
  </el-empty>

  <template v-else>
    <div v-if="hasAddActionAvailable">{{ $t('common.add') }}</div>
    <div v-else>-- Disabled --</div>
  </template>
</template>

<script>
export default {
  data() {
    return {
      hasAddActionAvailable: ['TTS', 'LLM', 'IMAGE', 'TTI', 'TTV', 'ITV','STT'].includes(this.base_form_data.model_type)
    };
  }
};
</script>

Key Changes

  • Single Condition Check with Includes: Used .some() method instead of multiple || checks to determine if base_form_data.model_type is one of the values related to empty messages (RERANKER, 'EMBEDDING', or 'STT').

  • Computed Property: Introduced a computed property hasAddActionAvailable to simplify disabling logic by directly checking against a predetermined list.

This approach maintains readability while optimizing the conditional checking process.

Expand Down
Loading