Skip to content

Commit

Permalink
Client count namespace filter (#13881)
Browse files Browse the repository at this point in the history
* setup

* add forward slash

* fix icon issue

* add to current view

* fixes

* change

* final cleanup

* remove todo
  • Loading branch information
Monkeychip authored and fairclothjm committed Feb 12, 2022
1 parent 96aa1a6 commit fa68cbd
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 17 deletions.
11 changes: 11 additions & 0 deletions ui/app/components/clients/current.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class Current extends Component {
chartLegend = [
{ key: 'entity_clients', label: 'entity clients' },
{ key: 'non_entity_clients', label: 'non-entity clients' },
];
@tracked namespaceArray = this.args.model.monthly?.byNamespace.map((namespace) => {
return { name: namespace['label'], id: namespace['label'] };
});
@tracked selectedNamespace = null;

// TODO CMB get from model
Expand Down Expand Up @@ -46,4 +50,11 @@ export default class Current extends Component {
filterByNamespace(namespace) {
return this.byNamespaceCurrent.find((ns) => ns.label === namespace);
}

// ACTIONS
@action
selectNamespace([value]) {
// value comes in as [namespace0]
this.selectedNamespace = value;
}
}
17 changes: 6 additions & 11 deletions ui/app/components/clients/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export default class Dashboard extends Component {
@tracked startYear = null;
@tracked selectedNamespace = null;
@tracked noActivityDate = '';
// @tracked selectedNamespace = 'namespace18anotherlong/'; // for testing namespace selection view with mirage
@tracked namespaceArray = this.args.model.activity?.byNamespace.map((namespace) => {
return { name: namespace['label'], id: namespace['label'] };
});

get startTimeDisplay() {
if (!this.startTimeFromResponse) {
Expand Down Expand Up @@ -173,16 +175,9 @@ export default class Dashboard extends Component {
}

@action
selectNamespace(value) {
// In case of search select component, value returned is an array
if (Array.isArray(value)) {
this.selectedNamespace = this.getNamespace(value[0]);
this.barChartSelection = false;
} else if (typeof value === 'object') {
// While D3 bar selection returns an object
this.selectedNamespace = this.getNamespace(value.label);
this.barChartSelection = true;
}
selectNamespace([value]) {
// value comes in as [namespace0]
this.selectedNamespace = value;
}

@action
Expand Down
3 changes: 2 additions & 1 deletion ui/app/styles/components/icon.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
.flight-icon {
&.flight-icon-display-inline {
vertical-align: middle;
margin: 0px 4px;
margin-left: 4px;
margin-right: 4px;
}
}
8 changes: 8 additions & 0 deletions ui/app/styles/components/search-select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ div > .ember-power-select-options {
width: 20px;
top: 5px;
}

.search-icon {
margin-top: 4px;
}

.search-select.display-inherit {
display: inherit;
}
11 changes: 10 additions & 1 deletion ui/app/templates/components/clients/current.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
FILTERS
<Toolbar>
<ToolbarFilters>
{{! ARG TODO more filters for namespace here }}
<SearchSelect
@id="namespace-search-select-monthly"
@options={{this.namespaceArray}}
@selectLimit="1"
@disallowNewItems={{true}}
@fallbackComponent="input-search"
@onChange={{this.selectNamespace}}
@placeholder={{"Filter by namespace"}}
@displayInherit={{true}}
/>
</ToolbarFilters>
</Toolbar>
</div>
Expand Down
13 changes: 11 additions & 2 deletions ui/app/templates/components/clients/dashboard.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@
@handleCurrentBillingPeriod={{this.handleCurrentBillingPeriod}}
@startTimeDisplay={{this.startTimeDisplay}}
/>
{{#if this.totalClientsData}}
{{! ARG TODO more filters for namespace here }}
{{#if this.namespaceArray}}
<SearchSelect
@id="namespace-search-select"
@options={{this.namespaceArray}}
@selectLimit="1"
@disallowNewItems={{true}}
@fallbackComponent="input-search"
@onChange={{this.selectNamespace}}
@placeholder={{"Filter by namespace"}}
@displayInherit={{true}}
/>
{{/if}}
</ToolbarFilters>
</Toolbar>
Expand Down
5 changes: 4 additions & 1 deletion ui/lib/core/addon/components/search-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ import layout from '../templates/components/search-select';
* @param {string} [subText] - Text to be displayed below the label
* @param {string} [subLabel] - a smaller label below the main Label
* @param {string} [wildcardLabel] - when you want the searchSelect component to return a count on the model for options returned when using a wildcard you must provide a label of the count e.g. role. Should be singular.
* @param {string} [placeholder] - text you wish to replace the default "search" with
* @param {boolean} [displayInherit] - if you need the search select component to display inherit instead of box.
*
* @param {Array} options - *Advanced usage* - `options` can be passed directly from the outside to the
* power-select component. If doing this, `models` should not also be passed as that will overwrite the
* passed value.
* passed value. ex: [{ name: 'namespace45', id: 'displayedName' }];
* @param {function} search - *Advanced usage* - Customizes how the power-select component searches for matches -
* see the power-select docs for more information.
*
*/
export default Component.extend({
layout,
'data-test-component': 'search-select',
classNameBindings: ['displayInherit:display-inherit'],
classNames: ['field', 'search-select'],
store: service(),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="field">
<p class="control has-icons-left has-icons-right">
<span class="input has-text-grey-light">Search</span>
<span class="input has-text-grey-light">{{or this.placeholder "Search"}}</span>
<Icon @name="search" class="search-icon has-text-grey-light" />
</p>
</div>
1 change: 1 addition & 0 deletions ui/lib/core/addon/templates/components/search-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{{#unless (gte this.selectedOptions.length this.selectLimit)}}
<PowerSelect
@eventType="click"
@placeholder={{this.placeholder}}
@searchEnabled={{true}}
@search={{action "searchAndSuggest"}}
@options={{this.options}}
Expand Down

0 comments on commit fa68cbd

Please sign in to comment.