-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui: dashboard links #5704
Merged
+290
−57
Merged
ui: dashboard links #5704
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
90ff1d8
ui: Adds templated-anchor component and uses it (hidden for now)
3fe55bf
ui: Adds styles for templated-anchor
0cf1317
ui: Adds usage of `consul-dashboard-url` meta property
eabfc38
ui: Tweak regex to include Meta keys, and don't match empty hbs selector
9913fa5
ui: Add some integration tests for template regex
fc67f89
ui: catch malformed paths for template interpolation
d8d21c6
ui: Moves dashboard buttons to use localStorage rather than meta data
9172e36
ui: Reorganizes layout of settings, disable ENTER press
db07948
ui: Add some CSS to make the new Settings items look nicer
b3f0ab1
ui: Add settings as a dependency of the unit test
cde53ba
Merge branch 'ui-staging' into feature/ui-dashboard-links
johncowen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,73 @@ | ||
import Component from '@ember/component'; | ||
import { get, set, computed } from '@ember/object'; | ||
|
||
const createWeak = function(wm = new WeakMap()) { | ||
return { | ||
get: function(ref, prop) { | ||
let map = wm.get(ref); | ||
if (map) { | ||
return map[prop]; | ||
} | ||
}, | ||
set: function(ref, prop, value) { | ||
let map = wm.get(ref); | ||
if (typeof map === 'undefined') { | ||
map = {}; | ||
wm.set(ref, map); | ||
} | ||
map[prop] = value; | ||
return map[prop]; | ||
}, | ||
}; | ||
}; | ||
const weak = createWeak(); | ||
// Covers alpha-capitalized dot separated API keys such as | ||
// `{{Name}}`, `{{Service.Name}}` etc. but not `{{}}` | ||
const templateRe = /{{([A-Za-z.0-9_-]+)}}/g; | ||
export default Component.extend({ | ||
tagName: 'a', | ||
attributeBindings: ['href', 'rel', 'target'], | ||
rel: computed({ | ||
get: function(prop) { | ||
return weak.get(this, prop); | ||
}, | ||
set: function(prop, value) { | ||
switch (value) { | ||
case 'external': | ||
value = `${value} noopener noreferrer`; | ||
set(this, 'target', '_blank'); | ||
break; | ||
} | ||
return weak.set(this, prop, value); | ||
}, | ||
}), | ||
vars: computed({ | ||
get: function(prop) { | ||
return weak.get(this, prop); | ||
}, | ||
set: function(prop, value) { | ||
weak.set(this, prop, value); | ||
set(this, 'href', weak.get(this, 'template')); | ||
}, | ||
}), | ||
href: computed({ | ||
get: function(prop) { | ||
return weak.get(this, prop); | ||
}, | ||
set: function(prop, value) { | ||
weak.set(this, 'template', value); | ||
const vars = weak.get(this, 'vars'); | ||
if (typeof vars !== 'undefined' && typeof value !== 'undefined') { | ||
value = value.replace(templateRe, function(match, group) { | ||
try { | ||
return get(vars, group) || ''; | ||
} catch (e) { | ||
return ''; | ||
} | ||
}); | ||
return weak.set(this, prop, value); | ||
} | ||
return ''; | ||
}, | ||
}), | ||
}); |
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
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
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
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 @@ | ||
{{yield}} |
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,26 +1,40 @@ | ||
{{#hashicorp-consul id="wrapper" dcs=dcs dc=dc}} | ||
{{#app-view class="settings show"}} | ||
{{#block-slot 'header'}} | ||
<h1> | ||
Settings | ||
</h1> | ||
{{/block-slot}} | ||
{{#block-slot 'content'}} | ||
<p> | ||
These settings are specific to the Consul web UI. They are saved to local storage and persist through browser usage and visits. | ||
</p> | ||
<form> | ||
<fieldset> | ||
<h2>Blocking Queries</h2> | ||
<p>Automatically get updated catalog information without refreshing the page. Any changes made to services and nodes would be reflected in real time.</p> | ||
<div class="type-toggle"> | ||
<label> | ||
<input type="checkbox" name="client[blocking]" checked={{if item.client.blocking 'checked' }} onchange={{action 'change'}} /> | ||
<span>{{if item.client.blocking 'On' 'Off' }}</span> | ||
</label> | ||
</div> | ||
</fieldset> | ||
</form> | ||
{{/block-slot}} | ||
{{/app-view}} | ||
{{#app-view class="settings show"}} | ||
{{#block-slot 'header'}} | ||
<h1> | ||
Settings | ||
</h1> | ||
{{/block-slot}} | ||
{{#block-slot 'content'}} | ||
<div class="notice info"> | ||
<h3>Local Storage</h3> | ||
<p> | ||
These settings are immediately saved to local storage and persisted through browser usage. | ||
</p> | ||
</div> | ||
<form> | ||
<fieldset> | ||
<h2>Dashboard Links</h2> | ||
<p> | ||
Add a link to the service detail page in the UI to get quick access to a service-wide metrics dashboard. Enter the dashboard URL into the field below. You can use the placeholder {{Service.Name}} which will be replaced with the name of the service currently being viewed. | ||
</p> | ||
<label class="type-text"> | ||
<span>Link template for services</span> | ||
<input type="text" name="urls[service]" value={{item.urls.service}} onchange={{action 'change'}} onkeypress={{action 'key'}} onkeydown={{action 'key'}} /> | ||
<em>e.g. https://grafana.example.com/d/1/consul-service-mesh&orgid=1&service-name={{ '{{Service.Name}}' }}</em> | ||
</label> | ||
</fieldset> | ||
<fieldset> | ||
<h2>Blocking Queries</h2> | ||
<p>Keep catalog info up-to-date without refreshing the page. Any changes made to services and nodes would be reflected in real time.</p> | ||
<div class="type-toggle"> | ||
<label> | ||
<input type="checkbox" name="client[blocking]" checked={{if item.client.blocking 'checked' }} onchange={{action 'change'}} /> | ||
<span>{{if item.client.blocking 'On' 'Off' }}</span> | ||
</label> | ||
</div> | ||
</fieldset> | ||
</form> | ||
{{/block-slot}} | ||
{{/app-view}} | ||
{{/hashicorp-consul}} |
98 changes: 98 additions & 0 deletions
98
ui-v2/tests/integration/components/templated-anchor-test.js
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,98 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('templated-anchor', 'Integration | Component | templated anchor', { | ||
integration: true, | ||
}); | ||
|
||
test('it renders', function(assert) { | ||
[ | ||
{ | ||
href: 'http://localhost/?={{Name}}/{{ID}}', | ||
vars: { | ||
Name: 'name', | ||
ID: 'id', | ||
}, | ||
result: 'http://localhost/?=name/id', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{Name}}/{{ID}}', | ||
vars: { | ||
Name: '{{Name}}', | ||
ID: '{{ID}}', | ||
}, | ||
result: 'http://localhost/?={{Name}}/{{ID}}', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{deep.Name}}/{{deep.ID}}', | ||
vars: { | ||
deep: { | ||
Name: '{{Name}}', | ||
ID: '{{ID}}', | ||
}, | ||
}, | ||
result: 'http://localhost/?={{Name}}/{{ID}}', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{}}/{{}}', | ||
vars: { | ||
Name: 'name', | ||
ID: 'id', | ||
}, | ||
result: 'http://localhost/?={{}}/{{}}', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{Service_Name}}/{{Meta-Key}}', | ||
vars: { | ||
Service_Name: 'name', | ||
['Meta-Key']: 'id', | ||
}, | ||
result: 'http://localhost/?=name/id', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{Service_Name}}/{{Meta-Key}}', | ||
vars: { | ||
WrongPropertyName: 'name', | ||
['Meta-Key']: 'id', | ||
}, | ||
result: 'http://localhost/?=/id', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{.Name}}', | ||
vars: { | ||
['.Name']: 'name', | ||
}, | ||
result: 'http://localhost/?=', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{.}}', | ||
vars: { | ||
['.']: 'name', | ||
}, | ||
result: 'http://localhost/?=', | ||
}, | ||
{ | ||
href: 'http://localhost/?={{deep..Name}}', | ||
vars: { | ||
deep: { | ||
Name: 'Name', | ||
ID: 'ID', | ||
}, | ||
}, | ||
result: 'http://localhost/?=', | ||
}, | ||
].forEach(item => { | ||
this.set('item', item); | ||
this.render(hbs` | ||
{{#templated-anchor href=item.href vars=item.vars}} | ||
Dashboard link | ||
{{/templated-anchor}} | ||
`); | ||
assert.equal( | ||
this.$() | ||
.find('a') | ||
.attr('href'), | ||
item.result | ||
); | ||
}); | ||
}); | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could be missing something but it looks like this doesn't actually test the variable replacement? Do we know that regexp etc. works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these are just the auto generated tests when you use an ember generator to create your stubs. They generally just test the thing you generate can be instantiated.
I've added some integration tests with some basic usecases which cover the regex.