Skip to content

Commit 90768a1

Browse files
committed
INT-1160: Validate duplicate keys
1 parent 0cd83e1 commit 90768a1

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"hadron-auto-update-manager": "^0.0.12",
105105
"hadron-compile-cache": "^0.1.0",
106106
"hadron-component-registry": "^0.3.0",
107-
"hadron-document": "^0.11.0",
107+
"hadron-document": "^0.12.0",
108108
"hadron-ipc": "^0.0.7",
109109
"hadron-module-cache": "^0.0.3",
110110
"hadron-package-manager": "0.1.0",

src/internal-packages/crud/lib/component/editable-key.jsx

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ const React = require('react');
77
*/
88
const EDITING = 'editing';
99

10+
/**
11+
* The duplicate key value.
12+
*/
13+
const DUPLICATE = 'duplicate';
14+
1015
/**
1116
* The document key class.
1217
*/
@@ -25,7 +30,7 @@ class EditableKey extends React.Component {
2530
constructor(props) {
2631
super(props);
2732
this.element = props.element;
28-
this.state = { editing: false };
33+
this.state = { duplcate: false, editing: false };
2934
}
3035

3136
/**
@@ -56,10 +61,22 @@ class EditableKey extends React.Component {
5661
onFocus={this.handleFocus.bind(this)}
5762
onChange={this.handleChange.bind(this)}
5863
onKeyDown={this.handleKeyDown.bind(this)}
59-
value={this.element.currentKey} />
64+
value={this.element.currentKey}
65+
title={this.renderTitle()} />
6066
);
6167
}
6268

69+
/**
70+
* Render the title.
71+
*
72+
* @returns {String} The title.
73+
*/
74+
renderTitle() {
75+
if (this.state.duplicate) {
76+
return `Duplicate key: '${this.element.currentKey}'`
77+
}
78+
return this.element.currentKey;
79+
}
6380
/**
6481
* When hitting a key on the last element some special things may happen.
6582
*
@@ -79,6 +96,11 @@ class EditableKey extends React.Component {
7996
handleChange(evt) {
8097
var value = evt.target.value;
8198
if (this.isEditable()) {
99+
if (this.element.isDuplicateKey(value)) {
100+
this.setState({ duplicate: true });
101+
} else if (this.state.duplicate) {
102+
this.setState({ duplicate: false });
103+
}
82104
this.element.rename(value);
83105
}
84106
}
@@ -116,7 +138,14 @@ class EditableKey extends React.Component {
116138
* @returns {String} The key style.
117139
*/
118140
style() {
119-
return this.state.editing ? `${KEY_CLASS} ${EDITING}` : KEY_CLASS;
141+
var style = KEY_CLASS;
142+
if (this.state.editing) {
143+
style = style.concat(` ${EDITING}`);
144+
}
145+
if (this.state.duplicate) {
146+
style = style.concat(` ${DUPLICATE}`);
147+
}
148+
return style;
120149
}
121150
}
122151

src/internal-packages/crud/styles/crud.less

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ input.editable-key {
310310
z-index: 10;
311311
margin-top: -1px;
312312
margin-bottom: -1px;
313+
314+
&.duplicate {
315+
border: 1px solid red;
316+
}
317+
}
318+
319+
&.duplicate {
320+
color: red;
313321
}
314322
}
315323

0 commit comments

Comments
 (0)