Repository navigation
feat(action-center): store Getting started per brand and work out its steps from the brand's data - #1234
Conversation
… 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]>
|
@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
left a comment
There was a problem hiding this comment.
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.
…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]>
|
@gkhngyk Done in
|
schema.sql is rebuilt with build-schema.sh after 00198 and 00199 landed. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
left a comment
There was a problem hiding this comment.
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.
Takes main after ansvisor#1234's squash; schema.sql is rebuilt with build-schema.sh. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
Takes main after the ansvisor#1234 and ansvisor#1235 squashes; only this PR's own changes are applied on top. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
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
… 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]>
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_startedkeeps one row per brand that runs it.dismissed_atmeans skipped.getting_started_stepsstores what a person did that leaves no other trace: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.tsholds the 17 step definitions andbuildGettingStarted(facts).saveKpiFrameworkmarks it.lib/actions/getting-started.tsadds three actions:getGettingStarted;markGettingStartedPageOpened, which accepts only the five explore pages;skipGettingStartedStep, for optional steps only.GettingStartedPageOpenedis 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.tsgains the new tables and functions.Interim done rules, until the Content Editor exists:
doneor was sent to the CMS webhook.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 featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Deploy: apply
00196first, then the web.00196. Existing brands get nogetting_startedrow; adding a brand creates one.select getting_started_facts('<brand id>'). It returns the counts. Another organization's brand returns null; anon has no execute.getting_started_stepsrow (opened) appears once.kpis/donerow appears.Verified on the dev DB in rolled-back transactions:
Unit tests:
steps.test.ts(19) andpage-opened.test.tsx(4).Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)yarn test(1799) passes on this commit alone.yarn buildpasses, andbash supabase/build-schema.shleavesschema.sqlunchanged.🤖 Generated with Claude Code