Rename categories to consentCategories
Exclude the UNCATEGORISED category at the SQL level so the admin cookie/display/translations pages only see consent-relevant categories. Removes dead client-side UNCATEGORISED filters that are no longer needed. Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -31,8 +31,8 @@ export const cookieBannerCookiesPageQuery = graphql`
|
|||||||
__typename
|
__typename
|
||||||
... on CookieBanner {
|
... on CookieBanner {
|
||||||
id
|
id
|
||||||
categories(first: 50, orderBy: { field: RANK, direction: ASC })
|
consentCategories(first: 50, orderBy: { field: RANK, direction: ASC })
|
||||||
@connection(key: "CookieBannerCookiesPage_categories")
|
@connection(key: "CookieBannerCookiesPage_consentCategories")
|
||||||
@required(action: THROW) {
|
@required(action: THROW) {
|
||||||
__id
|
__id
|
||||||
edges {
|
edges {
|
||||||
@@ -86,8 +86,8 @@ export default function CookieBannerCookiesPage({
|
|||||||
}
|
}
|
||||||
|
|
||||||
const banner = data.node;
|
const banner = data.node;
|
||||||
const connectionId = banner.categories.__id;
|
const connectionId = banner.consentCategories.__id;
|
||||||
const categories = banner.categories.edges.map(e => e.node);
|
const categories = banner.consentCategories.edges.map(e => e.node);
|
||||||
const sorted = [...categories].sort((a, b) => a.rank - b.rank);
|
const sorted = [...categories].sort((a, b) => a.rank - b.rank);
|
||||||
|
|
||||||
const [deleteCategory]
|
const [deleteCategory]
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ export const categorySectionFragment = graphql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
cookieBanner @required(action: THROW) {
|
cookieBanner @required(action: THROW) {
|
||||||
categories(first: 50, orderBy: { field: RANK, direction: ASC }) @required(action: THROW) {
|
consentCategories(first: 50, orderBy: { field: RANK, direction: ASC }) @required(action: THROW) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
id
|
||||||
@@ -451,7 +451,7 @@ export function CategorySection({ categoryKey, onDelete }: CategorySectionProps)
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const allCategories = category.cookieBanner.categories.edges.map(e => e.node) ?? [];
|
const allCategories = category.cookieBanner.consentCategories.edges.map(e => e.node) ?? [];
|
||||||
const siblingCategories = allCategories.filter(c => c.id !== category.id);
|
const siblingCategories = allCategories.filter(c => c.id !== category.id);
|
||||||
|
|
||||||
const handleMoveCookie = (patternId: string, targetCategoryId: string) => {
|
const handleMoveCookie = (patternId: string, targetCategoryId: string) => {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ import type { CategoryListReorderMutation } from "#/__generated__/core/CategoryL
|
|||||||
const categoryListFragment = graphql`
|
const categoryListFragment = graphql`
|
||||||
fragment CategoryList_cookieBanner on CookieBanner {
|
fragment CategoryList_cookieBanner on CookieBanner {
|
||||||
id
|
id
|
||||||
categories(first: 50, orderBy: { field: RANK, direction: ASC })
|
consentCategories(first: 50, orderBy: { field: RANK, direction: ASC })
|
||||||
@connection(key: "CategoryList_categories")
|
@connection(key: "CategoryList_consentCategories")
|
||||||
@required(action: THROW) {
|
@required(action: THROW) {
|
||||||
__id
|
__id
|
||||||
edges {
|
edges {
|
||||||
@@ -87,8 +87,8 @@ export function CategoryList({ cookieBannerKey }: CategoryListProps) {
|
|||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
|
|
||||||
const banner = useFragment(categoryListFragment, cookieBannerKey);
|
const banner = useFragment(categoryListFragment, cookieBannerKey);
|
||||||
const connectionId = banner.categories.__id;
|
const connectionId = banner.consentCategories.__id;
|
||||||
const categories = banner.categories.edges.map(e => e.node);
|
const categories = banner.consentCategories.edges.map(e => e.node);
|
||||||
|
|
||||||
const [deleteCategory] = useMutation<CategoryListDeleteMutation>(deleteCategoryMutation);
|
const [deleteCategory] = useMutation<CategoryListDeleteMutation>(deleteCategoryMutation);
|
||||||
const [reorderCategory] = useMutation<CategoryListReorderMutation>(reorderCategoryMutation);
|
const [reorderCategory] = useMutation<CategoryListReorderMutation>(reorderCategoryMutation);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export const cookieBannerTranslationsPageQuery = graphql`
|
|||||||
language
|
language
|
||||||
translations
|
translations
|
||||||
}
|
}
|
||||||
categories(first: 50, orderBy: { field: RANK, direction: ASC }) @required(action: THROW) {
|
consentCategories(first: 50, orderBy: { field: RANK, direction: ASC }) @required(action: THROW) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
id
|
||||||
@@ -101,14 +101,14 @@ export default function CookieBannerTranslationsPage({
|
|||||||
|
|
||||||
const categories = useMemo(
|
const categories = useMemo(
|
||||||
() =>
|
() =>
|
||||||
banner.categories.edges.map(e => ({
|
banner.consentCategories.edges.map(e => ({
|
||||||
id: e.node.id,
|
id: e.node.id,
|
||||||
name: e.node.name,
|
name: e.node.name,
|
||||||
slug: e.node.slug,
|
slug: e.node.slug,
|
||||||
description: e.node.description,
|
description: e.node.description,
|
||||||
kind: e.node.kind,
|
kind: e.node.kind,
|
||||||
})),
|
})),
|
||||||
[banner.categories],
|
[banner.consentCategories],
|
||||||
);
|
);
|
||||||
|
|
||||||
const necessaryCategoryName = useMemo(
|
const necessaryCategoryName = useMemo(
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ export function PanelTranslationSection({
|
|||||||
const buttonSave = useWatch({ control, name: "button_save" });
|
const buttonSave = useWatch({ control, name: "button_save" });
|
||||||
const categoryTranslations = useWatch({ control, name: "categories" });
|
const categoryTranslations = useWatch({ control, name: "categories" });
|
||||||
|
|
||||||
const visibleCategories = categories.filter(c => c.kind !== "UNCATEGORISED");
|
|
||||||
|
|
||||||
const translatedNecessaryName = (() => {
|
const translatedNecessaryName = (() => {
|
||||||
const necessaryCat = categories.find(c => c.kind === "NECESSARY");
|
const necessaryCat = categories.find(c => c.kind === "NECESSARY");
|
||||||
if (!necessaryCat) return necessaryCategoryName;
|
if (!necessaryCat) return necessaryCategoryName;
|
||||||
@@ -157,13 +155,13 @@ export function PanelTranslationSection({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{visibleCategories.length > 0 && (
|
{categories.length > 0 && (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<h4 className="text-sm font-medium text-txt-secondary">
|
<h4 className="text-sm font-medium text-txt-secondary">
|
||||||
{__("Category names")}
|
{__("Category names")}
|
||||||
</h4>
|
</h4>
|
||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
{visibleCategories.map(cat => (
|
{categories.map(cat => (
|
||||||
<Card key={cat.id} className="border p-4 space-y-3">
|
<Card key={cat.id} className="border p-4 space-y-3">
|
||||||
<div className="text-sm text-txt-secondary">
|
<div className="text-sm text-txt-secondary">
|
||||||
{cat.name}
|
{cat.name}
|
||||||
|
|||||||
@@ -99,7 +99,6 @@ export function TranslationEditor({
|
|||||||
|
|
||||||
const catDefaults: CategoryTranslations = {};
|
const catDefaults: CategoryTranslations = {};
|
||||||
for (const cat of categories) {
|
for (const cat of categories) {
|
||||||
if (cat.kind === "UNCATEGORISED") continue;
|
|
||||||
const existing = existingCategoryTranslations?.[cat.id];
|
const existing = existingCategoryTranslations?.[cat.id];
|
||||||
catDefaults[cat.id] = {
|
catDefaults[cat.id] = {
|
||||||
name: existing?.name ?? "",
|
name: existing?.name ?? "",
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ func (s *Service) ensureDraftVersionForBanner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadConsentCategoriesByCookieBannerID(ctx, tx, scope, bannerID); err != nil {
|
if err := categories.LoadAllConsentCategoriesByCookieBannerID(ctx, tx, scope, bannerID); err != nil {
|
||||||
return nil, fmt.Errorf("cannot load cookie categories: %w", err)
|
return nil, fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1078,7 +1078,7 @@ func (s *Service) ListCookieCategoriesForBanner(
|
|||||||
err := s.pg.WithConn(
|
err := s.pg.WithConn(
|
||||||
ctx,
|
ctx,
|
||||||
func(ctx context.Context, conn pg.Querier) error {
|
func(ctx context.Context, conn pg.Querier) error {
|
||||||
if err := categories.LoadByCookieBannerID(ctx, conn, scope, bannerID, cursor); err != nil {
|
if err := categories.LoadConsentCategoriesByCookieBannerID(ctx, conn, scope, bannerID, cursor); err != nil {
|
||||||
return fmt.Errorf("cannot list cookie categories: %w", err)
|
return fmt.Errorf("cannot list cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1105,7 +1105,7 @@ func (s *Service) CountCookieCategoriesForBanner(
|
|||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
count, err = categories.CountByCookieBannerID(ctx, conn, scope, bannerID)
|
count, err = categories.CountConsentCategoriesByCookieBannerID(ctx, conn, scope, bannerID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot count cookie categories: %w", err)
|
return fmt.Errorf("cannot count cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
@@ -1943,7 +1943,7 @@ func (s *Service) GetActiveBannerConfig(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var categories coredata.CookieCategories
|
var categories coredata.CookieCategories
|
||||||
if err := categories.LoadConsentCategoriesByCookieBannerID(ctx, conn, scope, banner.ID); err != nil {
|
if err := categories.LoadAllConsentCategoriesByCookieBannerID(ctx, conn, scope, banner.ID); err != nil {
|
||||||
return fmt.Errorf("cannot load cookie categories: %w", err)
|
return fmt.Errorf("cannot load cookie categories: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -274,6 +274,95 @@ WHERE
|
|||||||
return count, nil
|
return count, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CookieCategories) LoadConsentCategoriesByCookieBannerID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Querier,
|
||||||
|
scope Scoper,
|
||||||
|
cookieBannerID gid.GID,
|
||||||
|
cursor *page.Cursor[CookieCategoryOrderField],
|
||||||
|
) error {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
organization_id,
|
||||||
|
cookie_banner_id,
|
||||||
|
name,
|
||||||
|
slug,
|
||||||
|
description,
|
||||||
|
kind,
|
||||||
|
rank,
|
||||||
|
gcm_consent_types,
|
||||||
|
posthog_consent,
|
||||||
|
created_at,
|
||||||
|
updated_at
|
||||||
|
FROM
|
||||||
|
cookie_categories
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND cookie_banner_id = @cookie_banner_id
|
||||||
|
AND kind != @excluded_kind
|
||||||
|
AND %s
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"cookie_banner_id": cookieBannerID,
|
||||||
|
"excluded_kind": CookieCategoryKindUncategorised,
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
maps.Copy(args, cursor.SQLArguments())
|
||||||
|
|
||||||
|
rows, err := conn.Query(ctx, q, args)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot query consent cookie categories: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
categories, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[CookieCategory])
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cannot collect consent cookie categories: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
*c = categories
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CookieCategories) CountConsentCategoriesByCookieBannerID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Querier,
|
||||||
|
scope Scoper,
|
||||||
|
cookieBannerID gid.GID,
|
||||||
|
) (int, error) {
|
||||||
|
q := `
|
||||||
|
SELECT
|
||||||
|
COUNT(id)
|
||||||
|
FROM
|
||||||
|
cookie_categories
|
||||||
|
WHERE
|
||||||
|
%s
|
||||||
|
AND cookie_banner_id = @cookie_banner_id
|
||||||
|
AND kind != @excluded_kind
|
||||||
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
|
args := pgx.StrictNamedArgs{
|
||||||
|
"cookie_banner_id": cookieBannerID,
|
||||||
|
"excluded_kind": CookieCategoryKindUncategorised,
|
||||||
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
|
row := conn.QueryRow(ctx, q, args)
|
||||||
|
|
||||||
|
var count int
|
||||||
|
if err := row.Scan(&count); err != nil {
|
||||||
|
return 0, fmt.Errorf("cannot scan count: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return count, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *CookieCategories) LoadAllByCookieBannerID(
|
func (c *CookieCategories) LoadAllByCookieBannerID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
@@ -323,9 +412,9 @@ ORDER BY
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadConsentCategoriesByCookieBannerID loads all categories except
|
// LoadAllConsentCategoriesByCookieBannerID loads all categories except
|
||||||
// UNCATEGORISED, which is an admin-side inbox never shown to visitors.
|
// UNCATEGORISED, which is an admin-side inbox never shown to visitors.
|
||||||
func (c *CookieCategories) LoadConsentCategoriesByCookieBannerID(
|
func (c *CookieCategories) LoadAllConsentCategoriesByCookieBannerID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
scope Scoper,
|
scope Scoper,
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ func (r *cookieBannerResolver) Organization(ctx context.Context, obj *types.Cook
|
|||||||
return types.NewOrganization(organization), nil
|
return types.NewOrganization(organization), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Categories is the resolver for the categories field.
|
// ConsentCategories is the resolver for the consentCategories field.
|
||||||
func (r *cookieBannerResolver) Categories(ctx context.Context, obj *types.CookieBanner, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.CookieCategoryOrderBy) (*types.CookieCategoryConnection, error) {
|
func (r *cookieBannerResolver) ConsentCategories(ctx context.Context, obj *types.CookieBanner, first *int, after *page.CursorKey, last *int, before *page.CursorKey, orderBy *types.CookieCategoryOrderBy) (*types.CookieCategoryConnection, error) {
|
||||||
if err := r.authorize(ctx, obj.ID, probo.ActionCookieCategoryList); err != nil {
|
if err := r.authorize(ctx, obj.ID, probo.ActionCookieCategoryList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ type CookieBanner implements Node {
|
|||||||
|
|
||||||
organization: Organization @goField(forceResolver: true)
|
organization: Organization @goField(forceResolver: true)
|
||||||
|
|
||||||
categories(
|
consentCategories(
|
||||||
first: Int
|
first: Int
|
||||||
after: CursorKey
|
after: CursorKey
|
||||||
last: Int
|
last: Int
|
||||||
|
|||||||
Reference in New Issue
Block a user