FilterItems filters items based on current builder tags.
()
| 545 | |
| 546 | // FilterItems filters items based on current builder tags. |
| 547 | func (v *PricingView) FilterItems() { |
| 548 | rTags := lowered(v.CommandBuilder.RegionTags) |
| 549 | pTags := lowered(v.CommandBuilder.ProductTags) |
| 550 | aTags := lowered(v.CommandBuilder.AttributeTags) |
| 551 | priceTags := lowered(v.CommandBuilder.PriceTags) |
| 552 | |
| 553 | if len(rTags) == 0 && len(pTags) == 0 && len(aTags) == 0 && len(priceTags) == 0 { |
| 554 | v.FilteredItems = append([]PricingDisplayItem{}, v.Items...) |
| 555 | v.Selected = 0 |
| 556 | return |
| 557 | } |
| 558 | |
| 559 | var filtered []PricingDisplayItem |
| 560 | for _, item := range v.Items { |
| 561 | regionOK := len(rTags) == 0 || containsAny(strings.ToLower(item.Region), rTags) |
| 562 | productOK := len(pTags) == 0 || containsAny(strings.ToLower(item.Product), pTags) |
| 563 | attrsOK := attrMatch(item, aTags) |
| 564 | priceOK := priceMatch(item, priceTags) |
| 565 | if regionOK && productOK && attrsOK && priceOK { |
| 566 | filtered = append(filtered, item) |
| 567 | } |
| 568 | } |
| 569 | v.FilteredItems = filtered |
| 570 | v.Selected = 0 |
| 571 | } |
| 572 | |
| 573 | func lowered(ss []string) []string { |
| 574 | out := make([]string, len(ss)) |
no test coverage detected