Skip to content

feat(action-center): store Getting started per brand and work out its steps from the brand's data - #1234

Merged
gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/getting-started-data
Oct 20, 2026
Merged

gkhngyk merged 4 commits into
ansvisor:mainfrom
cihan-gyk:feature/getting-started-data

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

New Ansvisor: Action Center + Getting started, PR 2 of 7 (AC-ALT2 spec, §4). It adds the data behind Getting started: the 17 fixed setup steps that the next PR lists in the Actions page. Nothing is shown yet.

Most steps are done when the brand's own data says so, so only what the data can't show is stored.

Migration 00196_getting_started.sql:

  • getting_started keeps one row per brand that runs it.
    • A trigger starts it for every new brand (onboarding, the brands page, the API).
    • Existing brands get no row. They will be able to start it from the Actions page (PR 7).
    • dismissed_at means skipped.
  • getting_started_steps stores what a person did that leaves no other trace:
    • an explore page opened;
    • an optional step skipped;
    • KPIs saved from the KPI screen.
    • RLS: organization members can read and write their brands' rows.
  • getting_started_facts(brand) reads every count and flag the steps need in one call. It is security invoker, so RLS decides the brand. On the dev DB it runs in ~10 ms.
  • getting_started_page_opened(brand, step) records an explore page only once the brand's first answers are in. A page opened while it had nothing to show doesn't count.

Web:

  • lib/getting-started/steps.ts holds the 17 step definitions and buildGettingStarted(facts).
    • States: New / Done / Waiting for data / Skipped, with progress (e.g. topics 2/3, prompts 6/9).
    • Steps unlock when their data is ready, not on a schedule:
      • Set up: now.
      • Explore: first answers.
      • The high-value prompts step: GSC/GA suggestions.
      • Act: first content suggestions.
      • Ready: after all the others.
  • KPI step:
    • The ready-made KPI set (00163) appears on a visit, so only a save from the KPI screen counts. saveKpiFramework marks it.
    • KPIs a brand had before it started count too, for existing customers.
  • lib/actions/getting-started.ts adds three actions:
    • getGettingStarted;
    • markGettingStartedPageOpened, which accepts only the five explore pages;
    • skipGettingStartedStep, for optional steps only.
  • GettingStartedPageOpened is mounted once in the dashboard layout. It records the explore pages however they're reached. Each brand and step is sent until the server records it, then remembered in localStorage.
  • types/supabase.ts gains the new tables and functions.

Interim done rules, until the Content Editor exists:

  • "Create your first content": an opportunity is done or was sent to the CMS webhook.
  • "Optimize a page": a user-run Site Audit completed.

Related issue

New Ansvisor (AC-ALT2). Follows #1233 (sidebar). The Actions page list is the next PR, stacked on this one.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Deploy: apply 00196 first, then the web.

  1. Apply 00196. Existing brands get no getting_started row; adding a brand creates one.
  2. As a member, call select getting_started_facts('<brand id>'). It returns the counts. Another organization's brand returns null; anon has no execute.
  3. Open Visibility, Prompts, Mentions, Citations or AI Traffic on a brand that has answers. A getting_started_steps row (opened) appears once.
  4. Save the KPIs from the KPI screen's framework drawer. A kpis / done row appears.

Verified on the dev DB in rolled-back transactions:

  • RLS blocks another org's brand.
  • The step key check rejects bad keys.
  • The trigger creates the row.
  • anon sees nothing.

Unit tests: steps.test.ts (19) and page-opened.test.tsx (4).

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from web/)
  • yarn typecheck passes (run from web/)
  • yarn format:check passes (run from web/)
  • Changes are focused — one concern per PR

yarn test (1799) passes on this commit alone. yarn build passes, and bash supabase/build-schema.sh leaves schema.sql unchanged.

🤖 Generated with Claude Code

… steps from the brand's data

New Ansvisor (AC-ALT2 spec, §4), PR 2 of 7: the data behind Getting
started, the 17 setup steps that will sit in the Actions page.

- Migration 00196: getting_started (one row per brand that runs it; a
  trigger starts it for every new brand, existing brands have none) and
  getting_started_steps (what a person did that the data can't show: a
  page opened, an optional step skipped, KPIs saved), member RLS.
- getting_started_facts reads everything the steps need in one call;
  getting_started_page_opened records an explore page once the brand's
  first answers are in.
- lib/getting-started/steps.ts turns the facts into the 17 steps (New,
  Done, Waiting for data, Skipped, with progress); unlocks follow the
  data, not days.
- Saving from the KPI screen marks the KPI step (the ready-made set
  appears on a visit, so it doesn't count).
- The dashboard layout records the explore pages however they're opened.

Nothing is shown yet; the Actions page list follows in the next PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 20, 2026
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk New Ansvisor PR 2/7: the Getting started data (migration 00196, applied on the dev DB). New brands start Getting started through a trigger on brands; existing brands have no row until they start it from the Actions page (PR 7). Most steps are worked out from the brand's own data in one RPC (getting_started_facts, ~10 ms on the dev DB); only opened pages, skipped optional steps and a KPI save are stored. Two interim rules until the Content Editor: "Create your first content" = an opportunity done or sent to the CMS webhook, "Optimize a page" = a user-run audit completed. #1235 (the Actions page list) is stacked on this one.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RLS and the facts read look right. A member of another org gets null and writes nothing, the trigger function is service-only, and the facts read is per-brand exists and count checks on indexed columns.

One change:

Every role can write step rows (00196, the getting_started_steps insert and update policies). They allow any member, analyst and agency_partner included. With the card's Skip button (#1236) and skipGettingStartedStep, an analyst can skip the Search Console and Analytics steps. Through PostgREST directly, they can insert done or skipped for any step. Everywhere else, admins and managers write, and #1243 says "only admins and managers".

Keep opened for everyone, and require admin or manager for skipped and done. For example, add to both policies' checks:

and (state = 'opened' or exists (
  select 1 from public.profiles p
  where p.id = auth.uid() and p.role in ('admin', 'manager')
))

Then hide Skip in the card when !canManage.

Nit: updated_by defaults to auth.uid(), but the upserts never set it, so it keeps whoever wrote the row first. Set it in the upserts or drop the column.

cihan-gyk and others added 2 commits October 20, 2026 10:26
…rted-data

# Conflicts:
#	supabase/schema.sql
…ting started step

gkhngyk's review: the step policies let any member write any state, so
an analyst could skip Search Console and Analytics, or mark a step done
through PostgREST. Recording an opened page stays open to every member;
skipped and done now need an admin or a manager, as the other Getting
started and KPI writes do (insert check, and the update's with check).

updated_by is dropped: nothing set it after the first write, so it only
ever named whoever opened the page first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Done in 6330d1a4:

  • Step policies (00196): opened stays open to every member. skipped and done need an admin or a manager, on insert and in the update's with check. On the dev DB, as an analyst: opened inserts, skipped and an update to done are refused. As a manager, skipped inserts.
  • updated_by: dropped, since nothing set it after the first write. Types and schema.sql are updated.
  • The card hides Skip for !canManage; that part is in feat(action-center): open a card on the right for each Getting started step #1236.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, both points are fixed. skipped and done now need an admin or a manager, in the insert check and in the update's with check, and updated_by is gone. The facts read takes 128 ms as a member on our largest brand. I'll apply 00196 on prod before the merge.

Nit, optional: the update policy's using still lets any member turn a skipped or done row back into opened through PostgREST. Nothing in the app updates a row to opened, because the page RPC inserts with do nothing. So the update policy could be admin and manager only.

@gkhngyk
gkhngyk merged commit 0685898 into ansvisor:main Oct 20, 2026
5 checks passed
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 20, 2026
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 20, 2026
gkhngyk added a commit to cihan-gyk/ansvisor that referenced this pull request Oct 20, 2026
Takes main after the ansvisor#1234, ansvisor#1235 and ansvisor#1236 squashes; only this PR's own
changes are applied on top, and schema.sql is rebuilt with build-schema.sh.

Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk pushed a commit that referenced this pull request Oct 20, 2026
… back to opened (#1255)

00196's update policy on getting_started_steps checked the new row
(only an admin or a manager may write skipped or done) but not the row
being changed, so through PostgREST any member could turn a skipped or
done step back into opened. The app never does: the page RPC inserts
with on conflict do nothing, and skipping a step or saving the KPIs is
an admin's or a manager's. 00202 adds the same check to the policy's
using: the row must be opened, or the user an admin or a manager.

Follow-up to gkhngyk's note on #1234.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-migration Adds or edits a migration — apply it to the hosted database

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants