Skip to content

Commit 01fec00

Browse files
author
Aleksandra Sikora
committed
Add select fk to edit row
1 parent 88493f3 commit 01fec00

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

console/src/components/Services/Data/Common/Components/TypedInput.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ const searchableSelectStyles = {
2929
},
3030
};
3131

32+
const getSelectedFromPrev = (prevValue: string) => ({
33+
value: prevValue,
34+
label: prevValue,
35+
});
36+
3237
// TODO: value can be more that string
3338
type Option = { label: string; value: string };
3439

@@ -171,7 +176,7 @@ export const TypedInput: React.FC<Props> = ({
171176
{...standardInputProps}
172177
options={options}
173178
onChange={onFkValueChange}
174-
value={selectedOption}
179+
value={selectedOption || getSelectedFromPrev(prevValue)}
175180
bsClass={styles.insertBox}
176181
styleOverrides={searchableSelectStyles}
177182
onInputChange={(v: string) => setSearchValue(v)}

console/src/components/Services/Data/TableBrowseRows/EditItem.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,28 @@ import { findTable, generateTableDef } from '../../../Common/utils/pgUtils';
1313
import { getTableBrowseRoute } from '../../../Common/utils/routesUtils';
1414
import { TypedInput } from '../Common/Components/TypedInput';
1515
import { fetchEnumOptions } from './EditActions';
16+
import {
17+
loadConsoleOpts,
18+
getForeignKeyOptions,
19+
filterFkOptions,
20+
} from '../DataActions';
1621

1722
class EditItem extends Component {
1823
constructor() {
1924
super();
20-
this.state = { insertedRows: 0, editorColumnMap: {}, currentColumn: null };
25+
this.state = {
26+
insertedRows: 0,
27+
editorColumnMap: {},
28+
currentColumn: null,
29+
selectedFkOptions: {},
30+
};
2131
}
2232

2333
componentDidMount() {
2434
this.props.dispatch(fetchEnumOptions());
35+
this.props
36+
.dispatch(loadConsoleOpts())
37+
.then(() => this.props.dispatch(getForeignKeyOptions()));
2538
}
2639

2740
render() {
@@ -38,6 +51,7 @@ class EditItem extends Component {
3851
count,
3952
dispatch,
4053
enumOptions,
54+
fkOptions,
4155
} = this.props;
4256

4357
// check if item exists
@@ -80,23 +94,38 @@ class EditItem extends Component {
8094
defaultNode: null,
8195
};
8296

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+
83111
return (
84-
<div key={i} className="form-group">
112+
<div key={i} className={`form-group ${styles.displayFlexContainer}`}>
85113
<label
86114
className={'col-sm-3 control-label ' + styles.insertBoxLabel}
87115
title={colName}
88116
>
89117
{colName}
90118
</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' }}>
100129
<TypedInput
101130
inputRef={node => {
102131
refs[colName].valueInput = node;
@@ -106,8 +135,12 @@ class EditItem extends Component {
106135
col={col}
107136
index={i}
108137
hasDefault={hasDefault}
138+
fkOptions={fkOptions}
139+
getFkOptions={handleSearchValueChange}
140+
selectedOption={this.state.selectedFkOptions[colName]}
141+
onFkValueChange={handleFkOptionChange}
109142
/>
110-
</label>
143+
</span>
111144
<label className={styles.radioLabel + ' radio-inline'}>
112145
<input
113146
type="radio"
@@ -172,6 +205,8 @@ class EditItem extends Component {
172205
} else if (refs[colName].defaultNode.checked) {
173206
// default
174207
inputValues[colName] = { default: true };
208+
} else if (this.state.selectedFkOptions[colName]) {
209+
inputValues[colName] = this.state.selectedFkOptions[colName].value;
175210
} else if (refs[colName].valueNode.checked) {
176211
inputValues[colName] =
177212
refs[colName].valueInput.props !== undefined
@@ -247,6 +282,7 @@ const mapStateToProps = (state, ownProps) => {
247282
migrationMode: state.main.migrationMode,
248283
readOnlyMode: state.main.readOnlyMode,
249284
currentSchema: state.tables.currentSchema,
285+
fkOptions: state.tables.fkOptions,
250286
};
251287
};
252288

console/src/components/Services/Data/TableInsertItem/InsertItem.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ const mapStateToProps = (state, ownProps) => {
340340
migrationMode: state.main.migrationMode,
341341
readOnlyMode: state.main.readOnlyMode,
342342
currentSchema: state.tables.currentSchema,
343-
fkMappings: state.tables.fkMappings,
344343
fkOptions: state.tables.fkOptions,
345344
};
346345
};

0 commit comments

Comments
 (0)