-
Notifications
You must be signed in to change notification settings - Fork 100
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
Show active filters; Toolbar refactor #37
Conversation
export enum FacetNames { | ||
DocType = "docType", | ||
Owners = "owners", | ||
Status = "status", | ||
Product = "product", | ||
} |
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.
Moved this to toolbar.ts
handleClick(name, value) { | ||
// Build filters (selected facet values). | ||
let filters = { | ||
docType: [], | ||
owners: [], | ||
status: [], | ||
product: [], | ||
}; | ||
for (const facet in this.args.facets) { | ||
let selectedFacetVals = []; | ||
for (const facetVal in this.args.facets[facet]) { | ||
if (this.args.facets[facet][facetVal]["selected"]) { | ||
selectedFacetVals.push(facetVal); | ||
} | ||
} | ||
filters[facet] = selectedFacetVals; | ||
} | ||
|
||
// Update filters based on what facet value was clicked and if it was | ||
// previously selected or not. | ||
if (this.args.facets[name][value]["selected"]) { | ||
// Facet value was already selected so we need to remove it. | ||
const index = filters[name].indexOf(value); | ||
if (index > -1) { | ||
filters[name].splice(index, 1); | ||
} | ||
} else { | ||
// Facet value wasn't selected before so now we need to add it. | ||
filters[name].push(value); | ||
} | ||
|
||
this.router.transitionTo({ | ||
queryParams: { | ||
docType: filters["docType"], | ||
owners: filters["owners"], | ||
page: 1, | ||
product: filters["product"], | ||
status: filters["status"], | ||
}, | ||
}); | ||
} | ||
|
||
@action | ||
updateSortBy(value, closeDropdown) { | ||
this.toolbar.sortBy = value; | ||
|
||
this.router.transitionTo({ | ||
queryParams: { | ||
sortBy: value, | ||
}, | ||
}); | ||
closeDropdown(); | ||
} | ||
} |
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.
This is the removed chunk
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.
Looks reasonable to me - excited for this!
Design q (not blocking, just something I was thinking about): do you think we might want to differentiate the type of active filters somehow? It's probably mostly obvious which type each one is, but wondering if we'd want to label them something like type:RFC
, product:Terraform
etc. Not totally sure how I feel about this right now (there's a tradeoff of it looking busier) but wanted to see what you think.
@jfreda I tried it early on but it felt redundant, like the filters were obvious enough as types/products, etc. But I'll explore it further; it has potential to be helpful. |
* Merge Facet types * Convert toolbar to TS * Add Toolbar types * Documentation * Add tests * Cleanup * Renames, docs, cleanup * Refactor `handleClick` * Toolbar Service with working filters on all routes * Working LinkTo filters * Design tags * Route-based filters * Improve dropdown closing and model loading * Tests, cleanup and rearranging * Move styles to SCSS; Documentation; Cleanup * Test `get-facet-query-hash` * Refactor route promises
Shows which filters are active for a given route.
The newly created
ActiveFilters
service captures a route's queryParams (i.e., active filters) whenever its model is loaded or refreshed. This creates a shared index of active filters for components and helpers to compute off. In general, this lets us be more efficient with queryParams: You'll notice the URLs are more concise, for example.You'll also see that the facet and sort controls have switched from
button
s toLinkTo
s. Instead of computing the queryParamsonClick
, we do it beforehand, which means we can pass them directly to the component's@query
argument and ouronClick
function only has to close the dropdown.