Skip to content
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

Merged
merged 23 commits into from
Feb 22, 2023
Merged

Conversation

jeffdaley
Copy link
Contributor

@jeffdaley jeffdaley commented Feb 8, 2023

Shows which filters are active for a given route.

CleanShot 2023-02-08 at 14 11 20

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 buttons to LinkTos. Instead of computing the queryParams onClick, we do it beforehand, which means we can pass them directly to the component's @query argument and our onClick function only has to close the dropdown.

@jeffdaley jeffdaley changed the title Show active filters below toolbar ActiveFilters service; Toolbar refactor Feb 8, 2023
@jeffdaley jeffdaley changed the title ActiveFilters service; Toolbar refactor Show active filters; Toolbar refactor Feb 8, 2023
Comment on lines -14 to -19
export enum FacetNames {
DocType = "docType",
Owners = "owners",
Status = "status",
Product = "product",
}
Copy link
Contributor Author

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

Comment on lines -68 to -121
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();
}
}
Copy link
Contributor Author

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

@jeffdaley jeffdaley marked this pull request as ready for review February 8, 2023 20:20
@jeffdaley jeffdaley requested a review from a team as a code owner February 13, 2023 22:33
Copy link
Contributor

@jfreda jfreda left a 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.

@jeffdaley jeffdaley merged commit 9ab2cba into main Feb 22, 2023
@jeffdaley jeffdaley deleted the jeffdaley/show-active-tags branch February 22, 2023 15:01
@jeffdaley
Copy link
Contributor Author

@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.

anuragprafulla referenced this pull request in razorpay/hermes Jun 27, 2023
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants