Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(desktop): improve experience with avro #1762

Merged
merged 4 commits into from
Sep 23, 2024
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
20 changes: 7 additions & 13 deletions src/components/ImportScript.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
<el-row :gutter="20">
<el-col :span="24">
<el-form-item :label="$t('connections.importFormat')">
<el-select size="small" v-model="record.importFormat">
<el-option v-for="item in format" :key="item.value" :value="item.value" :label="item.label"> </el-option>
</el-select>
<el-input size="small" v-model="format" readonly></el-input>
</el-form-item>
</el-col>
<el-col :span="22">
Expand Down Expand Up @@ -66,12 +64,11 @@ export default class ImportScript extends Vue {
@Prop({ default: false }) public visible!: boolean
@Prop({ required: true }) public title!: string
@Prop({ required: true }) public extension!: string
@Prop({ required: true }) public format!: FunctionList[]
@Prop({ required: true }) public format!: FunctionType | SchemaType

private showDialog: boolean = this.visible
private confirmLoading: boolean = false
private record: ImportScriptForm = {
importFormat: this.format[0].value,
filePath: '',
fileName: '',
fileContent: '',
Expand All @@ -82,17 +79,13 @@ export default class ImportScript extends Vue {
this.showDialog = val
}

@Watch('format')
private onFormatChanged(val: FunctionList[]) {
this.record.importFormat = val[0].value
}

private getFileData() {
let loading: ElLoadingComponent | undefined = undefined
const extensions = this.extension === 'avsc' ? ['avsc', 'json'] : [`${this.extension}`]
remote.dialog
.showOpenDialog({
properties: ['openFile'],
filters: [{ name: '', extensions: [`${this.extension}`] }],
filters: [{ name: '', extensions }],
})
.then((res) => {
const { filePaths } = res
Expand All @@ -105,7 +98,9 @@ export default class ImportScript extends Vue {
this.getFileContentByFs(filePath)
}
})
.catch(() => {})
.catch((err: Error) => {
this.$message.error(err.message)
})
.finally(() => {
loading?.close()
})
Expand Down Expand Up @@ -155,7 +150,6 @@ export default class ImportScript extends Vue {
this.showDialog = false
this.$emit('update:visible', false)
this.record = {
importFormat: this.format[0].value,
filePath: '',
fileName: '',
fileContent: '',
Expand Down
1 change: 0 additions & 1 deletion src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ declare global {
}

interface ImportScriptForm {
importFormat: SchemaType | FunctionType | ''
filePath: string
fileName: string
fileContent: string
Expand Down
50 changes: 27 additions & 23 deletions src/views/script/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,11 @@
@qucik-save="handleTest"
/>
<Editor
v-if="activeTab === schemaTab && currentSchema === 'protobuf'"
v-if="activeTab === schemaTab"
ref="schemaEditor"
id="schema-editor"
:key="2"
:lang="currentFunction"
:isCustomerLang="true"
v-model="schemaEditorValue"
lineNumbers="on"
:lineNumbersMinChars="5"
renderHighlight="line"
@qucik-save="handleTest"
/>
<Editor
v-if="activeTab === schemaTab && currentSchema === 'avro'"
ref="schemaEditor"
id="schema-editor"
:key="3"
:lang="currentFunction"
:lang="scriptEditorLang"
:isCustomerLang="true"
v-model="schemaEditorValue"
lineNumbers="on"
Expand Down Expand Up @@ -127,7 +114,7 @@
:key="3"
ref="functionInput"
id="function-input"
:lang="functionEditorLang"
:lang="functionInputLang"
lineNumbers="on"
:lineNumbersMinChars="2"
v-model="functionInputValue"
Expand All @@ -137,7 +124,7 @@
:key="4"
ref="schemaInput"
id="schema-input"
:lang="schemaEditorLang"
:lang="schemaInputLang"
lineNumbers="on"
:lineNumbersMinChars="2"
v-model="schemaInputValue"
Expand Down Expand Up @@ -183,7 +170,7 @@
@finish="handleUpload"
:title="activeTab === functionTab ? $t('script.importFunction') : $t('script.importSchema')"
:extension="extension"
:format="activeTab === functionTab ? functionList : schemaList"
:format="activeTab === functionTab ? currentFunction : currentSchema"
:visible.sync="showImportScript"
/>
</div>
Expand Down Expand Up @@ -219,7 +206,6 @@ export default class Script extends Vue {
{ label: 'Avro', value: 'avro' },
]
private functionList: FunctionList[] = [{ label: 'JavaScript', value: 'javascript' }]
// TODO: Because the editor does not support the parsing of the protobuf language, the editor language is temporarily set to javascript.
private currentSchema: SchemaType = 'protobuf'
private currentFunction: FunctionType = 'javascript'
private readonly inputTypeList: PayloadType[] = ['JSON', 'Plaintext', 'Base64', 'Hex']
Expand Down Expand Up @@ -255,8 +241,8 @@ export default class Script extends Vue {
private tempScriptId: string = ''
private functionInputType: PayloadType = 'JSON'
private schemaInputType: PayloadType = 'JSON'
private functionEditorLang = 'json'
private schemaEditorLang = 'json'
private functionInputLang = 'json'
private schemaInputLang = 'json'
// record content
private protoName: string = ''
private record: ScriptModel = {
Expand Down Expand Up @@ -314,12 +300,12 @@ message Person {

@Watch('functionInputType')
handleFunctionInputTypeChange(val: PayloadType) {
this.functionEditorLang = val === 'JSON' ? 'json' : 'plaintext'
this.functionInputLang = val === 'JSON' ? 'json' : 'plaintext'
}

@Watch('schemaInputType')
handleSchemaInputTypeChange(val: PayloadType) {
this.schemaEditorLang = val === 'JSON' ? 'json' : 'plaintext'
this.schemaInputLang = val === 'JSON' ? 'json' : 'plaintext'
}

get inUseScript() {
Expand All @@ -328,6 +314,24 @@ message Person {
)
}

get scriptEditorLang() {
switch (this.activeTab) {
case 'functionTab':
return 'javascript'

case 'schemaTab':
return (
{
protobuf: 'plaintext',
avro: 'json',
}[this.currentSchema] || 'plaintext'
)

default:
return 'plaintext'
}
}

private created() {
this.functionEditorValue = this.defaultFunction[this.currentFunction].content
this.schemaEditorValue = this.defaultSchema[this.currentSchema].content
Expand Down
Loading