-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): make the one of component work properly (#6900)
- Loading branch information
1 parent
c6d6976
commit 4bb2fd5
Showing
3 changed files
with
136 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<template> | ||
<el-form-item> | ||
<el-select :model-value="selectedSchema" @update:model-value="onSelect"> | ||
<el-option | ||
v-for="schema in schemaOptions" | ||
:key="schema.label" | ||
:label="schema.label" | ||
:value="schema.value" | ||
/> | ||
</el-select> | ||
</el-form-item> | ||
<el-form label-position="top" v-if="selectedSchema"> | ||
<component | ||
:is="`task-${getType(currentSchema)}`" | ||
v-if="currentSchema" | ||
:model-value="modelValue" | ||
@update:model-value="onInput" | ||
:schema="currentSchema" | ||
:definitions="definitions" | ||
/> | ||
</el-form> | ||
</template> | ||
|
||
<script> | ||
import Task from "./Task"; | ||
import {mapState} from "vuex"; | ||
export default { | ||
mixins: [Task], | ||
data() { | ||
return { | ||
isOpen: false, | ||
schemas: [], | ||
selectedSchema: undefined, | ||
}; | ||
}, | ||
created() { | ||
this.schemas = this.schema?.oneOf ?? []; | ||
const schema = this.schemaOptions.find( | ||
(sch) => sch.id === this.modelValue.type, | ||
); | ||
this.onSelect(schema.value); | ||
// } | ||
}, | ||
methods: { | ||
onSelect(value) { | ||
this.selectedSchema = value; | ||
// Set up default values | ||
if ( | ||
this.currentSchema?.properties && | ||
this.modelValue === undefined | ||
) { | ||
const defaultValues = {}; | ||
for (let prop in this.currentSchema.properties) { | ||
if ( | ||
this.currentSchema.properties[prop].$required && | ||
this.currentSchema.properties[prop].default | ||
) { | ||
defaultValues[prop] = | ||
this.currentSchema.properties[prop].default; | ||
} | ||
} | ||
this.onInput(defaultValues); | ||
} | ||
}, | ||
}, | ||
computed: { | ||
...mapState("code", ["breadcrumbs"]), | ||
currentSchema() { | ||
return ( | ||
this.definitions[this.selectedSchema] ?? | ||
this.schemaByType[this.selectedSchema] | ||
); | ||
}, | ||
schemaByType() { | ||
return this.schemas.reduce((acc, schema) => { | ||
acc[schema.type] = schema; | ||
return acc; | ||
}, {}); | ||
}, | ||
schemaOptions() { | ||
return this.schemas.map((schema) => { | ||
const label = schema.$ref | ||
? schema.$ref.split("/").pop() | ||
: schema.type; | ||
return { | ||
label: label.capitalize(), | ||
value: label, | ||
id: label.split(".").pop().toLowerCase(), | ||
}; | ||
}); | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,48 @@ | ||
<template> | ||
<el-input | ||
:model-value="JSON.stringify(values)" | ||
:disabled="true" | ||
> | ||
<el-input :model-value="JSON.stringify(values)"> | ||
<template #append> | ||
<el-button :icon="Eye" @click="isOpen = true" /> | ||
</template> | ||
</el-input> | ||
|
||
<drawer | ||
v-if="isOpen" | ||
v-model="isOpen" | ||
> | ||
<template #header> | ||
<code>{{ root }}</code> | ||
</template> | ||
<el-form-item> | ||
<template #label> | ||
<span class="d-flex flex-grow-1"> | ||
<span class="me-auto"> | ||
<code> One of</code> | ||
</span> | ||
</span> | ||
</template> | ||
<el-select | ||
:model-value="selectedSchema" | ||
@update:model-value="onSelect" | ||
> | ||
<el-option | ||
v-for="schema in schemaOptions" | ||
:key="schema.label" | ||
:label="schema.label" | ||
:value="schema.value" | ||
/> | ||
</el-select> | ||
</el-form-item> | ||
<el-form label-position="top" v-if="selectedSchema"> | ||
<component | ||
:is="`task-${getType(currentSchema)}`" | ||
v-if="currentSchema" | ||
:model-value="modelValue" | ||
@update:model-value="onInput" | ||
:schema="currentSchema" | ||
:definitions="definitions" | ||
<el-button | ||
:icon="Eye" | ||
@click=" | ||
() => { | ||
$store.commit('code/addBreadcrumbs', { | ||
breadcrumb: { | ||
label: root, | ||
to: {}, | ||
component: h(OneOfContent, { | ||
modelValue, | ||
schema, | ||
definitions, | ||
'onUpdate:modelValue': onInput, | ||
}), | ||
}, | ||
position: | ||
breadcrumbs.length === 2 | ||
? 2 | ||
: breadcrumbs.length, | ||
}); | ||
} | ||
" | ||
/> | ||
</el-form> | ||
<template #footer> | ||
<el-button :icon="ContentSave" @click="isOpen = false" type="primary"> | ||
{{ $t("save") }} | ||
</el-button> | ||
</template> | ||
</drawer> | ||
</el-input> | ||
</template> | ||
|
||
<script setup> | ||
import {h} from "vue"; | ||
import Eye from "vue-material-design-icons/Eye.vue"; | ||
import ContentSave from "vue-material-design-icons/ContentSave.vue"; | ||
import OneOfContent from "./OneOfContent.vue"; | ||
</script> | ||
|
||
<script> | ||
import Task from "./Task" | ||
import Drawer from "../../Drawer.vue" | ||
import Task from "./Task"; | ||
import {mapState} from "vuex"; | ||
export default { | ||
mixins: [Task], | ||
components: {Drawer}, | ||
data() { | ||
return { | ||
isOpen: false, | ||
schemas: [], | ||
selectedSchema: undefined | ||
}; | ||
}, | ||
created() { | ||
this.schemas = this.schema?.oneOf ?? [] | ||
}, | ||
methods: { | ||
onSelect(value) { | ||
this.selectedSchema = value | ||
// Set up default values | ||
if (this.currentSchema.properties && this.modelValue === undefined) { | ||
const defaultValues = {}; | ||
for (let prop in this.currentSchema.properties) { | ||
if(this.currentSchema.properties[prop].$required && this.currentSchema.properties[prop].default) { | ||
defaultValues[prop] = this.currentSchema.properties[prop].default | ||
} | ||
} | ||
this.onInput(defaultValues); | ||
} | ||
} | ||
}, | ||
computed: { | ||
currentSchema() { | ||
return this.definitions[this.selectedSchema] ?? this.schemaByType[this.selectedSchema] | ||
}, | ||
schemaByType() { | ||
return this.schemas.reduce((acc, schema) => { | ||
acc[schema.type] = schema | ||
return acc | ||
}, {}) | ||
}, | ||
schemaOptions() { | ||
return this.schemas.map(schema => { | ||
const label = schema.$ref ? schema.$ref.split("/").pop() : schema.type | ||
return { | ||
label: label.capitalize(), | ||
value: label | ||
} | ||
}) | ||
} | ||
...mapState("code", ["breadcrumbs"]), | ||
}, | ||
}; | ||
</script> |