Skip to content

Commit

Permalink
improve(desktop): minor improvements
Browse files Browse the repository at this point in the history
1. expand the size of textboxes in Script -> Schema tab
2. use `$tc` instead of `$t` (i18n) to avoid type assertion
3. improve code style
  • Loading branch information
LAST7 authored and ysfscream committed Sep 14, 2024
1 parent afe5bcb commit 287be0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/components/UseScript.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class UseScript extends Vue {
this.functions = functions
this.schemas =
this.currentSchemaType == null
this.currentSchemaType === null
? []
: schemas.filter((s) => s.name.endsWith(this.defaultSchemaTypes[this.currentSchemaType!].extension))
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/scriptTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export const scriptTest = (
const avroResult = checkAvroInput(script, inputValue, inputType)
return avroResult
default:
return 'Test Error!'
return 'Test Error: Unsupported script type.'
}
}
11 changes: 5 additions & 6 deletions src/views/connections/ConnectionsDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1867,13 +1867,12 @@ export default class ConnectionsDetail extends Vue {
return payload
}
// TODO: separate Function and Schema from `ScriptState`
if (!this.scriptOption.schema.type || this.scriptOption.schema.type === 'javascript') {
this.$message.error('Convertion: Schema type is not defined or is not supported.')
return undefined
}
try {
// TODO: separate Function and Schema from `ScriptState`
if (!this.scriptOption.schema.type || this.scriptOption.schema.type === 'javascript') {
throw new Error('Conversion: Schema type is not defined or not supported.')
}
switch (msgType) {
case 'publish': {
return this.serializeWithSchema(
Expand Down
51 changes: 20 additions & 31 deletions src/views/script/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
<div
class="editor-container script-editor script-test-input"
:style="{
height: '80px',
height: '160px',
}"
>
<Editor
Expand Down Expand Up @@ -154,7 +154,7 @@
<el-row class="script-test-row script-test-output" :gutter="20">
<el-col :span="24">
<label>{{ $t('script.output') }}</label>
<el-input v-model="outputValue" type="textarea" rows="4" disabled></el-input>
<el-input v-model="outputValue" type="textarea" rows="16" disabled></el-input>
</el-col>
</el-row>

Expand Down Expand Up @@ -228,16 +228,16 @@ export default class Script extends Vue {
// function tab or schema tab
switch (this.activeTab) {
case 'functionTab':
return this.$t('script.uploadJs') as string
return this.$tc('script.uploadJs')
case 'schemaTab':
// protobuf or avro
switch (this.currentSchema) {
case 'protobuf':
return this.$t('script.uploadProto') as string
return this.$tc('script.uploadProto')
case 'avro':
return this.$t('script.uploadAvsc') as string
return this.$tc('script.uploadAvsc')
}
}
}
Expand Down Expand Up @@ -363,33 +363,22 @@ message Person {
)
}
} else {
switch (this.currentSchema) {
case 'protobuf':
if (!this.protoName) {
this.$message.warning(this.$tc('script.mustProtoName'))
return
}
this.outputValue = scriptTest(
this.schemaEditorValue,
this.currentSchema,
this.schemaInputValue,
this.schemaInputType,
{
name: this.protoName,
},
)
break
case 'avro':
this.outputValue = scriptTest(
this.schemaEditorValue,
this.currentSchema,
this.schemaInputValue,
this.schemaInputType,
)
break
// Send a warning message if proto name is not defined when testing protobuf
if (this.currentSchema === 'protobuf' && this.protoName === '') {
this.$message.warning(this.$tc('script.mustProtoName'))
return
}
// set the value in the output textbox
this.outputValue = scriptTest(
this.schemaEditorValue,
this.currentSchema,
this.schemaInputValue,
this.schemaInputType,
{
name: this.protoName,
},
)
}
} catch (error) {
this.$message.error((error as Error).toString())
Expand Down

0 comments on commit 287be0b

Please sign in to comment.