Skip to content

Commit

Permalink
merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
soorajshankar committed Sep 14, 2020
1 parent dd072a6 commit 66c8244
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 55 deletions.
99 changes: 76 additions & 23 deletions console/src/components/Services/Data/TableBrowseRows/EditItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import globals from '../../../../Globals';
import { E_ONGOING_REQ, editItem } from './EditActions';
import { findTable, generateTableDef } from '../../../Common/utils/pgUtils';
import { getTableBrowseRoute } from '../../../Common/utils/routesUtils';
import { TypedInput } from '../Common/Components/TypedInput';
import { fetchEnumOptions } from './EditActions';
import { filterFkOptions } from '../DataActions';
import styles from '../../../Common/TableCommon/Table.scss';

import { getExistingFKConstraints } from '../Common/Components/utils';
import { TableRow } from '../Common/Components/TableRow';

class EditItem extends Component {
constructor() {
Expand Down Expand Up @@ -98,13 +98,16 @@ class EditItem extends Component {
const refs = {};

const elements = columns.map((col, i) => {
const { column_name: colName } = col;
const colName = col.column_name;
const hasDefault = col.column_default && col.column_default.trim() !== '';
const isNullable = col.is_nullable && col.is_nullable !== 'NO';
const isIdentity = col.is_identity && col.is_identity !== 'NO';

const prevValue = oldItem[colName];

refs[colName] = {
insertRadioNode: null,
valueNode: null,
valueInput: null,
nullNode: null,
defaultNode: null,
};
Expand All @@ -120,21 +123,71 @@ class EditItem extends Component {
};

return (
<TableRow
key={i}
column={col}
setRef={(key, node) => (refs[colName][key] = node)}
enumOptions={enumOptions}
index={i}
prevValue={prevValue}
hasDefault={hasDefault}
fkOptions={fkOptions}
getFkOptions={this.handleSearchValueChange}
selectedOption={this.state.selectedFkOptions[colName]}
onFkValueChange={handleFkOptionChange}
refTables={refTables}
foreignKey={getForeignKey(col, schemas)}
/>
<div key={i} className={`form-group ${styles.displayFlexContainer}`}>
<label
className={'col-sm-3 control-label ' + styles.insertBoxLabel}
title={colName}
>
{colName}
</label>
<span
className={`${styles.radioLabel} ${styles.typedInputWrapper} radio-inline`}
>
<input
type="radio"
ref={node => {
refs[colName].valueNode = node;
}}
name={colName + '-value'}
value="option1"
/>
<TypedInput
inputRef={node => {
refs[colName].valueInput = node;
}}
prevValue={prevValue}
enumOptions={enumOptions}
col={col}
index={i}
hasDefault={hasDefault}
fkOptions={fkOptions}
getFkOptions={this.handleSearchValueChange}
selectedOption={this.state.selectedFkOptions[colName]}
onFkValueChange={handleFkOptionChange}
refTables={refTables}
foreignKey={getForeignKey(col, schemas)}
>
<>
<label className={styles.radioLabel + ' radio-inline'}>
<input
type="radio"
ref={node => {
refs[colName].nullNode = node;
}}
disabled={!isNullable}
name={colName + '-value'}
value="NULL"
defaultChecked={prevValue === null}
/>
<span className={styles.radioSpan}>NULL</span>
</label>
<label className={styles.radioLabel + ' radio-inline'}>
<input
type="radio"
ref={node => {
refs[colName].defaultNode = node;
}}
name={colName + '-value'}
value="option3"
disabled={!hasDefault && !isIdentity}
defaultChecked={isIdentity}
/>
<span className={styles.radioSpan}>Default</span>
</label>
</>
</TypedInput>
</span>
</div>
);
});

Expand Down Expand Up @@ -175,11 +228,11 @@ class EditItem extends Component {
} else if (this.state.selectedFkOptions[colName]) {
console.log({ state: this.state });
inputValues[colName] = this.state.selectedFkOptions[colName].value;
} else if (refs[colName].insertRadioNode.checked) {
} else if (refs[colName].valueNode.checked) {
inputValues[colName] =
refs[colName].valueNode.props !== undefined
? refs[colName].valueNode.props.value
: refs[colName].valueNode.value;
refs[colName].valueInput.props !== undefined
? refs[colName].valueInput.props.value
: refs[colName].valueInput.value;
}
});

Expand Down Expand Up @@ -256,4 +309,4 @@ const mapStateToProps = (state, ownProps) => {

const editItemConnector = connect => connect(mapStateToProps)(EditItem);

export default editItemConnector;
export default editItemConnector;
122 changes: 90 additions & 32 deletions console/src/components/Services/Data/TableInsertItem/InsertItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { ordinalColSort, getForeignKey } from '../utils';
import { insertItem, I_RESET, fetchEnumOptions } from './InsertActions';
import { setTable, filterFkOptions } from '../DataActions';
import { NotFoundError } from '../../../Error/PageNotFound';
import { findTable, generateTableDef } from '../../../Common/utils/pgUtils';
import {
findTable,
generateTableDef,
isColumnAutoIncrement,
} from '../../../Common/utils/pgUtils';
import { TypedInput } from '../Common/Components/TypedInput';
import styles from '../../../Common/TableCommon/Table.scss';
import { getExistingFKConstraints } from '../Common/Components/utils';
import { TableRow } from '../Common/Components/TableRow';

class InsertItem extends Component {
constructor() {
Expand All @@ -20,9 +24,8 @@ class InsertItem extends Component {
}

componentDidMount() {
const { tableName, dispatch } = this.props;
dispatch(setTable(tableName));
dispatch(fetchEnumOptions());
this.props.dispatch(setTable(this.props.tableName));
this.props.dispatch(fetchEnumOptions());
}

componentWillUnmount() {
Expand Down Expand Up @@ -98,18 +101,18 @@ class InsertItem extends Component {
const refs = {};

const elements = columns.map((col, i) => {
const { column_name: colName, is_identity, column_default } = col;
const hasDefault = column_default && column_default.trim() !== '';
const isIdentity = is_identity && is_identity !== 'NO';
const colName = col.column_name;
const hasDefault = col.column_default && col.column_default.trim() !== '';
const isNullable = col.is_nullable && col.is_nullable !== 'NO';
const isIdentity = col.is_identity && col.is_identity !== 'NO';
const isAutoIncrement = isColumnAutoIncrement(col);

refs[colName] = {
valueNode: null,
nullNode: null,
defaultNode: null,
insertRadioNode: null,
};
refs[colName] = { valueNode: null, nullNode: null, defaultNode: null };

const onChange = (e, val) => {
if (isAutoIncrement) return;
if (!isNullable && !hasDefault) return;

const textValue = typeof val === 'string' ? val : e.target.value;

const radioToSelectWhenEmpty =
Expand All @@ -121,6 +124,8 @@ class InsertItem extends Component {
radioToSelectWhenEmpty.checked = !textValue.length;
};
const onFocus = e => {
if (isAutoIncrement) return;
if (!isNullable && !hasDefault) return;
const textValue = e.target.value;
if (
textValue === undefined ||
Expand Down Expand Up @@ -148,23 +153,76 @@ class InsertItem extends Component {
};

return (
<TableRow
key={i}
column={col}
setRef={(key, node) => (refs[colName][key] = node)}
enumOptions={enumOptions}
index={i}
clone={clone}
onChange={onChange}
onFocus={onFocus}

fkOptions={fkOptions}
getFkOptions={this.handleSearchValueChange}
selectedOption={this.state.selectedFkOptions[colName]}
onFkValueChange={handleFkOptionChange}
refTables={refTables}
foreignKey={getForeignKey(col, schemas)}
/>
<div key={i} className={`form-group ${styles.displayFlexContainer}`}>
<label
className={'col-sm-2 control-label ' + styles.insertBoxLabel}
title={colName}
>
{colName}
</label>
<span
className={`${styles.radioLabel} ${styles.typedInputWrapper} radio-inline`}
>
<input
disabled={isAutoIncrement}
type="radio"
ref={node => {
refs[colName].insertRadioNode = node;
}}
name={colName + '-value'}
value="option1"
defaultChecked={!hasDefault & !isNullable}
/>
<TypedInput
inputRef={node => {
refs[colName].valueNode = node;
}}
enumOptions={enumOptions}
col={col}
clone={clone}
onChange={onChange}
onFocus={onFocus}
index={i}
fkOptions={fkOptions}
getFkOptions={this.handleSearchValueChange}
selectedOption={this.state.selectedFkOptions[colName]}
onFkValueChange={handleFkOptionChange}
refTables={refTables}
foreignKey={getForeignKey(col, schemas)}
>
<>
<label className={styles.radioLabel + ' radio-inline'}>
<input
type="radio"
ref={node => {
refs[colName].nullNode = node;
}}
disabled={!isNullable}
defaultChecked={isNullable}
name={colName + '-value'}
value="NULL"
data-test={`nullable-radio-${i}`}
/>
<span className={styles.radioSpan}>NULL</span>
</label>
<label className={styles.radioLabel + ' radio-inline'}>
<input
type="radio"
ref={node => {
refs[colName].defaultNode = node;
}}
name={colName + '-value'}
value="option3"
disabled={!hasDefault && !isIdentity}
defaultChecked={hasDefault || isIdentity}
data-test={`typed-input-default-${i}`}
/>
<span className={styles.radioSpan}>Default</span>
</label>
</>
</TypedInput>
</span>
</div>
);
});

Expand Down Expand Up @@ -310,4 +368,4 @@ const mapStateToProps = (state, ownProps) => {

const insertItemConnector = connect => connect(mapStateToProps)(InsertItem);

export default insertItemConnector;
export default insertItemConnector;

0 comments on commit 66c8244

Please sign in to comment.