@@ -13,15 +13,28 @@ import { findTable, generateTableDef } from '../../../Common/utils/pgUtils';
13
13
import { getTableBrowseRoute } from '../../../Common/utils/routesUtils' ;
14
14
import { TypedInput } from '../Common/Components/TypedInput' ;
15
15
import { fetchEnumOptions } from './EditActions' ;
16
+ import {
17
+ loadConsoleOpts ,
18
+ getForeignKeyOptions ,
19
+ filterFkOptions ,
20
+ } from '../DataActions' ;
16
21
17
22
class EditItem extends Component {
18
23
constructor ( ) {
19
24
super ( ) ;
20
- this . state = { insertedRows : 0 , editorColumnMap : { } , currentColumn : null } ;
25
+ this . state = {
26
+ insertedRows : 0 ,
27
+ editorColumnMap : { } ,
28
+ currentColumn : null ,
29
+ selectedFkOptions : { } ,
30
+ } ;
21
31
}
22
32
23
33
componentDidMount ( ) {
24
34
this . props . dispatch ( fetchEnumOptions ( ) ) ;
35
+ this . props
36
+ . dispatch ( loadConsoleOpts ( ) )
37
+ . then ( ( ) => this . props . dispatch ( getForeignKeyOptions ( ) ) ) ;
25
38
}
26
39
27
40
render ( ) {
@@ -38,6 +51,7 @@ class EditItem extends Component {
38
51
count,
39
52
dispatch,
40
53
enumOptions,
54
+ fkOptions,
41
55
} = this . props ;
42
56
43
57
// check if item exists
@@ -80,23 +94,38 @@ class EditItem extends Component {
80
94
defaultNode : null ,
81
95
} ;
82
96
97
+ const handleSearchValueChange = ( config , value ) => {
98
+ this . props . dispatch ( filterFkOptions ( config , value ) ) ;
99
+ } ;
100
+
101
+ const handleFkOptionChange = ( { value, label } ) => {
102
+ this . setState ( prev => ( {
103
+ ...prev ,
104
+ selectedFkOptions : {
105
+ ...prev . selectedFkOptions ,
106
+ [ colName ] : { value, label } ,
107
+ } ,
108
+ } ) ) ;
109
+ } ;
110
+
83
111
return (
84
- < div key = { i } className = " form-group" >
112
+ < div key = { i } className = { ` form-group ${ styles . displayFlexContainer } ` } >
85
113
< label
86
114
className = { 'col-sm-3 control-label ' + styles . insertBoxLabel }
87
115
title = { colName }
88
116
>
89
117
{ colName }
90
118
</ label >
91
- < label className = { styles . radioLabel + ' radio-inline' } >
92
- < input
93
- type = "radio"
94
- ref = { node => {
95
- refs [ colName ] . valueNode = node ;
96
- } }
97
- name = { colName + '-value' }
98
- value = "option1"
99
- />
119
+ < input
120
+ type = "radio"
121
+ ref = { node => {
122
+ refs [ colName ] . valueNode = node ;
123
+ } }
124
+ name = { colName + '-value' }
125
+ value = "option1"
126
+ style = { { marginTop : '10px' } }
127
+ />
128
+ < span style = { { padding : '0 12px' , paddingLeft : '8px' } } >
100
129
< TypedInput
101
130
inputRef = { node => {
102
131
refs [ colName ] . valueInput = node ;
@@ -106,8 +135,12 @@ class EditItem extends Component {
106
135
col = { col }
107
136
index = { i }
108
137
hasDefault = { hasDefault }
138
+ fkOptions = { fkOptions }
139
+ getFkOptions = { handleSearchValueChange }
140
+ selectedOption = { this . state . selectedFkOptions [ colName ] }
141
+ onFkValueChange = { handleFkOptionChange }
109
142
/>
110
- </ label >
143
+ </ span >
111
144
< label className = { styles . radioLabel + ' radio-inline' } >
112
145
< input
113
146
type = "radio"
@@ -172,6 +205,8 @@ class EditItem extends Component {
172
205
} else if ( refs [ colName ] . defaultNode . checked ) {
173
206
// default
174
207
inputValues [ colName ] = { default : true } ;
208
+ } else if ( this . state . selectedFkOptions [ colName ] ) {
209
+ inputValues [ colName ] = this . state . selectedFkOptions [ colName ] . value ;
175
210
} else if ( refs [ colName ] . valueNode . checked ) {
176
211
inputValues [ colName ] =
177
212
refs [ colName ] . valueInput . props !== undefined
@@ -247,6 +282,7 @@ const mapStateToProps = (state, ownProps) => {
247
282
migrationMode : state . main . migrationMode ,
248
283
readOnlyMode : state . main . readOnlyMode ,
249
284
currentSchema : state . tables . currentSchema ,
285
+ fkOptions : state . tables . fkOptions ,
250
286
} ;
251
287
} ;
252
288
0 commit comments