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
27 changes: 14 additions & 13 deletions agent/app/dto/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,20 @@ type AppForm struct {
}

type AppFormFields struct {
Type string `json:"type"`
LabelZh string `json:"labelZh"`
LabelEn string `json:"labelEn"`
Label Locale `json:"label"`
Required bool `json:"required"`
Default interface{} `json:"default"`
EnvKey string `json:"envKey"`
Disabled bool `json:"disabled"`
Edit bool `json:"edit"`
Rule string `json:"rule"`
Multiple bool `json:"multiple"`
Child interface{} `json:"child"`
Values []AppFormValue `json:"values"`
Type string `json:"type"`
LabelZh string `json:"labelZh"`
LabelEn string `json:"labelEn"`
Label Locale `json:"label"`
Description Locale `json:"description"`
Required bool `json:"required"`
Default interface{} `json:"default"`
EnvKey string `json:"envKey"`
Disabled bool `json:"disabled"`
Edit bool `json:"edit"`
Rule string `json:"rule"`
Multiple bool `json:"multiple"`
Child interface{} `json:"child"`
Values []AppFormValue `json:"values"`
}

type AppFormValue struct {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are no irregularities, potential issues, or optimization suggestions with the provided code changes. The fields that were added (Description, EnvKey) will not affect existing functionality but can be useful for additional context if needed. If there was an intention to replace Label with another data structure for labels in different languages, ensure it's structured similarly so the rest of the app can accommodate this change gracefully.

Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/interface/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export namespace App {
multiple?: boolean;
allowCreate?: boolean;
label: Locale;
description: Locale;
}

export interface FromFieldChild extends FromField {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,15 @@ export function getLabel(row: any) {
}
}

export function getDescription(row: any) {
const language = localStorage.getItem('lang') || 'zh';
let lang = language == 'tw' ? 'zh-Hant' : language;
if (row.description && row.description[lang] != '') {
return row.description[lang];
}
return '';
}

export function emptyLineFilter(str: string, spilt: string) {
let list = str.split(spilt);
let results = [];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The code appears to be well-structured, but here are some suggestions for improvement:

Suggestion 1: Ensure Language Handling Consistency

The function getDescription uses different languages ('tw' vs. 'zh-Hant'). It might be useful to define a mapping between these two codes for better consistency.

function getLanguageCode(language: string): string {
    return language === 'tw' ? 'zh-Hant' : language;
}

const descriptionsByLang = new Map<string, Record<string, string>>([
    ['en', { description_en: '' }],
    ['fr', { description_fr: '' }],
    // Add more mappings as needed
]);

export function getDescription(row: any) {
    const language = localStorage.getItem('lang') || 'zh';
    const langCode = getLanguageCode(language);

    const rowDescription = descriptionsByLang.get(langCode)?.description[lang];
   if (typeof rowDescription !== 'undefined') {
       return String(rowDescription); // Convert to non-null assertion operator or type guard if necessary
   }

   return '';
}

Suggestion 2: Remove Unnecessary Typing Conversion

Convertion from any to specific types is unnecessary without context and can lead to runtime errors if used incorrectly. If the types of the properties in row are known, they should be defined explicitly.

Additional Considerations:

  1. Error Handling: Consider adding error handling for cases such as missing keys or invalid data types.
  2. Data Structure: Depending on how deeply nested your row data may become, using TypeScript interfaces/objects can provide better type safety while maintaining readability.
  3. Documentation: Adding comments explaining complex logic or assumptions about the input data can make it easier for others (and future you) to understand the purpose and functionality of each part of the code.

Overall, the current code is clean and effective for its intended use case, with room for enhancement based on additional requirements or constraints.

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/app-store/detail/params/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
</span>
</el-col>
</el-row>
<span class="input-help" v-if="p.description">{{ getDescription(p) }}</span>
</el-form-item>
</div>
</template>
Expand All @@ -125,7 +126,7 @@ import { getRandomStr } from '@/utils/util';
import { getAppService } from '@/api/modules/app';
import { Rules } from '@/global/form-rules';
import { App } from '@/api/interface/app';
import { getDBName, getLabel } from '@/utils/util';
import { getDBName, getLabel, getDescription } from '@/utils/util';
import { getPathByType } from '@/api/modules/files';

interface ParamObj extends App.FromField {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are no errors in the provided code changes. However, there is a typo in one of the lines that could lead to an unintended outcome:

@@ -126,7 +126,7 @@ import { getDescription } from '@/utils/util';

The line should be corrected to:

import { getDescription, getLabel } from '@/utils/util'; // Corrected typo here

Additionally, it's recommended to add documentation or comments about new functionality introduced by this change to help future developers understand why getDescription is being used and how it relates to other functions like getDBName, getLocale, etc., which would improve maintainability if they follow similar patterns.

Expand Down
Loading