Repository navigation
feat(action-center): open a brand without KPIs on a ready-made set - #1129
Merged
Merged
Conversation
The Action Center can track Positive Sentiment: the positive share of the AI responses naming the brand, the same figure as Insights' Positive sentiment card, with its change in points and a daily trend that leaves out days without a mention. It comes last in the KPI list, the Brand Monitoring template becomes Mentions + Positive Sentiment, and Mentions actions link to it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A brand that never had a KPI no longer opens on an empty KPI tab. For an admin or manager it gets AI Visibility, Mentions, Citations, Share of Voice and Positive Sentiment (and AI Referral Traffic when Google Analytics is mapped), each aiming 20% above its last 30 days, with a note saying so; other members see the same set unsaved. Migration 00163 adds brands.kpi_setup_at, set by a trigger when a brand first has a KPI, so a brand whose KPIs were all removed isn't offered them again, and seed_kpi_presets, which adds the set once. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Collaborator
Author
|
@gkhngyk the follow-up to #1128: a brand that never had a KPI opens on a ready-made set (Visibility, Mentions, Citations, Share of Voice, Positive Sentiment, plus traffic with GA), each 20% above its last 30 days, saved once for an admin/manager and previewed for others. On deploy please apply 00163 (brands.kpi_setup_at + seed_kpi_presets). Stacked on #1128. |
supabase/schema.sql regenerated with build-schema.sh. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
previously approved these changes
Oct 17, 2026
gkhngyk
left a comment
Contributor
There was a problem hiding this comment.
Rebuilt on main with schema.sql regenerated: the KPI page, kpis and presets tests, typecheck, lint and format pass, and CI is green.
00163 is applied on production. Seven brands had KPIs and got kpi_setup_at from their first one. Checked as authenticated in rolled-back transactions:
- An admin on a brand that was never set up: the first call adds the valid entries (a zero target is skipped) and the trigger sets
kpi_setup_at. A second call returns false. - An admin on a brand already set up: false.
- A user from another organization: 42501.
supabase/schema.sql regenerated with build-schema.sh. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
9 of 12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A brand without KPIs opens on a ready-made set instead of an empty KPI tab. For an admin or manager, the first visit saves the set, and a note says so:
A member who can't set KPIs sees the same set unsaved. A brand whose KPIs were all removed keeps its empty state: the set is offered once per brand.
Migration
00163_kpi_presets.sqlbrands.kpi_setup_at: when the brand first had a KPI, from the ready-made set or set by hand.kpi_definitionssets it on the first insert.seed_kpi_presets(brand, kpis jsonb): security definer.kpi_definitions' write policies do, and raises42501otherwise.falsewhen the brand was already set up.Web
lib/kpis/presets.ts:presetTarget: the last 30 days × 1.2.lib/actions/kpis.ts:getKpiSnapshots: says whether a brand without KPIs was ever set up (everSetUp). Without the column (a database before 00163) nothing is offered.seedKpiPresets: computes the targets from the same reads the KPI table uses, then calls the function.getKpiPresetPreview: returns the set as unsaved rows.KpiTable: withoutonEdit/onRemove, the rows have no menu.Deploy
Apply 00163. It is independent of the open Mentions migrations (00160–00162) and of 00159.
Related issue
None.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
delete from kpi_definitions where brand_id = …; update brands set kpi_setup_at = null where id = ….Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/): no errors; the 7 warnings are in files this PR does not touchyarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also run:
web:yarn test(1268) andyarn buildpass.lib/kpis/presets.test.ts: the set with and without GA; +20%; the percent cap and floor; defaults; every target valid.lib/actions/kpis.test.ts:everSetUp, also without the column;PGRST202and a refusal;page.test.tsx:bash supabase/build-schema.sh: regeneratedschema.sql.🤖 Generated with Claude Code