* feat: 🎸 add filters applied tags under search/filter bar ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * feat: 🎸 create Rose::FilterTags component ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 use Rose::FilterTags component in targets list ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 update FilterTags to handle multiple queryParams ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * test: 💍 update dropdown component tests - applyFilter ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * feat: 🎸 create filter-tags component in core ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * chore: 🤖 update core addon to export styles ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 remove filter-tags component from rose addon ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * chore: 🤖 update sass package version ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * feat: 🎸 use FilterTags component in targets list screen ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 reduce component complexity ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * chore: 🤖 add sinon to core ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 update how FilterTags displays filters ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 trucate long tag names ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 wrap FilterTags component in if this.filters to fix issue of static text displaying before the dynamic tags ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069 * refactor: 💡 address feedback ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12069
93 lines
2.2 KiB
JavaScript
93 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import { debounce } from 'core/decorators/debounce';
|
|
|
|
export default class DropdownComponent extends Component {
|
|
// =attributes
|
|
|
|
@tracked selectedItems = [];
|
|
@tracked searchTerm;
|
|
|
|
/**
|
|
* Takes itemOptions and filters them by searchTerm if there is one
|
|
* @returns {[object]}
|
|
*/
|
|
get itemOptions() {
|
|
let items = this.args.itemOptions;
|
|
if (this.searchTerm) {
|
|
const searchTerm = this.searchTerm.toLowerCase();
|
|
items = this.args.itemOptions.filter((item) => {
|
|
const isNameMatch = item.name?.toLowerCase().includes(searchTerm);
|
|
const isIdMatch = item.id.includes(this.searchTerm);
|
|
return isNameMatch || isIdMatch;
|
|
});
|
|
}
|
|
return items;
|
|
}
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Sets searchTerm to be used for filtering itemOptions
|
|
* @param {object} event
|
|
*/
|
|
@action
|
|
@debounce(150)
|
|
filterItems(event) {
|
|
const { value } = event.target;
|
|
this.searchTerm = value;
|
|
}
|
|
|
|
/**
|
|
* Handles checkbox event changes for selectedItems
|
|
* @param {object} event
|
|
*/
|
|
@action
|
|
selectItem(event) {
|
|
const { checked, value } = event.target;
|
|
if (checked) {
|
|
this.selectedItems = [...this.selectedItems, value];
|
|
} else {
|
|
this.selectedItems = this.selectedItems.filter(
|
|
(scope) => scope !== value,
|
|
);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Pass selectedItems to applyFilter callback and call onClose
|
|
* @param {function} close
|
|
*/
|
|
@action
|
|
applyFilter(onClose) {
|
|
this.args.applyFilter(this.selectedItems);
|
|
onClose();
|
|
}
|
|
|
|
/**
|
|
* Sets selectedItems to checkedItems when the user opens
|
|
* the dropdown and potentially has made changes
|
|
* outside of the scope of dropdown
|
|
*/
|
|
@action
|
|
open() {
|
|
this.selectedItems = [...this.args.checkedItems];
|
|
}
|
|
|
|
/**
|
|
* Custom close method for dropdown that resets selectedItems
|
|
* to checkedItems when the user closes the dropdown
|
|
*/
|
|
@action
|
|
close() {
|
|
this.selectedItems = [...this.args.checkedItems];
|
|
this.searchTerm = '';
|
|
}
|
|
}
|