Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added namespace search to client count (#12577)
* Added namespace search to client count - Used existing search select component for namespace search * Added changelog * Added download csv component - generate namespaces data in csv format - Show root in top 10 namespaces - Changed active direct tokens to non-entity tokens * Added test for checking graph render * Added documentation for the download csv component
- Loading branch information
Showing
9 changed files
with
177 additions
and
19 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,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 { | ||
@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