mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
feat(UI): ForeignKeySelect implements BaseSelect component
This commit is contained in:
@ -1,23 +1,15 @@
|
||||
<template>
|
||||
<select
|
||||
<BaseSelect
|
||||
ref="editField"
|
||||
:options="foreigns"
|
||||
class="form-select pl-1 pr-4"
|
||||
:class="{'small-select': size === 'small'}"
|
||||
:value="currentValue"
|
||||
dropdown-class="select-sm"
|
||||
dropdown-container=".workspace-query-results > .vscroll"
|
||||
@change="onChange"
|
||||
@blur="$emit('blur')"
|
||||
>
|
||||
<option v-if="!isValidDefault" :value="modelValue">
|
||||
{{ modelValue === null ? 'NULL' : modelValue }}
|
||||
</option>
|
||||
<option
|
||||
v-for="row in foreignList"
|
||||
:key="row.foreign_column"
|
||||
:value="row.foreign_column"
|
||||
:selected="row.foreign_column === modelValue"
|
||||
>
|
||||
{{ row.foreign_column }} {{ cutText('foreign_description' in row ? ` - ${row.foreign_description}` : '') }}
|
||||
</option>
|
||||
</select>
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@ -26,8 +18,11 @@ import Tables from '@/ipc-api/Tables';
|
||||
import { useNotificationsStore } from '@/stores/notifications';
|
||||
import { useWorkspacesStore } from '@/stores/workspaces';
|
||||
import { TEXT, LONG_TEXT } from 'common/fieldTypes';
|
||||
import BaseSelect from '@/components/BaseSelect.vue';
|
||||
|
||||
export default {
|
||||
name: 'ForeignKeySelect',
|
||||
components: { BaseSelect },
|
||||
props: {
|
||||
modelValue: [String, Number],
|
||||
keyUsage: Object,
|
||||
@ -47,7 +42,8 @@ export default {
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
foreignList: []
|
||||
foreignList: [],
|
||||
currentValue: this.modelValue
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -55,6 +51,17 @@ export default {
|
||||
if (!this.foreignList.length) return true;
|
||||
if (this.modelValue === null) return false;
|
||||
return this.foreignList.some(foreign => foreign.foreign_column.toString() === this.modelValue.toString());
|
||||
},
|
||||
foreigns () {
|
||||
const list = [];
|
||||
|
||||
if (!this.isValidDefault)
|
||||
list.push({ value: this.modelValue, label: this.modelValue === null ? 'NULL' : this.modelValue });
|
||||
|
||||
for (const row of this.foreignList)
|
||||
list.push({ value: row.foreign_column, label: `${row.foreign_column} ${this.cutText('foreign_description' in row ? ` - ${row.foreign_description}` : '')}` });
|
||||
|
||||
return list;
|
||||
}
|
||||
},
|
||||
async created () {
|
||||
@ -95,8 +102,8 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onChange () {
|
||||
this.$emit('update:modelValue', this.$refs.editField.value);
|
||||
onChange (opt) {
|
||||
this.$emit('update:modelValue', opt.value);
|
||||
},
|
||||
cutText (val) {
|
||||
if (typeof val !== 'string') return val;
|
||||
|
Reference in New Issue
Block a user