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})
@@ -36,7 +38,7 @@ const importSuiteFormSubmit = async (formEl: FormInstance | undefined) => {
3638 emit (' created' )
3739 formEl .resetFields ()
3840 }, (e ) => {
39- ElMessage .error (e )
41+ ElMessage .error (e . message )
4042 })
4143 }
4244 })
@@ -69,12 +71,16 @@ const importSourceKinds = [{
6971 " name" : " Native" ,
7072 " value" : " native" ,
7173 " description" : " http://your-server/api/v1/suites/xxx/yaml?x-store-name=xxx"
74+ }, {
75+ " name" : " Native-Inline" ,
76+ " value" : " native-inline" ,
77+ " description" : " Native test suite content in YAML format"
7278}]
73- const placeholderOfImportURL = ref (" " )
79+ const importSourceDesc = ref (" " )
7480const kindChanged = (e ) => {
7581 importSourceKinds .forEach (k => {
7682 if (k .value === e ) {
77- placeholderOfImportURL .value = k .description
83+ importSourceDesc .value = k .description
7884 }
7985 });
8086}
@@ -117,8 +123,15 @@ const kindChanged = (e) => {
117123 />
118124 </el-select >
119125 </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" />
126+ <el-form-item label =" Data" prop =" data" v-if =" importSuiteForm.kind === 'native-inline'" >
127+ <el-input v-model =" importSuiteForm.data"
128+ class =" full-width" type =" textarea"
129+ :placeholder =" importSourceDesc" />
130+ </el-form-item >
131+ <el-form-item label =" URL" prop =" url" v-else >
132+ <el-input v-model =" importSuiteForm.url" test-id =" suite-import-form-api"
133+ class =" full-width"
134+ :placeholder =" importSourceDesc" />
122135 </el-form-item >
123136 <el-form-item >
124137 <el-button
@@ -130,3 +143,9 @@ const kindChanged = (e) => {
130143 </el-form >
131144 </el-dialog >
132145</template >
146+
147+ <style scoped>
148+ .full-width {
149+ width : 100% ;
150+ }
151+ </style >
0 commit comments