Skip to content

feat(content): filter the Library by each page's last send to the CMS - #1567

Merged
gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/library-send-filter
Oct 27, 2026
Merged

gkhngyk merged 1 commit into
ansvisor:mainfrom
cihan-gyk:feature/library-send-filter

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

The Library filter on the last send, left for later in phase 1 of Send to CMS (#1331, scope note of 2026-10-24). A Last send select beside Created lists the pages by how their last send to the CMS went: Never sent, Sending, Sent, Failed or Published (or Any).

  • It reads each row's last send, as the row's mark does (content_draft_last_deliveries, 00262; a send left queued past its half hour reads as failed).
  • The choice is kept in the URL (?sent=failed), as Created is, and Export exports the rows it lists.
  • It shows once a page of the brand has been sent, or while the URL names a filter. A brand that never sent anything doesn't get an extra select.
  • The list is filtered only once the sends of the drafts listed are read, so it never shows every draft for a moment, nor lets Export or the bulk bar act on the unfiltered list. A list read again in another order (a status change, the agent writing) doesn't wait again.
  • The empty state names the filter that left nothing: Created when the date range already empties the tab, else "No page in this tab matches the Last send filter."
  • The cap's note ("Showing the N changed most recently of M") is left out while the filter narrows the list, as it is for Created.

draftsLastSent and SEND_FILTERS are in lib/content/drafts.ts, next to draftsCreatedIn. Strings are in en.json (contentEditor.library.lastSend). Docs: Send to CMS and the Content Editor guide.

Related issue

Part of #1331 (phase 1 follow-up: "a Library filter on the last send").

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

  1. cd web && yarn vitest run src/lib/content/drafts.test.ts 'src/app/[locale]/(dashboard)/dashboard/content/library/page.test.tsx'
  2. Open Content › Library for a brand that has sent a page to its CMS. Last send shows beside Created. Pick Failed: only pages whose last send failed are listed, the URL reads ?sent=failed, and Export exports those.
  3. For a brand that never sent a page, the select isn't shown. Open /dashboard/content/library?sent=never: it shows, and lists every page.

Checked in the browser at 1024 px, light and dark: the two selects sit under the tabs on the right, and the empty state reads as above.

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

Also run: yarn format, yarn lint (0 errors), yarn typecheck, yarn test (4,087 tests) and yarn build in web/. After the pre-push review's fixes: the Library page and drafts tests (50 + the drafts file), lint, typecheck, format check and yarn build again. Each fix's test fails without it.

🤖 Generated with Claude Code

@mintlify

mintlify Bot commented Oct 27, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit f93dff5.

Approve preview

@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.

Looks good, with follow-ups.

What I checked:

  • Where it filters. In the browser, over the list the Library already holds. There's no paging to get wrong:
    • getContentDrafts returns the brand's latest 500 drafts by updated_at (LIBRARY_LIMIT), and the table renders all of them.
    • readCmsStatuses already reads their last sends for the row marks. That's one content_draft_last_deliveries call, since it takes 500 ids and the list is capped at 500. It uses content_draft_deliveries_draft_created.
    • The PR adds no request. draftsLastSent, sendsRead and anySent are one pass each over at most 500 rows.
    • The tab counts aren't narrowed, as with Created. Export (page.tsx:367) and the bulk bar (:338) both take listed, so they act on the filtered rows.
    • The cap is covered in follow-up 2.
  • The states match the mark. The filter reads the same cms map and the same status as CmsStatusMark:
    • Never sent: no delivery, so no mark.
    • Sending: queued, under 30 minutes.
    • Sent, Failed and Published: the mark's own status. A send queued for more than 30 minutes reads as failed, through lastSend in cms-send-client.ts, as the mark does.
    • Targets. The filter ignores the target. A Webflow draft item is Sent, and its mark says so. Once Webflow reports it live, it's Published. WordPress and Framer (#1572, #1580) fit the same states.
    • "Published". Here it's the delivery's status, meaning the CMS reported the page live. That also sets the draft to Published when it's the latest send (content-published.js:37-47). A page marked published by hand (CE-013, markDraftPublished) keeps its delivery as it was. So it's under the Published tab but listed here as Sent or Never sent, beside a Published badge. That matches the mark. See follow-up 4 for the docs.
  • The wait.
    • While the sends of the listed drafts are unread, the list shows the loading dots, Export is disabled and nothing can be picked. That's sendsRead, and the read drafts are compared as a set.
    • A read that only changes the order doesn't wait again.
    • On a brand switch, the old brand's ids don't count, and anySent only looks at this brand's drafts.
  • URL. readUrlChoice('sent', SEND_FILTERS, 'all'): an unknown value reads as Any, with no crash. Choosing Any removes the param.
  • When it shows. The select shows once one of the listed drafts has a send, or while the URL names a filter. On a brand with no sends, choosing Any from a URL-opened filter hides the select again. That's as the PR describes.
  • Empty state. When the date range already leaves nothing, it blames Created. Otherwise it shows the Last send message. The cap's note is hidden while the filter is on.
  • The deploy gap. None. Web only, with no API call. content_draft_last_deliveries is from 00262, is on prod, and the marks read it already.
  • Speed. No regex. No loop beyond one pass over the list.
  • Tests. I ran both files from an export of the head, outside the repo.
    • On the head: 60 pass. The long-list Export test times out at the default 5 s on this machine, on the base too. The test after it then fails because of that timeout, and passes when run alone. With a 60 s timeout, all 60 pass.
    • With page.tsx back at the base: 8 of the 11 new page tests fail. Three pass anyway: the order re-read, no select without sends, and the Created empty state. They guard parts of the change that the base can't break.
    • drafts.test.ts fails without draftsLastSent.
  • Merge.
    • One commit on 3b650fb. Main's 55b49e7 doesn't touch the Library. git merge-tree is clean (968c0c2b), with the same change as the PR's own diff, and the 60 tests pass on that tree.
    • It merges cleanly with each open PR on the same files: #1507, #1572, #1573, #1578, #1580 and #1581. On #1567 + #1580, the two test files pass (66 tests).

Follow-ups:

  1. A failed read of the sends reads as "Never sent" (cms-send-client.ts:204-207, page.tsx:171-181).
    • supabase.rpc returns a network or server error rather than throwing, and readCmsStatuses logs it and goes on. The page then counts the drafts as read, with no sends.
    • Under Never sent, every draft is listed, and Select all and Send to CMS would send again pages that were already sent. Sent and Failed show "No page in this tab matches". The .catch branch hits the same issue on a first read, since cms is still empty.
    • Fix: have readCmsStatuses throw when a read fails. There's one chunk at the cap. On a failure with a Last send filter on, leave the ids unread and show the load error with Retry. The marks can show nothing, as they do now.
    • Add a test: ?sent=never with a failed read lists no row and offers Retry.
  2. Past the cap, the filter covers only the latest 500, and nothing says so (page.tsx:576).
    • A send writes the draft's slug and meta, which bumps updated_at, so recent sends sit near the top. But an older send, or an old page never sent, isn't listed past the cap. The cap's note is hidden while a filter is on. Created has the same gap.
    • Fix: while at the cap (inTab.length < counts[tab]), keep a note even with a filter on, e.g. "Filters cover the 500 changed most recently of 1,240."
  3. Read the sends again when a CMS reports pages live (page.tsx:207-209).
    • After refreshWebflowPublished marks pages, the list is read again. The sends are read again only if the list's order changed. A page that was already first, or the only one, keeps its Sent mark, stays under Sent and stays out of Published until a reload.
    • This was already true of the mark. The filter now depends on it.
    • Fix: if (published.length) { setAttempt((n) => n + 1); setCmsAttempt((n) => n + 1); }. #1572 and #1580 add the same call for WordPress and Framer.
  4. Docs.
    • content-editor.mdx is reformatted beyond the two lines: padded tables, re-wrapped Note and Tip, blank lines in the Steps, about 36 lines in all. .prettierignore keeps the docs MDX hand-formatted. Drop the unrelated changes.
    • In send-to-cms.mdx:60, say what Published means here: "Published lists the pages your CMS reported live; a page you mark published yourself keeps its last send."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants