Skip to content

Commit 61f48bb

Browse files
committed
Ens
1 parent a544656 commit 61f48bb

5 files changed

Lines changed: 66 additions & 86 deletions

File tree

frontend/src/components/modal/EditFieldModal.vue

Lines changed: 26 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<template>
22
<main class="field-modal-container">
3-
<div class="grid-2x2">
3+
<div class="input-container">
44
<div class="input-group">
5-
<label class="field-label">Field Name:</label>
5+
<label class="field-label">Field name</label>
66
<input class="field-input" v-model="fieldName" type="text" />
77
</div>
88

99
<div class="input-group">
10-
<label class="field-label">Type:</label>
10+
<label class="field-label">Type</label>
1111
<select class="field-select" v-model="type">
1212
<option disabled value="">-- Select type --</option>
1313
<option value="String">String</option>
@@ -20,25 +20,23 @@
2020
</div>
2121

2222
<div class="input-group">
23-
<label class="field-label">Default Value:</label>
23+
<label class="field-label">Default value</label>
2424
<input class="field-input" v-model="defaultValue" type="text" />
2525
</div>
2626

27-
<div class="input-group checkbox-inline">
28-
<label class="field-label">Primary Key:</label>
29-
<input type="checkbox" v-model="isPrimaryKey" />
30-
</div>
27+
3128
</div>
3229

3330
<div class="checkbox-group">
31+
<label><input type="checkbox" v-model="isPrimaryKey" /> Primary key</label>
3432
<label><input type="checkbox" v-model="isNullable" /> Nullable</label>
3533
<label><input type="checkbox" v-model="isUnique" /> Unique</label>
3634
<label><input type="checkbox" v-model="isIndex" /> Index</label>
3735
</div>
3836

3937
<div class="action-group">
40-
<button class="delete-field-btn" @click="deleteField">Delete</button>
4138
<button class="save-field-btn" @click="saveField">Save</button>
39+
<button class="delete-field-btn" @click="deleteField">Delete</button>
4240
</div>
4341
</main>
4442
</template>
@@ -89,77 +87,59 @@ const deleteField = () => {
8987
display: flex;
9088
flex-direction: column;
9189
gap: 1rem;
92-
border: 2px solid black;
9390
padding: 1rem;
94-
box-shadow: 4px 4px 0px black;
95-
background-color: #fff;
91+
background-color: #ffdb58;
9692
}
9793
98-
.grid-2x2 {
99-
display: grid;
100-
grid-template-columns: 1fr 1fr;
94+
.input-container {
95+
display: flex;
96+
flex-direction: column;
10197
gap: 1rem;
10298
}
10399
104100
.input-group {
105101
display: flex;
106102
flex-direction: column;
103+
gap: 0.15rem;
107104
}
108105
109-
.checkbox-inline {
110-
flex-direction: row;
111-
align-items: center;
112-
gap: 0.5rem;
113-
}
106+
114107
115108
.field-label {
116109
font-weight: bold;
117-
margin-bottom: 0.25rem;
110+
margin-bottom: 5px;
118111
}
119112
120113
.field-input,
121114
.field-select {
122115
border: 2px solid black;
123-
border-radius: 4px;
124-
padding: 0.5rem;
125-
box-shadow: 3px 3px 0px black;
126-
background-color: #f4f4f0;
127-
transition:
128-
transform 0.1s ease-in-out,
129-
box-shadow 0.1s ease-in-out;
130-
}
131-
132-
.field-input:focus,
133-
.field-select:focus {
134-
outline: none;
135-
transform: translate(2px, 2px);
136-
box-shadow: none;
116+
border-radius: 6px;
117+
padding: 0.6rem;
118+
background-color: white;
137119
}
138120
139121
.checkbox-group {
140122
display: flex;
141-
justify-content: space-between;
142-
gap: 1rem;
123+
flex-direction: column;
124+
gap: 0.5rem;
143125
font-weight: bold;
144126
}
145127
146128
.action-group {
129+
gap: 0.5rem;
130+
margin-top: 2rem;
147131
display: flex;
148-
justify-content: space-between;
149-
gap: 1rem;
132+
flex-direction: column;
150133
}
151134
152135
.delete-field-btn {
153-
align-self: flex-end;
136+
width: 100%;
154137
padding: 0.5rem 1rem;
155138
border: 2px solid black;
156139
border-radius: 4px;
157-
font-weight: bold;
158140
background-color: #ff6b6b;
159141
box-shadow: 3px 3px 0px black;
160-
transition:
161-
transform 0.1s ease-in-out,
162-
box-shadow 0.1s ease-in-out;
142+
transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out;
163143
}
164144
165145
.delete-field-btn:hover {
@@ -169,16 +149,13 @@ const deleteField = () => {
169149
}
170150
171151
.save-field-btn {
172-
align-self: flex-end;
152+
width: 100%;
173153
padding: 0.5rem 1rem;
174154
border: 2px solid black;
175155
border-radius: 4px;
176-
font-weight: bold;
177156
background-color: #2fff2f;
178157
box-shadow: 3px 3px 0px black;
179-
transition:
180-
transform 0.1s ease-in-out,
181-
box-shadow 0.1s ease-in-out;
158+
transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out;
182159
}
183160
184161
.save-field-btn:hover {

frontend/src/components/modal/GlobalModal.vue

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
<div class="modal">
55
<div class="modal-header">
66
<div class="modal-title">
7-
<slot name="title">Modal Title</slot>
7+
<div name="title">{{ modalTitle }}</div>
8+
</div>
9+
<div class="modal-actions" @click="close">
10+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-x h-4 w-4"><path d="M18 6 6 18"></path><path d="m6 6 12 12"></path></svg>
811
</div>
9-
<div class="modal-actions" @click="close">×</div>
1012
</div>
1113
<div class="modal-body">
1214
<component v-if="currentComponent" :is="currentComponent" v-bind="props" @close="close" />
@@ -21,7 +23,7 @@ import { storeToRefs } from "pinia"
2123
import { useModalStore } from "@/stores/useModalStore"
2224
2325
const modalStore = useModalStore()
24-
const { isOpen, currentComponent, props } = storeToRefs(modalStore)
26+
const { modalTitle, isOpen, currentComponent, props } = storeToRefs(modalStore)
2527
2628
function close() {
2729
modalStore.close()
@@ -43,51 +45,45 @@ function close() {
4345
}
4446
4547
.modal {
48+
font-family: sans-serif;
4649
border: 2px solid black;
4750
border-radius: 6px;
48-
box-shadow: 2px 2px 0px rgba(0, 0, 0, 1);
4951
overflow: hidden;
5052
background-color: white;
53+
max-width: 350px;
54+
width: 100%;
55+
margin: 0 1rem;
56+
display: flex;
57+
flex-direction: column;
5158
}
5259
5360
.modal-header {
5461
display: flex;
5562
justify-content: space-between;
5663
align-items: center;
57-
border-bottom: 2px solid black;
58-
width: 100%;
59-
height: 32px;
64+
background-color: #ffdb58;
65+
padding: 0.75rem 1rem;
6066
}
6167
6268
.modal-title {
6369
font-weight: bold;
64-
background-color: #ffdb58;
65-
width: 100%;
66-
height: 100%;
70+
flex-grow: 1;
6771
display: flex;
6872
align-items: center;
69-
justify-content: center;
70-
padding: 0 8px;
73+
font-size: 1rem;
7174
}
7275
7376
.modal-actions {
7477
cursor: pointer;
75-
width: 32px;
76-
height: 100%;
78+
width: 24px;
79+
height: 24px;
7780
display: flex;
7881
align-items: center;
7982
justify-content: center;
80-
border-left: 2px solid black;
81-
font-size: 1.2rem;
82-
}
83-
84-
.modal-actions:hover {
85-
background-color: #f0f0f0;
8683
}
8784
8885
.modal-body {
89-
display: flex;
90-
flex-direction: column;
91-
padding: 0;
86+
background-color: #ffdb58;
87+
overflow: hidden;
9288
}
9389
</style>

frontend/src/components/schema_editor/SchemaEditor.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import RenameNodeModal from "@/components/modal/RenameNodeModal.vue"
4545
import { useProjectStore } from "@/stores/store"
4646
import { VueFlow } from "@vue-flow/core"
4747
import { useModalStore } from "@/stores/useModalStore"
48-
import type { RelationalRelationField } from "@/types.types"
48+
import type { RelationalRelationField, RelationalField } from "@/types.types"
4949
5050
const store = useProjectStore()
5151
const modalStore = useModalStore()
@@ -63,23 +63,23 @@ const deleteNode = (id: string) => {
6363
}
6464
6565
const openRenameNodeModal = (id: string) => {
66-
modalStore.open(RenameNodeModal, { id })
66+
modalStore.open(id, RenameNodeModal, { id })
6767
}
6868
6969
const openAddFieldModal = (id: string) => {
70-
modalStore.open(AddFieldModal, { id })
70+
modalStore.open(id, AddFieldModal, { id })
7171
}
7272
73-
const openEditFieldModal = (id: string, field: object) => {
74-
modalStore.open(EditFieldModal, { id, field })
73+
const openEditFieldModal = (id: string, field: RelationalField) => {
74+
modalStore.open("Edit field", EditFieldModal, { id, field })
7575
}
7676
7777
const openAddRelationModal = (id: string) => {
78-
modalStore.open(AddRelationModal, { id })
78+
modalStore.open(id, AddRelationModal, { id })
7979
}
8080
8181
const openEditRelationModal = (id: string, relation: RelationalRelationField) => {
82-
modalStore.open(EditRelationModal, { id, relation })
82+
modalStore.open(relation.fieldName, EditRelationModal, { id, relation })
8383
}
8484
</script>
8585

frontend/src/stores/store.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export const useProjectStore = defineStore("projectSpec", () => {
154154
fieldName: string,
155155
) => {
156156
const node = findNodeById(source)
157-
if (!node) return
157+
if (!node) throw new Error(`Model does not exist: ${source}`)
158158
node.data.fields = node.data.fields.filter(
159159
(field) => field.name !== fieldName
160160
)
@@ -196,13 +196,12 @@ export const useProjectStore = defineStore("projectSpec", () => {
196196
(rel) => rel.fieldName === originalFieldName
197197
)
198198
node.data.relations[index] = relationData
199-
if (originalTarget === relationData.targetModel) return;
200199

201-
const edgeId = `(${source})-(${originalTarget})-(${originalFieldName})`
200+
const edgeId = formatEdgeId(source, originalTarget, originalFieldName)
202201
const edge = getEdgeById(edgeId)
203202
if (!edge) return;
204203

205-
const newEdgeId = `(${source})-(${relationData.targetModel})-(${relationData.fieldName})`
204+
const newEdgeId = formatEdgeId(source, relationData.targetModel, relationData.fieldName)
206205
edge.id = newEdgeId
207206
edge.source = source
208207
edge.target = relationData.targetModel
@@ -214,14 +213,18 @@ export const useProjectStore = defineStore("projectSpec", () => {
214213
return edges.value.find((edge) => edge.id === id)
215214
}
216215

216+
const formatEdgeId = (source: string, target: string, fieldName: string): string => {
217+
return `(${source})-(${target})-(${fieldName})`
218+
}
219+
217220
const createEdge = (
218221
source: string,
219222
target: string,
220223
fieldName: string
221224
): void => {
222225
if (source === target) return
223226
edges.value.push({
224-
id: `(${source})-(${target})-(${fieldName})`,
227+
id: formatEdgeId(source, target, fieldName),
225228
source,
226229
target,
227230
})
@@ -233,7 +236,7 @@ export const useProjectStore = defineStore("projectSpec", () => {
233236
fieldName: string
234237
) => {
235238
edges.value = edges.value.filter(
236-
(edge) => edge.id !== `(${source})-(${target})-(${fieldName})`
239+
(edge) => edge.id !== formatEdgeId(source, target, fieldName)
237240
)
238241
}
239242

frontend/src/stores/useModalStore.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,27 @@ import { ref, shallowRef, markRaw, type Component } from "vue"
33

44
export const useModalStore = defineStore("modal", () => {
55
const isOpen = ref(false)
6+
const modalTitle = ref("")
67
const currentComponent = shallowRef<Component | null>(null)
78
const props = ref<Record<string, any>>({})
89

9-
function open(component: Component, componentProps: Record<string, any> = {}) {
10+
function open(title: string, component: Component, componentProps: Record<string, any> = {}) {
1011
currentComponent.value = markRaw(component)
1112
props.value = componentProps
13+
modalTitle.value = title
1214
isOpen.value = true
1315
}
1416

1517
function close() {
1618
isOpen.value = false
1719
currentComponent.value = null
1820
props.value = {}
21+
modalTitle.value = ""
1922
}
2023

2124
return {
2225
isOpen,
26+
modalTitle,
2327
currentComponent,
2428
props,
2529
open,

0 commit comments

Comments
 (0)