Hello everybody
,
I am trying to create a custom filter that would allow me to filter subdomains (I am trying to follow https://backstage.io/docs/features/software-catalog/catalog-customization#custom-filters), idea is that I would check for optional .spec.subdomainOf if it is present in any form I can say that entity is subdomain of different entity, if not that it is domain. But from what I understood and tested it seems that custom filters basically only support some predetermined values, such as some specific annotation
. Is there some way to work around that or do I missunderstand it and there is some mainstream solution for this?
Thanks for any help!
#Creating custom filter for subdomains
5 messages · Page 1 of 1 (latest)
Hello, just a small update from my side I have now resolved it by adding "dummy" value to subdomain in postprocessor so now filtering works fine, but I have one additional question, can I somewhere override default behaviour where when I access entity from sidebar, url gets truncated to default?
What I mean:
I have added sidebar item where I have my custom filter, so it looks like this:
catalog?filters[kind]=domain&filters[customFilter]=value
but when I want click on the item it gets truncated to:
catalog?filters[kind]=domain
This seems to be the case onl y for custom filter, is there some way to override this behaviour?
Hi @remote depot, in the EntityFilter code example you get the actual entity:
import { EntityFilter } from '@backstage/plugin-catalog-react';
import { Entity } from '@backstage/catalog-model';
class EntitySecurityTierFilter implements EntityFilter {
constructor(readonly values: string[]) {}
filterEntity(entity: Entity): boolean {
const tier = entity.metadata.annotations?.['company.com/security-tier'];
return tier !== undefined && this.values.includes(tier);
}
}
But it's of type Entity which is pretty generic and won't have the spec information or it's limited. You could cast it as the Kind you expect it to be and then be able to check for your subdomainOf. I'll admit that also depends on how you set that up, is it an actual property you added or is that a relation? If it's a relation then you should be able to look at the relations array on the entity for this value instead.
As for the query string issue I believe this has come up before a few times and the resolution has been a missing part when following the docs. Let me see If I can find the related posts about this.
Hi @heavy orbit, thanks for the reply! Main issue was that .spec.subdomainOf may or may not exist on the entity and therefore I had issues implementing getCatalogFilters , but in the end we decided to just append some value to every entity and after that implementing the filter was trivial. If you would find information about my second question it would be great! I tried to look for it on both discord and github but I did not find anything useful, but maybe I was just looking in wrong spots. Thanks 
This is harder to find than I expected, there's been at least 3 cases like this where someone created a custom filter and it works fine by they say the query params didn't work. The follow up was always something they missed in the guide. BUT I think you are saying that they do show but there's some nuanced difference. I may not be tottaly understanding what you are describing? 🤔