11<script setup lang="ts">
22import { useI18n } from ' vue-i18n'
33import { reactive , ref } from ' vue'
4- import type { Suite } from ' @/views/types'
54import { API } from ' @/views/net'
65import { ElMessage } from ' element-plus'
6+ import type { ImportSource } from ' @/views/net'
77import type { FormInstance , FormRules } from ' element-plus'
88
99const { t } = useI18n ()
@@ -16,14 +16,16 @@ const importSuiteFormRef = ref<FormInstance>()
1616const importSuiteForm = reactive ({
1717 url: ' ' ,
1818 store: ' ' ,
19- kind: ' '
20- })
19+ kind: ' ' ,
20+ data: ' '
21+ } as ImportSource )
2122
22- const importSuiteFormRules = reactive <FormRules <Suite >>({
23+ const importSuiteFormRules = reactive <FormRules <ImportSource >>({
2324 url: [
24- { required: true , message: ' URL is required' , trigger: ' blur' },
25+ { required: importSuiteForm . kind !== ' native-inline ' , message: ' URL is required' , trigger: ' blur' },
2526 { type: ' url' , message: ' Should be a valid URL value' , trigger: ' blur' }
2627 ],
28+ data: [{ required: importSuiteForm .kind === ' native-inline' , message: ' Data is required' , trigger: ' blur' }],
2729 store: [{ required: true , message: ' Location is required' , trigger: ' blur' }],
2830 kind: [{ required: true , message: ' Kind is required' , trigger: ' blur' }]
2931})
@@ -32,6 +34,9 @@ const importSuiteFormSubmit = async (formEl: FormInstance | undefined) => {
3234 if (! formEl ) return
3335 await formEl .validate ((valid : boolean ) => {
3436 if (valid ) {
37+ if (importSuiteForm .kind === ' native-inline' ) {
38+ importSuiteForm .kind = ' native'
39+ }
3540 API .ImportTestSuite (importSuiteForm , () => {
3641 emit (' created' )
3742 formEl .resetFields ()
@@ -69,12 +74,16 @@ const importSourceKinds = [{
6974 " name" : " Native" ,
7075 " value" : " native" ,
7176 " description" : " http://your-server/api/v1/suites/xxx/yaml?x-store-name=xxx"
77+ }, {
78+ " name" : " Native-Inline" ,
79+ " value" : " native-inline" ,
80+ " description" : " Native test suite content in YAML format"
7281}]
73- const placeholderOfImportURL = ref (" " )
82+ const importSourceDesc = ref (" " )
7483const kindChanged = (e ) => {
7584 importSourceKinds .forEach (k => {
7685 if (k .value === e ) {
77- placeholderOfImportURL .value = k .description
86+ importSourceDesc .value = k .description
7887 }
7988 });
8089}
@@ -117,8 +126,15 @@ const kindChanged = (e) => {
117126 />
118127 </el-select >
119128 </el-form-item >
120- <el-form-item label =" URL" prop =" url" >
121- <el-input v-model =" importSuiteForm.url" test-id =" suite-import-form-api" :placeholder =" placeholderOfImportURL" />
129+ <el-form-item label =" Data" prop =" data" v-if =" importSuiteForm.kind === 'native-inline'" >
130+ <el-input v-model =" importSuiteForm.data"
131+ class =" full-width" type =" textarea"
132+ :placeholder =" importSourceDesc" />
133+ </el-form-item >
134+ <el-form-item label =" URL" prop =" url" v-else >
135+ <el-input v-model =" importSuiteForm.url" test-id =" suite-import-form-api"
136+ class =" full-width"
137+ :placeholder =" importSourceDesc" />
122138 </el-form-item >
123139 <el-form-item >
124140 <el-button
@@ -130,3 +146,9 @@ const kindChanged = (e) => {
130146 </el-form >
131147 </el-dialog >
132148</template >
149+
150+ <style scoped>
151+ .full-width {
152+ width : 100% ;
153+ }
154+ </style >
0 commit comments