Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ const imageExtensions = ['JPG', 'JPEG', 'PNG', 'GIF', 'BMP']
const documentExtensions = ['PDF', 'DOCX', 'TXT', 'XLS', 'XLSX', 'MD', 'HTML', 'CSV']
const videoExtensions: any = []
const audioExtensions = ['MP3', 'WAV', 'OGG', 'AAC', 'M4A']
let otherExtensions = ref(['PPT', 'DOC'])
const otherExtensions = ref(['PPT', 'DOC'])

const getAcceptList = () => {
const { image, document, audio, video, other } = props.applicationDetails.file_upload_setting
Expand Down Expand Up @@ -554,7 +554,7 @@ const switchMicrophone = (status: boolean) => {
}
}

const TouchEnd = (bool?: Boolean) => {
const TouchEnd = (bool?: boolean) => {
if (bool) {
stopRecording()
recorderStatus.value = 'STOP'
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/ai-chat/component/control/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const menus = ref([
*/
const clearSelectedText = () => {
if (window.getSelection) {
var selection = window.getSelection()
const selection = window.getSelection()
if (selection) {
selection.removeAllRanges()
}
Expand Down

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions ui/src/components/ai-chat/component/user-form/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ watch(

function handleInputFieldList() {
dynamicsFormRefresh.value++
let default_value: any = {}
const default_value: any = {}
props.application.work_flow?.nodes
?.filter((v: any) => v.id === 'base-node')
.map((v: any) => {
Expand Down Expand Up @@ -312,8 +312,8 @@ const validate = () => {
}
const validate_query = () => {
// 浏览器query参数找到接口传参
let msg = []
for (let f of apiInputFieldList.value) {
const msg = []
for (const f of apiInputFieldList.value) {
if (f.required && !api_form_data_context.value[f.field]) {
msg.push(f.field)
}
Expand All @@ -328,9 +328,9 @@ const validate_query = () => {
}

const initRouteQueryValue = () => {
for (let f of apiInputFieldList.value) {
for (const f of apiInputFieldList.value) {
if (!api_form_data_context.value[f.field]) {
let _value = getRouteQueryValue(f.field)
const _value = getRouteQueryValue(f.field)
if (_value != null) {
api_form_data_context.value[f.field] = _value
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The provided code has several potential issues:

  1. Type Annotations: The variable default_value is declared without proper type annotations, which can lead to unexpected behavior in the future if TypeScript linting or compiler features like strict mode are enabled. Consider adding any | {} instead.

  2. Destructuring vs. Old Syntax: There's a mix of destructuring (const { ... } = ...) and older syntax (let varName: any). For consistency, convert default_value to use curly braces for destructuring.

  3. Variable Names: Use descriptive names for variables like default_value, especially when dealing with complex objects or collections.

  4. Function Definitions: Ensure that all functions have clear purpose statements at the top (docstrings or comments) for better understanding.

  5. Code Organization: Although the file seems structured well, consider grouping related logic together within functions rather than having them spread across sections.

Here’s an improved version of the code based on these suggestions:

// Function handling the input field list and refreshing form data
function handleInputFieldList() {
  dynamicsFormRefresh.value++;
  const default_value: Record<string, unknown> = {};
  
  // Filter nodes by ID 'base-node' and map properties
  const baseNode = props.application.work_flow.nodes.find(v => v.id === 'base-node');
  if (baseNode) {
    baseNode.properties.forEach(property => {
      default_value[property.name] = property.default || null;
    });
  }

  // Other logic...
}

async function validate() {
  // Validation logic here...
}

const validate_query = async () => {
  const messageErrors: string[] = [];
  
  apiInputFieldList.value.forEach(field => {
    if (field.required && !api_form_data_context.value[field.field]) {
      messageErrors.push(field.field);
    }
    
    // Additional validation logic...
  });

  // Handle errors...
};

const initRouteQueryValue = async () => {
  apiInputFieldList.value.forEach(field => {
    if (!api_form_data_context.value[field.field]) {
      const routeQueryValue = getRouteQueryValue(field.field);
      
      if (routeQueryValue !== null) {
        api_form_data_context.value[field.field] = routeQueryValue;
      }
    }
  });
};

Key Changes:

  • Type Annotations: Changed (Record<string, unknown>) for clearer semantic meaning.
  • Curly Braces Usage: Used {} for object initialization.
  • Descriptive Variable Names: E.g., properties, messageErrors.
  • Consistent Code Structure: Ensured clarity by maintaining consistent structure around each logical section.

Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/ai-chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function sendMessage(val: string, other_params_data?: any, chat?: chatType): Pro
return userFormRef.value
?.validate()
.then((ok) => {
let userFormData = accessToken
const userFormData = accessToken
? JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
: {}
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
Expand Down Expand Up @@ -640,7 +640,7 @@ const handleScroll = () => {

onMounted(() => {
if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) {
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
const userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
form_data.value = userFormData
}
if (window.speechSynthesis) {
Expand Down
6 changes: 5 additions & 1 deletion ui/src/components/back-button/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ const emit = defineEmits(['click'])
const back: any = router.options.history.state.back
function jump() {
if (props.to === '-1') {
back ? router.push(back) : router.go(-1)
if (back) {
router.push(back)
} else {
router.go(-1)
}
} else if (props.to) {
router.push(props.to as RouteLocationRaw)
} else {
Expand Down
2 changes: 2 additions & 0 deletions ui/src/components/folder-tree/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ const resourceType = computed(() => {
return 'model'
} else if (props.source === 'TOOL') {
return 'tool'
} else {
return 'application'
}
})

Expand Down
3 changes: 1 addition & 2 deletions ui/src/components/markdown/EchartsRander.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ function evalParseOption(option_json: any) {
if (option_json.style) {
style.value = option_json.style
}
let option = {}
echarts
const option = {}
tmp.value = echarts
eval(option_json.option)
return option
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/markdown/HtmlRander.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ onMounted(() => {
range.selectNode(htmlRef.value)
const scripts = htmlRef.value.getElementsByTagName('script')
if (scripts) {
var documentFragment = range.createContextualFragment(
const documentFragment = range.createContextualFragment(
[...scripts]
.map((item: HTMLElement) => {
htmlRef.value?.removeChild(item)
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/markdown/MdEditorMagnify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import { ref, computed, watch } from 'vue'
defineOptions({ name: 'MdEditorMagnify' })
const props = defineProps<{
title: String
title: string
modelValue: any
}>()
const emit = defineEmits(['update:modelValue', 'submitDialog'])
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/select-knowledge-document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ import useStore from '@/stores'
import { t } from '@/locales'
const props = defineProps<{
data?: {
type: Object
default: () => {}
type: object
default: () => null
}
apiType: 'systemShare' | 'workspace' | 'systemManage'
isApplication?: boolean,
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/application-overview/component/APIKeyDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ function settingApiKey(row: any) {

function deleteApiKey(row: any) {
MsgConfirm(
// @ts-ignore
`${t('views.applicationOverview.appInfo.APIKeyDialog.msgConfirm1')}: ${row.secret_key}?`,
t('views.applicationOverview.appInfo.APIKeyDialog.msgConfirm2'),
{
confirmButtonText: t('common.confirm'),
cancelButtonText: t('common.cancel'),
confirmButtonClass: 'color-danger',
confirmButtonClass: 'danger',
},
)
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const submit = async (formEl: FormInstance | undefined) => {
.putAccessToken(id as string, form.value, loading)
.then(() => {
emit('refresh')
// @ts-ignore

MsgSuccess(t('common.settingSuccess'))
dialogVisible.value = false
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const submit = async (formEl: FormInstance | undefined) => {
.putAccessToken(id as string, obj, loading)
.then(() => {
emit('refresh')
// @ts-ignore

MsgSuccess(t('common.settingSuccess'))
dialogVisible.value = false
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const submit = async (formEl: FormInstance | undefined) => {

apiCall.then(() => {
emit('refresh')
//@ts-ignore

MsgSuccess(t('common.settingSuccess'))
dialogVisible.value = false
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ const props = defineProps({
const statisticsType = computed(() => [
{
id: 'customerCharts',
// @ts-ignore
name: t('views.applicationOverview.monitor.charts.customerTotal'),
icon: 'app-user',
background: '#EBF1FF',
Expand Down
2 changes: 0 additions & 2 deletions ui/src/views/application-overview/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ const shareUrl = computed(
const dayOptions = [
{
value: 7,
// @ts-ignore
label: t('views.applicationOverview.monitor.pastDayOptions.past7Days'),
},
{
Expand Down Expand Up @@ -373,7 +372,6 @@ function refreshAccessToken() {
const obj = {
access_token_reset: true,
}
// @ts-ignore
const str = t('views.applicationOverview.appInfo.refreshToken.refreshSuccess')
updateAccessToken(obj, str)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ const onChange = (file: any, fileList: UploadFiles, attr: string) => {
//1、判断文件大小是否合法,文件限制不能大于 10 MB
const isLimit = file?.size / 1024 / 1024 < 10
if (!isLimit) {
// @ts-ignore
MsgError(t('common.EditAvatarDialog.fileSizeExceeded'))
return false
} else {
Expand Down Expand Up @@ -675,7 +674,6 @@ const submit = async (formEl: FormInstance | undefined) => {
.putXpackAccessToken(id as string, fd, loading)
.then(() => {
emit('refresh')
// @ts-ignore
MsgSuccess(t('common.settingSuccess'))
dialogVisible.value = false
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ const submit = async (formEl: FormInstance | undefined) => {
.putAccessToken(id as string, obj, loading)
.then(() => {
emit('refresh')
// @ts-ignore
MsgSuccess(t('common.settingSuccess'))
dialogVisible.value = false
})
Expand Down
10 changes: 8 additions & 2 deletions ui/src/views/application-workflow/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ function back() {
saveApplication(true, true)
})
.catch((action: Action) => {
action === 'cancel' && go()
if (action === 'cancel') {
go()
}
})
} else {
go()
Expand Down Expand Up @@ -275,7 +277,11 @@ function openHistory() {
}

function changeSave(bool: boolean) {
bool ? initInterval() : closeInterval()
if (bool) {
initInterval()
} else {
closeInterval()
}
localStorage.setItem('workflowAutoSave', bool.toString())
}

Copy link
Contributor

Choose a reason for hiding this comment

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

The provided code is mostly clean, but there are two small improvements to make:

Improvements

  1. Consistent go() Logic: The logic for handling the back and openHistory functions should be consistent. Currently, both use go(), which might lead to unintended behavior at some points in your application's lifecycle.

  2. Avoiding Redundancy in Save/Unsave Handling: In the changeSave function, you have redundant conditions that check if bool is false before calling closeInterval. This can be simplified to avoid unnecessary condition checks.

Here’s the revised version of the code with these changes:

function back(action: Action = 'continue') {
  switch (action) {
    case 'cancel':
      go();
      break;
    default:
      saveApplication(true, true).catch(action =>
        action === 'cancel' && go()
      );
  }
}

function openHistory() {
  // Add functionality for opening history here
}

function changeSave(bool: boolean) {
  const savedState = storedItem.get('workflowAutoSave');
  bool === 'true'

} else {
  closeInterval();
}
localStorage.setItem('workflowAutoSave', bool.toString());

Explanation of Changes

  • Switch Statement: Added a switch statement to handle different actions more clearly.
  • Default Case: Changed the back function to include a default case so it doesn't throw an error when action isn’t explicitly passed.
  • Simplified Condition for Saved State: Removed the redundancy by directly comparing storedItem.get('workflowAutoSave') with the string 'true'.

These changes enhance readability and maintainability of the code.

Expand Down
1 change: 0 additions & 1 deletion ui/src/views/application/ApplicationSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})

// @ts-ignore
const defaultPrompt = t('views.application.form.prompt.defaultPrompt', {
data: '{data}',
question: '{question}',
Expand Down
3 changes: 1 addition & 2 deletions ui/src/views/application/component/CopyApplicationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import useStore from '@/stores'
const router = useRouter()
const { common, user } = useStore()

// @ts-ignore
const defaultPrompt = t('views.application.form.prompt.defaultPrompt', {
data: '{data}',
question: '{question}',
Expand All @@ -69,7 +68,7 @@ const applicationFormRef = ref()

const loading = ref(false)
const dialogVisible = ref<boolean>(false)
// @ts-ignore

const applicationForm = ref<ApplicationFormType>({
name: '',
desc: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const { user } = useStore()
const router = useRouter()
const emit = defineEmits(['refresh'])

// @ts-ignore
const defaultPrompt = t('views.application.form.prompt.defaultPrompt', {
data: '{data}',
question: '{question}',
Expand Down
1 change: 0 additions & 1 deletion ui/src/views/application/component/ParamSettingDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ const noReferencesformRef = ref()

const defaultValue = {
ai_questioning: '{question}',
// @ts-ignore
designated_answer: t('views.application.dialog.designated_answer'),
}

Expand Down
1 change: 0 additions & 1 deletion ui/src/views/chat-log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ const formRef = ref()
const dayOptions = [
{
value: 7,
// @ts-ignore
label: t('views.applicationOverview.monitor.pastDayOptions.past7Days'), // 使用 t 方法来国际化显示文本
},
{
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/model/component/CreateModelDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:before-close="close"
append-to-body
>
<template #header="{ close, titleId, titleClass }">
<template #header>
<el-breadcrumb separator=">">
<el-breadcrumb-item>
<span @click="toSelectProvider" class="select-provider">
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/model/component/EditModel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:destroy-on-close="true"
:before-close="close"
>
<template #header="{ close, titleId, titleClass }">
<template #header>
<el-breadcrumb separator=">">
<el-breadcrumb-item
><span class="active-breadcrumb">{{
Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/paragraph/component/ParagraphDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
import permissionMap from '@/permission'

const props = defineProps<{
title: String
title: string
apiType: 'systemShare' | 'workspace' | 'systemManage'
}>()

Expand Down
6 changes: 3 additions & 3 deletions ui/src/views/paragraph/component/ProblemComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ import permissionMap from '@/permission'


const props = defineProps<{
paragraphId: String
docId: String
knowledgeId: String
paragraphId: string
docId: string
knowledgeId: string
apiType: 'systemShare' | 'workspace' | 'systemManage'
}>()

Expand Down
2 changes: 1 addition & 1 deletion ui/src/views/paragraph/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
container=".paragraph-scollbar"
@click="handleClick"
>
<template v-for="(item, index) in paragraphDetail" :key="item.id">
<template v-for="(item) in paragraphDetail" :key="item.id">
<el-anchor-link :href="`#m${item.id}`" :title="item.title" v-if="item.title">
<span :title="item.title">
{{ item.title }}
Expand Down
9 changes: 7 additions & 2 deletions ui/src/views/problem/component/RelateProblemDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ function associationClick(item: any) {
function searchHandle() {
paginationConfig.current_page = 1
paragraphList.value = []
currentDocument.value && getParagraphList(currentDocument.value)
if (currentDocument.value) {
getParagraphList(currentDocument.value)
}
}

function clickDocumentHandle(item: any) {
Expand All @@ -222,7 +224,10 @@ function getDocument() {
documentList.value = res.data
currentDocument.value =
cloneDocumentList.value?.length > 0 ? cloneDocumentList.value[0].id : ''
currentDocument.value && getParagraphList(currentDocument.value)

if (currentDocument.value) {
getParagraphList(currentDocument.value)
}
})
}

Copy link
Contributor

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 good, but here are some minor suggestions for improvement:

  1. Whitespace Cleanup: The lines if (currentDocument.value) { and } have an extra space before them which might not be necessary.

  2. Avoid Repeated Code: Although it's minimal, you can extract the logic of updating currentDocument.value and calling getParagraphList into its own helper function to reduce duplication.

  3. Type Annotations: It would help clarity if you have type annotations for paginationConfig, paragraphList, currentDocument, and other variables used within the functions.

Here's a slightly refined version incorporating these points:

function associationClick(item: any): void {
  // Function implementation
}

function searchHandle(): void {
  paginationConfig.current_page = 1;
  paragraphList.value = [];
  
  if (currentDocument.value) {
    getParagraphList(currentDocument.value);
  }
}

function clickDocumentHandle(item: any): void {
  // Function implementation
}

async function getDocument(documentId: string | null): Promise<void> {
  const res = await fetch(`https://example.com/documents/${documentId}`);
  const data = await res.json();
  documentList.value = data;
  
  const firstDocId = cloneDocumentList.value.filter(doc => doc.id === documentList.value[0]?.id).map(doc => doc.id)[0];
  currentDocument.value = firstDocId || '';

  if (currentDocument.value) {
    getParagraphList(currentDocument.value);
  }
}

In this revision:

  • I added comments explaining each part of the functions.
  • Used async/await for better readability when fetching documents.
  • Removed unnecessary spaces around conditional statements and curly braces.
  • Ensured there are no duplicate operations on getParagraphList.
  • Included null or empty string checks in case cloneDocumentList might unexpectedly be empty or cause issues later.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ function mapToUrlParams(map: any[]) {

function deleteApplication(row: any) {
MsgConfirm(
// @ts-ignore
`${t('views.application.delete.confirmTitle')}${row.name} ?`,
t('views.application.delete.confirmMessage'),
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ const search_type_change = () => {
}

function getRequestParams() {
let obj: any = {
const obj: any = {
name: model_search_form.value.name,
create_user: model_search_form.value.create_user,
model_type: model_search_form.value.model_type,
Expand Down
1 change: 0 additions & 1 deletion ui/src/views/system-setting/theme/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ const rules = reactive<FormRules>({
const onChange = (file: any, fileList: UploadFiles, attr: string) => {
const isLimit = file?.size / 1024 / 1024 < 10
if (!isLimit) {
// @ts-ignore
MsgError(t('theme.fileMessageError'))
return false
} else {
Expand Down
Loading
Loading