Skip to content

feat: wire CSV segments to the cohorts API - #8295

Merged
Zaimwa9 merged 5 commits into
mainfrom
feat/cohort-csv-frontend
Aug 25, 2026
Merged

feat: wire CSV segments to the cohorts API#8295
Zaimwa9 merged 5 commits into
mainfrom
feat/cohort-csv-frontend

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Wires the CSV segment drawer (#8283) to the cohorts API (#8294).

Create flow

  • New useCohort service: createCohort, syncCohortCsv (multipart) and deleteCohort mutations, invalidating the segment list.
  • The drawer submits in two steps: create the cohort, then sync the trimmed, headerless, single-column CSV built from the selected identifier column. Only the identifier column leaves the browser. If the sync fails, retrying reuses the created cohort instead of creating a duplicate segment.
  • Success toast reports the added count from the API and stays visible for 10 seconds.
  • Custom Fields (metadata) are sent with the create call.

Segment list

  • CSV-backed segments show a CSV chip and a chip with the targeted environment's name, driven by the cohort summary on the segment payload.
  • Removing a CSV segment routes through the cohort delete endpoint (the segment endpoint rejects cohort-managed segments); plain segments are unchanged.
  • Deletion is drain-then-delete on the API side, so while a cohort is awaiting drain the row is greyed out, cannot be opened, and has no actions.
  • Fixed the row action dropdown staying open under the confirm modal (it only closed on outside clicks).

Upload hardening

  • CsvUpload takes a maxSizeBytes prop; the drawer passes 10MB to mirror the API cap, so oversized files are rejected client-side with a clear message.
  • toParsedCsv no longer spreads every row into Math.max, which overflowed the call stack on large files.

How did you test this code?

  • Unit tests for the CSV utilities (17 passing), including quoting and column extraction.
  • Manual QA against a local API: happy path with multi-column and single-column files, count parity between the preview and the toast, metadata on create, oversized file rejection, CSV and plain segment deletion, the deleting state, and membership rows verified in the database.
image

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner August 14, 2026 14:37
@Zaimwa9
Zaimwa9 requested review from kyle-ssg and talissoncosta and removed request for a team August 14, 2026 14:37
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview Aug 25, 2026 1:08pm
flagsmith-frontend-staging Ready Ready Preview Aug 25, 2026 1:08pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 25, 2026 1:08pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added typed cohort APIs and request and response contracts. Added UTF-8 identifier limits, CSV column serialisation, and upload size validation. Updated the CSV modal to create cohorts and synchronise identifier columns. Updated segment deletion and read-only editing for cohort-managed segments. Segment rows now show cohort details and deletion state.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: 🟠 High · up to 73abe

The CSV segment creation workflow can crash when users select a file or open Custom Fields because required UI components are missing imports, so the feature is not ready to merge until this is fixed. Cohort-managed segment metadata can also be edited locally despite being read-only, although those changes are not saved.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-8295 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-8295 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-8295 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-8295 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-8295 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-8295 Finished ✅ Results

@Zaimwa9

Zaimwa9 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@Zaimwa9
Zaimwa9 removed the request for review from kyle-ssg August 14, 2026 14:41
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor
✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19734 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.5 seconds
commit  73abef4
info  🔄 Run: #19734 (attempt 1)

🗂️ Previous results
✅ private-cloud · depot-ubuntu-latest-16 — run #19734 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  32.5 seconds
commit  73abef4
info  🔄 Run: #19734 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #19734 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  40.6 seconds
commit  73abef4
info  🔄 Run: #19734 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #19734 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  41.2 seconds
commit  73abef4
info  🔄 Run: #19734 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19719 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  1 minute, 4 seconds
commit  290b0c1
info  🔄 Run: #19719 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #19719 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  4 passed

Details

stats  4 tests across 4 suites
duration  32.6 seconds
commit  290b0c1
info  🔄 Run: #19719 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #19719 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  38.5 seconds
commit  290b0c1
info  🔄 Run: #19719 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #19719 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.6 seconds
commit  290b0c1
info  🔄 Run: #19719 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-arm-16 — run #19710 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.1 seconds
commit  b2ed327
info  🔄 Run: #19710 (attempt 1)

✅ private-cloud · depot-ubuntu-latest-16 — run #19710 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  32.1 seconds
commit  b2ed327
info  🔄 Run: #19710 (attempt 1)

✅ oss · depot-ubuntu-latest-arm-16 — run #19710 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.5 seconds
commit  b2ed327
info  🔄 Run: #19710 (attempt 1)

✅ oss · depot-ubuntu-latest-16 — run #19710 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  36.7 seconds
commit  b2ed327
info  🔄 Run: #19710 (attempt 1)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8b480a4e-0382-4485-8041-aa747fe926f9

📥 Commits

Reviewing files that changed from the base of the PR and between aa61a35 and f5c68a3.

📒 Files selected for processing (10)
  • frontend/common/services/useCohort.ts
  • frontend/common/types/requests.ts
  • frontend/common/types/responses.ts
  • frontend/common/utils/__tests__/csv.test.ts
  • frontend/common/utils/csv.ts
  • frontend/web/components/CsvUpload/CsvUpload.tsx
  • frontend/web/components/modals/ConfirmRemoveSegment.tsx
  • frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.tsx
  • frontend/web/components/segments/SegmentRow/SegmentRow.tsx
  • frontend/web/components/segments/SegmentRow/components/SegmentAction.tsx

Comment thread frontend/common/types/requests.ts
Comment thread frontend/web/components/modals/ConfirmRemoveSegment.tsx Outdated
Comment thread frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.tsx Outdated
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

19 screenshots compared. See report for details.
View full report

@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-csv-frontend branch from f5c68a3 to 5757a9d Compare August 14, 2026 14:48
@Zaimwa9
Zaimwa9 requested review from a team as code owners August 14, 2026 14:48
@Zaimwa9
Zaimwa9 requested review from matthewelwell and removed request for a team August 14, 2026 14:48
@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates labels Aug 14, 2026
@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-csv-sync branch from aa61a35 to 4083994 Compare August 14, 2026 14:49
@Zaimwa9
Zaimwa9 removed the request for review from matthewelwell August 14, 2026 14:51
Comment thread frontend/web/components/modals/ConfirmRemoveSegment.tsx Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.tsx (1)

1-2: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Import the JSX components before use.

Select on Line 244 and FormGroup on Line 378 have no binding in this module. Selecting a CSV or opening Custom Fields throws a ReferenceError.

Proposed fix
 import React, { FC, FormEvent, useMemo, useState } from 'react'
 import classNames from 'classnames'
+import Select from 'react-select'
+import { FormGroup } from 'reactstrap'

Also applies to: 244-261, 378-390


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4c190586-88c5-49af-9b90-fcbc2e78c96c

📥 Commits

Reviewing files that changed from the base of the PR and between ecb0485 and 73abef4.

📒 Files selected for processing (4)
  • frontend/common/types/requests.ts
  • frontend/common/types/responses.ts
  • frontend/web/components/modals/CreateSegment.tsx
  • frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.tsx

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Comment thread frontend/web/components/modals/CreateSegment.tsx

@talissoncosta talissoncosta 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 pretty good, just some non-blocking comments.

What about the name input, is it intentional to be narrow ?

Image

Comment thread frontend/common/services/useCohort.ts
Comment thread frontend/common/types/responses.ts
@Zaimwa9
Zaimwa9 merged commit d0485cc into main Aug 25, 2026
31 checks passed
@Zaimwa9
Zaimwa9 deleted the feat/cohort-csv-frontend branch August 25, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API feature New feature or request front-end Issue related to the React Front End Dashboard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants