1
- import { Row , Col , Select , Button , Popover , Table } from "@douyinfe/semi-ui" ;
1
+ import {
2
+ Row ,
3
+ Col ,
4
+ Select ,
5
+ Button ,
6
+ Popover ,
7
+ Table ,
8
+ Input ,
9
+ } from "@douyinfe/semi-ui" ;
2
10
import {
3
11
IconDeleteStroked ,
4
12
IconLoopTextStroked ,
@@ -13,6 +21,7 @@ import {
13
21
import { useDiagram , useUndoRedo } from "../../../hooks" ;
14
22
import i18n from "../../../i18n/i18n" ;
15
23
import { useTranslation } from "react-i18next" ;
24
+ import { useState } from "react" ;
16
25
17
26
const columns = [
18
27
{
@@ -27,8 +36,10 @@ const columns = [
27
36
28
37
export default function RelationshipInfo ( { data } ) {
29
38
const { setUndoStack, setRedoStack } = useUndoRedo ( ) ;
30
- const { tables, setRelationships, deleteRelationship } = useDiagram ( ) ;
39
+ const { tables, setRelationships, deleteRelationship, updateRelationship } =
40
+ useDiagram ( ) ;
31
41
const { t } = useTranslation ( ) ;
42
+ const [ editField , setEditField ] = useState ( { } ) ;
32
43
33
44
const swapKeys = ( ) => {
34
45
setUndoStack ( ( prev ) => [
@@ -121,6 +132,36 @@ export default function RelationshipInfo({ data }) {
121
132
122
133
return (
123
134
< >
135
+ < div className = "flex items-center mb-2.5" >
136
+ < div className = "text-md font-semibold break-keep" > { t ( "name" ) } : </ div >
137
+ < Input
138
+ value = { data . name }
139
+ validateStatus = { data . name . trim ( ) === "" ? "error" : "default" }
140
+ placeholder = { t ( "name" ) }
141
+ className = "ms-2"
142
+ onChange = { ( value ) => updateRelationship ( data . id , { name : value } ) }
143
+ onFocus = { ( e ) => setEditField ( { name : e . target . value } ) }
144
+ onBlur = { ( e ) => {
145
+ if ( e . target . value === editField . name ) return ;
146
+ setUndoStack ( ( prev ) => [
147
+ ...prev ,
148
+ {
149
+ action : Action . EDIT ,
150
+ element : ObjectType . RELATIONSHIP ,
151
+ component : "self" ,
152
+ rid : data . id ,
153
+ undo : editField ,
154
+ redo : { name : e . target . value } ,
155
+ message : t ( "edit_relationship" , {
156
+ refName : e . target . value ,
157
+ extra : "[name]" ,
158
+ } ) ,
159
+ } ,
160
+ ] ) ;
161
+ setRedoStack ( [ ] ) ;
162
+ } }
163
+ />
164
+ </ div >
124
165
< div className = "flex justify-between items-center mb-3" >
125
166
< div className = "me-3" >
126
167
< span className = "font-semibold" > { t ( "primary" ) } : </ span >
0 commit comments