Skip to content

feat(content): export an opportunity as CSV, Excel or Word - #1337

Merged
gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:feature/opportunity-export
Oct 22, 2026
Merged

gkhngyk merged 18 commits into
ansvisor:mainfrom
cihan-gyk:feature/opportunity-export

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

From the user: an Export button on the opportunity's full page ("Open in new tab") and in the right-hand panel. Clicking it lists Export CSV, Export Excel and Export Word, one under the other. It sits on the actions row, left of the "…" menu (#1334).

One write-up, four outputs

  • Shared write-up: opportunityToMarkdown (Copy All Data) now renders a structured write-up, opportunityDocument: sections of fields, items, numbered steps and text. Its Markdown output is unchanged; I compared old and new on every test fixture before removing the comparison.
  • The three file formats: lib/content/opportunity-export.ts writes the same write-up as:
    • CSV: section, field, value rows. The opening facts go under "Overview", and there's a byte order mark so Excel reads UTF-8.
    • Excel: one sheet with a bold header, using write-excel-file (already a dependency).
    • Word: a real .docx with the title, section headings, bold field labels, bullet lists and numbered outline steps with their key points.
  • File names: ansvisor_opportunity_<title-slug>.<csv|xlsx|docx>.

New dependency: docx (MIT), added with the user's OK.

  • Version: pinned to 9.9.0, a release at least two weeks old; the latest, 9.13.0, was three days old.
  • Loading: it loads only on Export Word's click, so it doesn't add to the page bundle.
  • Lockfile: yarn.lock only gains docx and its dependencies (jszip, nanoid, hash.js, xml-js…). yarn check --integrity passes.

Stacked on #1334, whose actions row this adds to (and on #1332/#1321 below it). This PR's own commit is 76b4b1b8.

Related issue

None. Product feedback from the user. The same Word decision covers the queued Library export (CSV/Excel/Word).

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. Content → Opportunities → open one. Click Export ⌄ next to "…".
  2. Export CSV / Excel / Word each download a file named after the opportunity:
    • the CSV opens in Excel with section, field and value columns;
    • the .xlsx has one sheet with a bold header;
    • the .docx opens in Word, Google Docs and Pages, with headings and lists.
  3. Open the opportunity's full page (Open in new tab). The same Export button is there.

In the browser I checked that the CSV starts with the UTF-8 byte order mark and that the .xlsx and .docx are valid zip packages. A test opens the .docx and finds the content. Checked in light and dark, at 1024 px and wider.

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: 287 files, 2,530 tests pass. yarn build passes with CI's placeholders.

🤖 Generated with Claude Code

cihan-gyk and others added 9 commits October 21, 2026 21:39
…e in its final layout

- "What AI cites in your topics" drew both shares on one track scaled to
  AI's largest share, so a type the brand leans on more than AI does
  (e.g. 35% · 73%) ran its bar past the track onto the shares column. The
  two shares are now two thin bars on one scale, the larger of the two,
  never past the track.
- The list and the sections above it (AI results, the mix) were read and
  drawn apart, so the list showed mid-screen first and jumped down when
  the sections came in. The page now shows one spinner until both reads
  are in; a list that fails says so at once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rlap warning

More of the brand's pages cited for the same prompts is no loss (AI
answers aren't a ranking), so neither Start nor the Plan treats it as a
problem any more:

- Start's "Overlap check" is an "Overview": a plain box listing the
  brand's pages AI already cites for these prompts, with no amber warning,
  no "Safe to create" and no "Recommended". The action the person clicked
  stays chosen (Create stays Create); the choices are the plan's page when
  it named one, a new page, and optimizing the page cited most.
- The Plan drops the Overlaps card, the ⚠ Overlap tag on rows, and the
  rows that were listed only because another page of the brand is cited
  for the same prompts.

content_plan_pages (00220/00221) still returns overlaps; the Plan no
longer reads it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each Priority list row gets a "…" menu:
- Assign to… (every member): a row with a draft assigns its Action
  Center task (sending the draft first when needed); a row without one
  opens Start on Team, which now has an "Assign to" picker. The Who
  column shows the assignee.
- Mark as priority (admins and managers): the row goes to the top with a
  Priority tag; a Priority card counts and filters the marked rows.
- Hide from the plan (admins and managers): the row leaves the list, with
  Undo and "N hidden rows · Show"; an opportunity's row also dismisses the
  opportunity and gets its status back when shown again.

Migration 00229 adds content_plan_marks (members read; admins and
managers write).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…type

Content Opportunities gave every brand the same ten asset types, so a
shop could get a glossary or landing page and a SaaS brand a product or
category page. The generator now reads brands.site_type (or the
editor's guess from Shopping mode and industry), lists that site's page
types with their formats in the prompt, and limits assetType and the
supporting types to them, plus the earned third_party_article and
backlink. No calculation changes.

Older opportunities keep their stored types and are read as the brand's
page types (pillar_guide -> guide / buying_guide, landing_page ->
solution_page / collection_page / destination_page, and so on). The
opportunities list, the drawer, the assets card and Copy All Data name
them with the editor's labels. Start preselects an opportunity's type
for a new page; an existing page goes by its own address or title
first. The Content Plan follows the same rules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	web/src/components/content/new-content-dialog.tsx
#	web/src/lib/actions/content-plan.ts
From the user's spec, PR B of the Content Editor entry points, with the
user's follow-up choices:

- Opportunity panel: three buttons in front, in this order: Send to
  Actions, Generate Brief and Send to Editor. Each turns into its done
  state in place (Open in Actions, Brief Generated, Open draft). The
  rest move into a "..." menu on the right: Send to Plan, Another angle,
  Send to Workflow, Copy All Data, Mark as reviewed, Restore, Dismiss.
- Opportunities list: a row's actions sit in one "..." menu: Send to
  Editor or Open draft, Send to Plan or Open in Plan, Send to Workflow,
  Open in new tab, Dismiss. The Actions column narrows to fit.
- Send to Editor opens New content > Start. A create decision starts a
  new page; any other decision starts on its first target page
  (lib/content/opportunity-start.ts). Owned work still open only.
  getOpportunityDrafts finds the draft already being written.
- Send to Plan marks the opportunity's Plan row as a priority
  (content_plan_marks, ansvisor#1321) for admins and managers;
  getPlanPriorities reads which rows already are.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The user asked for an Export button on the opportunity's full page and in
the right-hand panel, listing Export CSV, Export Excel and Export Word one
under the other. It sits on the actions row, left of the "..." menu.

All three formats come from what Copy All Data copies.
opportunityToMarkdown now renders a structured write-up
(opportunityDocument: sections of fields, items, numbered steps and
text), and its Markdown output is unchanged. lib/content/opportunity-export.ts
writes that same write-up as:
- CSV: section, field and value rows, with a byte order mark;
- Excel: one sheet with a bold header (write-excel-file);
- Word: a .docx with the title, section headings, bold field labels
  and lists.

Word uses the docx package, added at the user's OK. It is pinned to 9.9.0,
a release at least two weeks old, and loaded only on the click.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk This one adds an Export button (CSV / Excel / Word) on the opportunity panel and full page, as the user asked. It brings in one new dependency, docx (MIT), which the user approved: it's pinned to 9.9.0, at least two weeks old, and loaded only on the Word click. CSV, Excel and Word are all generated from the same write-up as Copy All Data, whose Markdown output is unchanged. It's stacked on #1334. Tests (2,530) and the build pass.

@github-actions github-actions Bot added the needs-migration Adds or edits a migration — apply it to the hosted database label Oct 22, 2026

@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. I reviewed this PR's own commit (76b4b1b8); the rest of the diff is #1334 and the PRs below it, so this merges after #1334.

What I checked:

  • Dependency. [email protected] is MIT, pinned exactly like the repo's other pinned packages, and 15 days old. The project is active (9.13.0 is the latest). GitHub's advisory database lists nothing for docx, xml, xml-js or hash.js. [email protected] is outside every nanoid advisory range, and [email protected] is already in the lockfile, past both of its advisories. The lockfile adds only docx's own dependency tree. One quirk: docx lists @types/node@^26 as a runtime dependency, so a second @types/node is installed. It's harmless here because skipLibCheck is on.
  • Bundle. The ESM build is a self-contained bundle of about 1.3 MB before minification. It's loaded with await import('docx') only on Export Word and runs in the browser, so it doesn't add to the page's bundle.
  • Formula injection. The CSV goes through toCsv, which prefixes cells starting with = + - @, tab or CR with an apostrophe. The .xlsx writes values as string cells, which Excel never evaluates. docx escapes its text runs.
  • File name. slugify keeps only [a-z0-9-], the slug is capped at 60 characters, and an empty slug falls back to export.
  • Auth. There is no new server action or route. Export writes the data the panel already read under the member's session, the same data Copy All Data copies.
  • The Markdown refactor keeps the output the same. The one difference is that an empty brief field (Suggested title, Content type) is now left out instead of printed with no value, which is better.

Optional:

  1. web/src/lib/content/opportunity-export.ts:70: outline steps put their key points on new lines (:33), but the cells don't wrap, so Excel shows them on one line. Use { value: row.value, wrap: true } for multi-line values.
  2. opportunity-export.ts:15: the CSV header is section,field,value, but the sheet's header is Section / Field / Value. Use the same case in both.

cihan-gyk and others added 6 commits October 22, 2026 12:02
# Conflicts:
#	supabase/schema.sql
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-insights.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.tsx
#	web/src/components/content/new-content-dialog.test.tsx
#	web/src/lib/content/plan.test.ts
#	web/src/lib/content/plan.ts
… only what is still dismissed

hidePlanRow and showPlanRow no longer take an opportunity id from the client:
the server reads it from the row key the mark is written under (a uuid, or
'invalid'). Show again gives an opportunity back its status only while it
is still dismissed; one completed or reopened elsewhere keeps its status and
only the mark goes. Hidden rows read only dismissed opportunities. The
Priority card's dot is in ink, as its outline badge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and tell the list about Send to Plan

- A failed getOpportunityDrafts is no "no draft": the row menu and the
  panel offer "Couldn't check for a draft · Retry" instead of Start, so a
  failed read never starts a second draft for the same opportunity.
- Send to Plan from the panel calls the page's onPrioritized, so the row's
  menu says Open in Plan without a reload.
- Start's page types come from the opportunity's brand, not the active one.
- content.send is gone; content.alternative.hint is Another angle's title.
- Drop the unused contains mock and fix the content prop's doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ansvisor#1334's retry test lists the panel's front buttons; with this PR's Export
button there is one more.

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

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

Two fixes before merge. The new commits are the merge of #1334 (a0ad3445) and a test update (2475509e) that adds Export to the panel's buttons. Re-merging a0ad3445's parents gives the same tree, so it has no hidden changes.

  1. CI's web job fails at yarn install. [email protected] depends on nanoid@^6, and [email protected] requires Node ^22 || ^24 || >=26. The web job runs Node 20 (.github/workflows/ci.yml:34), and yarn 1 stops on the engine check: error [email protected]: The engine "node" is incompatible with this module. Format, lint and typecheck never run. Vercel's install would stop the same way if the project builds on Node 20. The smallest fix is to pin docx to 9.7.0 at web/package.json:44. That's the last minor on nanoid@^5.1.3 (Node ^18 || >=20) and @types/node@^25, and Document, Paragraph, TextRun, HeadingLevel and Packer are all in it. The alternative is to move CI and Vercel to Node 22+, but that's a separate change.
  2. web/yarn.lock conflicts with main. #1210 added undici@^6.28.0, and this PR adds undici-types@~8.9.0 beside it. Merge main and keep both entries, or regenerate the lockfile after the docx pin from item 1. That pin changes this PR's lock entries anyway.

Still optional from the last review (unchanged):

  • web/src/lib/content/opportunity-export.ts:70: wrap multi-line cells.
  • opportunity-export.ts:15: use the same header case in the CSV and the sheet.

Merge notes

  • Apart from yarn.lock, it merges cleanly on main.
  • It contains #1334 at its current head (92a4aaac), so it also carries #1321 (00229) and #1332's original commit. It merges last in that stack.
  • It conflicts with #1328 in the same two test files as #1334 (keep both mocks).

cihan-gyk and others added 3 commits October 22, 2026 15:03
…-export

# Conflicts:
#	web/messages/en.json
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
#	web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.tsx
#	web/src/components/content/opportunity-actions.test.tsx
#	web/src/components/content/opportunity-actions.tsx
#	web/src/components/content/opportunity-detail.tsx
#	web/src/lib/actions/content-drafts-start.test.ts
#	web/src/lib/content/drafts.ts
#	web/src/lib/content/opportunity-markdown.ts
#	web/src/lib/content/plan.test.ts
#	web/yarn.lock
[email protected] depends on nanoid@^6, whose engines need Node 22+, so CI's
Node 20 web job (and Vercel's install on Node 20) stopped at yarn install.
9.7.0 is the last release on nanoid@^5 (Node ^18 || >=20) and @types/node
^25, and has every API the export uses. The lockfile drops docx 9.9.0's
nanoid 6, @types/node 26 and undici-types 8.9; @types/node@^25.2.3 joins
the existing 25.7.0 entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r case in the CSV

An outline step's points sit on their own lines in one value; the sheet's
cell now wraps, so Excel shows them. The CSV's header reads Section,Field,Value
like the sheet's.

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

Copy link
Copy Markdown
Collaborator Author

@gkhngyk Thanks, both fixes and both optional items are in:

  1. docx pinned to 9.7.0 (77196a50). It's on nanoid@^5 (Node ^18 || >=20) and @types/node@^25. The lockfile changes:

    • [email protected] and [email protected] are added; their resolved #sha1 match the tarballs' shasums;
    • "@types/node@^25.2.3" joins the existing 25.7.0 entry;
    • docx 9.9.0's nanoid@^6, @types/node@^26 and undici-types@~8.9.0 are dropped.

    Web tests (2,608), tsc, lint, Prettier and the build pass with docx 9.7.0, export tests included. I edited the lockfile instead of reinstalling, because this Mac is short on disk, so CI's yarn install --frozen-lockfile on Node 20 is the real check. I'll watch it.

  2. Merged main (59ad3f64), now that feat(content): open the Content Editor from Content Opportunities #1334 is in. feat(content): open the Content Editor from Content Opportunities #1334's squash made the default merge base re-apply its original commits, so I resolved with feat(content): open the Content Editor from Content Opportunities #1334's head (92a4aaac) as the base. This PR's own files equal that three-way merge, and every other file, schema.sql included, matches main. yarn.lock kept both sides (feat(settings): add OpenAI, Gemini, Azure OpenAI and OpenRouter keys for Chat #1210's undici).

Optional, done (baf7e42e):

  • multi-line values (an outline step and its points) wrap in the sheet, { value, wrap: true };
  • the CSV header is Section,Field,Value, as in the sheet.

Tests cover both.

@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. Both items from the last review are done:

  1. Node 20. 77196a50 pins docx to 9.7.0. Compared with main, the lockfile adds [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] and [email protected]. It reuses the @types/[email protected], [email protected] and inherits entries that main already has. Their engines fields:

    • docx: >=10
    • nanoid: ^18 || >=20
    • sax: >=11
    • the rest declare none.

    No nanoid@^6 or undici-types@~8 entry is left, and every integrity hash matches the registry. The web job at baf7e42e passes yarn install --frozen-lockfile on Node 20, and then the tests and next build.

  2. yarn.lock conflict. It's gone: the PR now merges main through 59ad3f64 and merges cleanly.

The two optional notes are done in baf7e42e:

  • multi-line cells wrap in the sheet;
  • the CSV uses the sheet's Section,Field,Value header.

The diff from main to the head only touches the export's nine files. So the merges of #1334 and main carry nothing hidden.

Merge notes

  • It merges cleanly on current main. The stack under it (#1321, #1332, #1334) is on main, so it contains no other open PR.
  • #1348 adds the same [email protected] pin and the same lock entries, and the two merge cleanly with each other.

Tested on top of main together with #1339–#1341, #1352 and #1337: web and server tests, tsc, lint and Prettier pass.

@gkhngyk
gkhngyk merged commit 6aed201 into ansvisor:main Oct 22, 2026
5 checks passed
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