-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ui: Replaces Service listing filterbar with a phrase-editor search (#5507) 1. New phrase-editor restricting search to whole phrases (acts on enter key). Allows removal of previously entered phrases 2. Searching now allows arrays of terms, multiple terms work via AND
- Loading branch information
Showing
18 changed files
with
289 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Component from '@ember/component'; | ||
import { get, set } from '@ember/object'; | ||
|
||
export default Component.extend({ | ||
classNames: ['phrase-editor'], | ||
item: '', | ||
remove: function(index, e) { | ||
this.items.removeAt(index, 1); | ||
this.onchange(e); | ||
}, | ||
add: function(e) { | ||
const value = get(this, 'item').trim(); | ||
if (value !== '') { | ||
set(this, 'item', ''); | ||
const currentItems = get(this, 'items') || []; | ||
const items = new Set(currentItems).add(value); | ||
if (items.size > currentItems.length) { | ||
set(this, 'items', [...items]); | ||
this.onchange(e); | ||
} | ||
} | ||
}, | ||
onkeydown: function(e) { | ||
switch (e.keyCode) { | ||
case 8: | ||
if (e.target.value == '' && this.items.length > 0) { | ||
this.remove(this.items.length - 1); | ||
} | ||
break; | ||
} | ||
}, | ||
oninput: function(e) { | ||
set(this, 'item', e.target.value); | ||
}, | ||
onchange: function(e) { | ||
let searchable = get(this, 'searchable'); | ||
if (!Array.isArray(searchable)) { | ||
searchable = [searchable]; | ||
} | ||
searchable.forEach(item => { | ||
item.search(get(this, 'items')); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
import { get } from '@ember/object'; | ||
import ucfirst from 'consul-ui/utils/ucfirst'; | ||
const find = function(obj, term) { | ||
if (Array.isArray(obj)) { | ||
return obj.some(function(item) { | ||
return find(item, term); | ||
}); | ||
} | ||
return obj.toLowerCase().indexOf(term) !== -1; | ||
}; | ||
export default function(filterable) { | ||
return filterable(function(item, { s = '' }) { | ||
const term = s.toLowerCase(); | ||
return ( | ||
get(item, 'Name') | ||
.toLowerCase() | ||
.indexOf(term) !== -1 || | ||
(get(item, 'Tags') || []).some(function(item) { | ||
return item.toLowerCase().indexOf(term) !== -1; | ||
}) | ||
); | ||
let status; | ||
switch (true) { | ||
case term.startsWith('service:'): | ||
return find(get(item, 'Name'), term.substr(8)); | ||
case term.startsWith('tag:'): | ||
return find(get(item, 'Tags') || [], term.substr(4)); | ||
case term.startsWith('status:'): | ||
status = term.substr(7); | ||
switch (term.substr(7)) { | ||
case 'warning': | ||
case 'critical': | ||
case 'passing': | ||
return get(item, `Checks${ucfirst(status)}`) > 0; | ||
default: | ||
return false; | ||
} | ||
default: | ||
return find(get(item, 'Name'), term) || find(get(item, 'Tags') || [], term); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
%with-icon { | ||
background-repeat: no-repeat; | ||
background-position: center; | ||
} | ||
%as-pseudo { | ||
display: inline-block; | ||
content: ''; | ||
visibility: visible; | ||
background-size: contain; | ||
} | ||
%with-cancel-plain-icon { | ||
@extend %with-icon; | ||
background-image: $cancel-plain-svg; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
@import './base-variables'; | ||
@import './base-placeholders'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@import './phrase-editor/index'; | ||
.phrase-editor { | ||
@extend %phrase-editor; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@import './skin'; | ||
@import './layout'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
%phrase-editor { | ||
display: flex; | ||
margin-top: 14px; | ||
margin-bottom: 5px; | ||
} | ||
%phrase-editor ul { | ||
overflow: hidden; | ||
} | ||
%phrase-editor li { | ||
@extend %pill; | ||
float: left; | ||
margin-right: 4px; | ||
} | ||
%phrase-editor span { | ||
display: none; | ||
} | ||
%phrase-editor label { | ||
flex-grow: 1; | ||
} | ||
%phrase-editor input { | ||
width: 100%; | ||
height: 33px; | ||
padding: 8px 10px; | ||
box-sizing: border-box; | ||
} | ||
@media #{$--horizontal-selects} { | ||
%phrase-editor { | ||
margin-top: 14px; | ||
} | ||
%phrase-editor ul { | ||
padding-top: 5px; | ||
padding-left: 5px; | ||
} | ||
%phrase-editor input { | ||
padding-left: 3px; | ||
} | ||
} | ||
@media #{$--lt-horizontal-selects} { | ||
%phrase-editor { | ||
margin-top: 9px; | ||
} | ||
%phrase-editor label { | ||
display: block; | ||
margin-top: 5px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@media #{$--horizontal-selects} { | ||
%phrase-editor { | ||
border: 1px solid $gray-300; | ||
border-radius: 2px; | ||
} | ||
%phrase-editor input:focus { | ||
outline: 0; | ||
} | ||
} | ||
@media #{$--lt-horizontal-selects} { | ||
%phrase-editor label { | ||
border: 1px solid $gray-300; | ||
border-radius: 2px; | ||
} | ||
} | ||
%phrase-editor input { | ||
-webkit-appearance: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
display: inline-block; | ||
padding: 1px 5px; | ||
} | ||
%pill button { | ||
padding: 0; | ||
margin-right: 3px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<ul> | ||
{{#each items as |item index|}} | ||
<li> | ||
<button type="button" onclick={{action remove index}}>Remove</button>{{item}} | ||
</li> | ||
{{/each}} | ||
</ul> | ||
<label class="type-search"> | ||
<span>Search</span> | ||
<input onchange={{action add}} onsearch={{action add}} oninput={{action oninput}} onkeydown={{action onkeydown}} placeholder="{{placeholder}}" value="{{item}}" type="search" name="s" autofocus="autofocus" /> | ||
</label> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.