Skip to content

Commit 51fceed

Browse files
committed
Show input on edit tag
1 parent 2aad7d7 commit 51fceed

4 files changed

Lines changed: 98 additions & 14 deletions

File tree

js/components/blocks/ReposBlock.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const ReposBlock = React.createClass({
145145
{tag.key}
146146
{ isCurrentUser ?
147147
<FontAwesome
148-
className="tag-remove-icon"
148+
className="tag-icon tag-remove-icon"
149149
name="times"
150150
onClick={() => this.removeRepoTag(tag.key, tag.repos, repo.id)}
151151
/> :

js/components/blocks/TagsBlock.js

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ const TagsBlock = React.createClass({
2828
Reflux.connect(FilterStore, 'filterStore')
2929
],
3030

31+
getInitialState() {
32+
return({
33+
tagEditingKey: ''
34+
});
35+
},
36+
3137
componentDidMount() {
3238
const userID = this.props.openUser.id;
3339
const query = this.props.query;
@@ -73,18 +79,40 @@ const TagsBlock = React.createClass({
7379
//
7480
const openUserName = this.props.openUser.login;
7581
const tagKey = tag.key;
76-
const isRemoving = event && ~event.target.className.indexOf('tag-remove-icon');
82+
const targetClassName = event.target.className;
83+
const isRemoving = ~targetClassName.indexOf('tag-remove-icon');
84+
const isEditing = ~targetClassName.indexOf('tag-edit-icon');
85+
if (~targetClassName.indexOf('tag-edit-input')) {
86+
return;
87+
}
7788
if (isRemoving) {
7889
this.props.setFirebaseTags(tagKey);
7990
activeTags = _.difference(activeTags, [tagKey]);
8091
}
92+
else if (isEditing) {
93+
this.setState({
94+
tagEditingKey: tag.key
95+
});
96+
}
8197
else {
8298
activeTags = _.xor(activeTags, [tagKey]);
8399
}
84100
//
85-
const tagReposIds = this.getTagReposIds(this.props.tags, activeTags);
86-
FilterActions.setTagsReposIds(tagReposIds);
87-
FilterActions.setTags(activeTags);
101+
if (!isEditing) {
102+
const tagReposIds = this.getTagReposIds(this.props.tags, activeTags);
103+
FilterActions.setTagsReposIds(tagReposIds);
104+
FilterActions.setTags(activeTags);
105+
}
106+
},
107+
108+
handleKeyUp(e) {
109+
if (e.keyCode == 13) {
110+
this.submitTagEdit();
111+
}
112+
},
113+
114+
submitTagEdit() {
115+
this.props.editTag(this.state.tagEditingKey, this.refs.inputTagEdit.getValue().trim());
88116
},
89117

90118
render() {
@@ -120,19 +148,41 @@ const TagsBlock = React.createClass({
120148
let activeClass = filterStore && _.includes(filterStore.tags, tag.key) ?
121149
' active' :
122150
'';
151+
let editingClass = (this.state.tagEditingKey === tag.key) ?
152+
' active editing-tag' :
153+
'';
123154
//
124155
return (
125156
<span
126-
className={'tag' + activeClass}
157+
className={'tag' + activeClass + editingClass}
127158
key={'tag-' + tag.key}
128159
onClick={(e) => this.filterReposByTags(e, tag)}
129160
>
130-
{tag.key}
161+
{ this.state.tagEditingKey !== tag.key ?
162+
tag.key :
163+
<Input
164+
type="text"
165+
ref="inputTagEdit"
166+
defaultValue={tag.key}
167+
className="tag-edit-input"
168+
onKeyUp={(e) => this.handleKeyUp(e)}
169+
/>
170+
}
131171
{ isCurrentUser ?
132-
<FontAwesome
133-
className="tag-remove-icon"
134-
name="times"
135-
/> :
172+
[
173+
<FontAwesome
174+
key="tag-remove-icon"
175+
className="tag-icon tag-remove-icon"
176+
name="times"
177+
title="Remove tag"
178+
/>,
179+
<FontAwesome
180+
key="tag-edit-icon"
181+
className="tag-icon tag-edit-icon"
182+
name="pencil"
183+
title="Edit tag"
184+
/>
185+
]:
136186
null
137187
}
138188
</span>

less/components.less

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090

9191
.tag {
9292
.tag-decorations(@brand-primary);
93+
.no-select();
9394
font-size: @font-size-h4;
9495
margin-right: 5px;
9596
margin-bottom: 5px;
@@ -105,21 +106,44 @@
105106
}
106107

107108
.tag, .repo-tag {
108-
.tag-remove-icon {
109+
.tag-icon {
109110
visibility: hidden;
110111
position: absolute;
111112
right: 3px;
112-
top: 3px;
113113
font-size: 10px;
114114
cursor: pointer;
115115
}
116+
.tag-remove-icon {
117+
top: 3px;
118+
}
119+
.tag-edit-icon {
120+
bottom: 3px;
121+
}
116122
&:hover {
117-
.tag-remove-icon {
123+
.tag-icon {
118124
visibility: initial;
125+
&:hover {
126+
font-size: 16px;
127+
}
119128
}
120129
}
121130
}
122131

132+
.editing-tag {
133+
.tag-icon {
134+
visibility: hidden !important;
135+
}
136+
.form-group {
137+
margin-bottom: 0;
138+
}
139+
}
140+
141+
.tag-edit-input {
142+
color: darken(@brand-primary, 10%);
143+
border: 1px solid @brand-primary;
144+
font-size: @font-size-h4;
145+
}
146+
123147
.repo-tag {
124148
.text-overflow();
125149
.tag-decorations(@brand-primary);

less/mixins.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@
1515
background: @color;
1616
}
1717
}
18+
19+
.no-select {
20+
-webkit-touch-callout: none; /* iOS Safari */
21+
-webkit-user-select: none; /* Chrome/Safari/Opera */
22+
-khtml-user-select: none; /* Konqueror */
23+
-moz-user-select: none; /* Firefox */
24+
-ms-user-select: none; /* Internet Explorer/Edge */
25+
user-select: none; /* Non-prefixed version, currently
26+
not supported by any browser */
27+
}

0 commit comments

Comments
 (0)