|
16 | 16 | <option value="DateTime">DateTime</option> |
17 | 17 | <option value="Boolean">Boolean</option> |
18 | 18 | <option value="Float">Float</option> |
| 19 | + <option value="Enum">Enum</option> |
| 20 | + </select> |
| 21 | + </div> |
| 22 | + |
| 23 | + <div class="input-group" v-if="type === 'Enum'"> |
| 24 | + <label class="field-label">Select Enum</label> |
| 25 | + <select class="field-select" v-model="selectedEnum"> |
| 26 | + <option disabled value="">-- Select Enum --</option> |
| 27 | + <option v-for="e in projectStore.enums" :key="e.name" :value="e"> |
| 28 | + {{ e.name }} |
| 29 | + </option> |
19 | 30 | </select> |
20 | 31 | </div> |
21 | 32 |
|
22 | 33 | <div class="input-group"> |
23 | 34 | <label class="field-label">Default value</label> |
24 | | - <input class="field-input" v-model="defaultValue" type="text" /> |
| 35 | + <select class="field-select" v-model="defaultValue" v-if="type === 'Enum'"> |
| 36 | + <option value="" /> |
| 37 | + <option v-for="v in selectedEnum?.values" :key="v.name" :value="v.name"> |
| 38 | + {{ v.name }} |
| 39 | + </option> |
| 40 | + </select> |
| 41 | + <input class="field-input" v-model="defaultValue" type="text" v-else /> |
25 | 42 | </div> |
26 | 43 | </div> |
27 | 44 |
|
|
40 | 57 | </template> |
41 | 58 |
|
42 | 59 | <script setup lang="ts"> |
43 | | -import { ref } from "vue" |
| 60 | +import { ref, onMounted } from "vue" |
44 | 61 | import { useProjectStore } from "@/stores/useProjectStore" |
45 | 62 | import { useModalStore } from "@/stores/useModalStore" |
46 | | -import type { Field } from "@/types/types" |
| 63 | +import type { EnumT, RelationalField } from "@/types/types" |
47 | 64 |
|
48 | 65 | const props = defineProps<{ |
49 | 66 | id: string |
50 | | - field: Field |
| 67 | + field: RelationalField |
51 | 68 | }>() |
52 | 69 |
|
53 | 70 | const projectStore = useProjectStore() |
54 | 71 | const modalStore = useModalStore() |
55 | 72 |
|
| 73 | +const selectedEnum = ref<EnumT | undefined>() |
| 74 | +onMounted(() => { |
| 75 | + if (props.field.type !== "Enum" || !props.field.typeEnum) return |
| 76 | + selectedEnum.value = projectStore.findEnumByName(props.field.typeEnum) |
| 77 | +}) |
| 78 | +
|
56 | 79 | const fieldName = ref(props.field.name) |
57 | 80 | const type = ref(props.field.type) |
58 | | -const defaultValue = ref(props.field.default || "") |
| 81 | +const defaultValue = ref(props.field.defaultValue || "") |
59 | 82 | const isPrimaryKey = ref(props.field.isPrimaryKey || false) |
60 | 83 | const isNullable = ref(props.field.isNullable || false) |
61 | 84 | const isUnique = ref(props.field.isUnique || false) |
62 | 85 | const isIndex = ref(props.field.isIndex || false) |
63 | 86 |
|
| 87 | +console.log(defaultValue.value) |
| 88 | +
|
64 | 89 | const saveField = () => { |
65 | 90 | projectStore.updateField(props.id, props.field.name, { |
66 | 91 | name: fieldName.value, |
67 | 92 | type: type.value, |
68 | | - default: defaultValue.value || undefined, |
| 93 | + typeEnum: selectedEnum.value?.name, |
| 94 | + defaultValue: defaultValue.value || undefined, |
69 | 95 | isPrimaryKey: isPrimaryKey.value, |
70 | 96 | isNullable: isNullable.value, |
71 | 97 | isUnique: isUnique.value, |
|
0 commit comments