-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Added namespace search to client count #12577
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
68ca6cf
Added namespace search to client count
arnav28 0febf6c
Added changelog
arnav28 9e8c229
Added download csv component
arnav28 da2aea2
Added test for checking graph render
arnav28 d4524ab
Added documentation for the download csv component
arnav28 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,3 @@ | ||
```release-note:improvement | ||
ui: namespace search in client count views | ||
``` |
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,40 +1,102 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { tracked } from '@glimmer/tracking'; | ||
|
||
export default class HistoryComponent extends Component { | ||
max_namespaces = 10; | ||
|
||
@tracked selectedNamespace = null; | ||
|
||
// Determine if we have client count data based on the current tab, | ||
// since model is slightly different for current month vs history api | ||
get hasClientData() { | ||
if (this.args.tab === 'current') { | ||
return this.args.model.activity && this.args.model.activity.clients; | ||
} | ||
return this.args.model.activity && this.args.model.activity.total; | ||
} | ||
|
||
get barChartDataset() { | ||
// Show namespace graph only if we have more than 1 | ||
get showGraphs() { | ||
return ( | ||
this.args.model.activity && | ||
this.args.model.activity.byNamespace && | ||
this.args.model.activity.byNamespace.length > 1 | ||
); | ||
} | ||
|
||
// Construct the namespace model for the search select component | ||
get searchDataset() { | ||
if (!this.args.model.activity || !this.args.model.activity.byNamespace) { | ||
return null; | ||
} | ||
let dataset = this.args.model.activity.byNamespace; | ||
// Filter out root data | ||
dataset = dataset.filter(item => { | ||
return item.namespace_id !== 'root'; | ||
let dataList = this.args.model.activity.byNamespace; | ||
return dataList.map(d => { | ||
return { | ||
name: d['namespace_id'], | ||
id: d['namespace_path'] === '' ? 'root' : d['namespace_path'], | ||
}; | ||
}); | ||
// Show only top 10 namespaces | ||
dataset = dataset.slice(0, this.max_namespaces); | ||
} | ||
|
||
// Construct the namespace model for the bar chart component | ||
get barChartDataset() { | ||
if (!this.args.model.activity || !this.args.model.activity.byNamespace) { | ||
return null; | ||
} | ||
let dataset = this.args.model.activity.byNamespace.slice(0, this.max_namespaces); | ||
return dataset.map(d => { | ||
return { | ||
label: d['namespace_path'], | ||
label: d['namespace_path'] === '' ? 'root' : d['namespace_path'], | ||
non_entity_tokens: d['counts']['non_entity_tokens'], | ||
distinct_entities: d['counts']['distinct_entities'], | ||
total: d['counts']['clients'], | ||
}; | ||
}); | ||
} | ||
|
||
get showGraphs() { | ||
// Create namespaces data for csv format | ||
get getCsvData() { | ||
if (!this.args.model.activity || !this.args.model.activity.byNamespace) { | ||
return null; | ||
} | ||
return this.args.model.activity.byNamespace.length > 1; | ||
let results = '', | ||
namespaces = this.args.model.activity.byNamespace, | ||
fields = ['Namespace path', 'Active clients', 'Unique entities', 'Non-entity tokens']; | ||
|
||
results = fields.join(',') + '\n'; | ||
|
||
namespaces.forEach(function(item) { | ||
let path = item.namespace_path !== '' ? item.namespace_path : 'root', | ||
total = item.counts.clients, | ||
unique = item.counts.distinct_entities, | ||
non_entity = item.counts.non_entity_tokens; | ||
|
||
results += path + ',' + total + ',' + unique + ',' + non_entity + '\n'; | ||
}); | ||
return results; | ||
} | ||
|
||
// Get the namespace by matching the path from the namespace list | ||
getNamespace(path) { | ||
return this.args.model.activity.byNamespace.find(ns => { | ||
if (path === 'root') { | ||
return ns.namespace_path === ''; | ||
} | ||
return ns.namespace_path === path; | ||
}); | ||
} | ||
|
||
@action | ||
selectNamespace(value) { | ||
// In case of search select component, value returned is an array | ||
if (Array.isArray(value)) { | ||
this.selectedNamespace = this.getNamespace(value[0]); | ||
} else if (typeof value === 'object') { | ||
// While D3 bar selection returns an object | ||
this.selectedNamespace = this.getNamespace(value.label); | ||
} else { | ||
this.selectedNamespace = null; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
} | ||
|
||
.header-right { | ||
text-align: center; | ||
text-align: right; | ||
|
||
> button { | ||
font-size: $size-8; | ||
|
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,31 @@ | ||
import Component from '@glimmer/component'; | ||
import layout from '../templates/components/download-csv'; | ||
import { setComponentTemplate } from '@ember/component'; | ||
import { action } from '@ember/object'; | ||
|
||
/** | ||
* @module DownloadCsv | ||
* Download csv component is used to display a link which initiates a csv file download of the data provided by it's parent component. | ||
* | ||
* @example | ||
* ```js | ||
* <DownloadCsv @label={{'Export all namespace data'}} @csvData={{"Namespace path,Active clients /n nsTest5/,2725"}} @fileName={{'client-count.csv'}} /> | ||
* ``` | ||
* | ||
* @param {string} label - Label for the download link button | ||
* @param {string} csvData - Data in csv format | ||
* @param {string} fileName - Custom name for the downloaded file | ||
* | ||
*/ | ||
class DownloadCsvComponent extends Component { | ||
arnav28 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@action | ||
downloadCsv() { | ||
let hiddenElement = document.createElement('a'); | ||
hiddenElement.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURI(this.args.csvData)); | ||
hiddenElement.setAttribute('target', '_blank'); | ||
hiddenElement.setAttribute('download', this.args.fileName || 'vault-data.csv'); | ||
hiddenElement.click(); | ||
} | ||
} | ||
|
||
export default setComponentTemplate(layout, DownloadCsvComponent); |
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,3 @@ | ||
<button type="button" class="link" {{on "click" this.downloadCsv}}> | ||
{{or @label 'Download'}} | ||
</button> |
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 @@ | ||
export { default } from 'core/components/download-csv'; |
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.
nice call on adding these checks first