Populate subprocessor filters from server facets

The subprocessors toolbar derived its category and region filter
options client-side from a second, unfiltered subprocessors(first: 250)
fetch, shipping up to 250 rows purely to compute two small facet sets
and silently capping the options at that limit.

Expose subprocessorCategories and subprocessorCountries on TrustCenter,
each backed by a DISTINCT query over the organization's third parties
scoped to show_on_trust_center, and read them directly in the toolbar.
The page now issues one filtered list query plus two tiny arrays, and
the options only ever include values that can actually return results.

Signed-off-by: Émile Ré <emile@probo.com>
This commit is contained in:
Émile Ré
2026-07-08 10:24:06 -04:00
parent 1e946d065c
commit 52b6ccac55
7 changed files with 181 additions and 27 deletions

View File

@@ -780,6 +780,78 @@ WHERE
return count, nil
}
func (v *ThirdParties) LoadDistinctTrustCenterCategoriesByOrganizationID(
ctx context.Context,
conn pg.Querier,
scope Scoper,
organizationID gid.GID,
) ([]ThirdPartyCategory, error) {
q := `
SELECT DISTINCT
category
FROM
third_parties
WHERE
%s
AND organization_id = @organization_id
AND show_on_trust_center = true
ORDER BY
category ASC
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return nil, fmt.Errorf("cannot query thirdParty categories: %w", err)
}
categories, err := pgx.CollectRows(rows, pgx.RowTo[ThirdPartyCategory])
if err != nil {
return nil, fmt.Errorf("cannot collect thirdParty categories: %w", err)
}
return categories, nil
}
func (v *ThirdParties) LoadDistinctTrustCenterCountriesByOrganizationID(
ctx context.Context,
conn pg.Querier,
scope Scoper,
organizationID gid.GID,
) ([]CountryCode, error) {
q := `
SELECT DISTINCT
unnest(countries) AS country
FROM
third_parties
WHERE
%s
AND organization_id = @organization_id
AND show_on_trust_center = true
ORDER BY
country ASC
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.NamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
rows, err := conn.Query(ctx, q, args)
if err != nil {
return nil, fmt.Errorf("cannot query thirdParty countries: %w", err)
}
countries, err := pgx.CollectRows(rows, pgx.RowTo[CountryCode])
if err != nil {
return nil, fmt.Errorf("cannot collect thirdParty countries: %w", err)
}
return countries, nil
}
func (v *ThirdParties) LoadByOrganizationID(
ctx context.Context,
conn pg.Querier,