Skip to content

feat: cohort segment detail view with CSV re-synchronisation - #8387

Merged
Zaimwa9 merged 14 commits into
mainfrom
feat/cohort-resync-frontend
Aug 28, 2026
Merged

feat: cohort segment detail view with CSV re-synchronisation#8387
Zaimwa9 merged 14 commits into
mainfrom
feat/cohort-resync-frontend

Conversation

@Zaimwa9

@Zaimwa9 Zaimwa9 commented Aug 26, 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

Detail view for CSV cohort-managed segments, replacing the read-only rules editor:

  • Sync status chip, progress bar and last-synchronisation time, polled while a synchronisation is in flight.
  • Editable name and description via the new cohort PATCH endpoint.
  • Re-upload flow reusing CsvUpload and the new shared CsvPreview, with a review summary before synchronising.
  • SegmentSelect shows the CSV chip and hides segments pending deletion.
  • Fixed double horizontal padding in the tabbed segment drawers.

Stacked on #8386.

How did you test this code?

Manually: created a CSV segment, re-uploaded a smaller file and verified the add/remove counts, progress and status against a running task processor; renamed the segment and checked list/breadcrumb refresh. Unit tests, eslint and typecheck (no new errors) pass.

image image image image image image

@Zaimwa9
Zaimwa9 requested a review from a team as a code owner August 26, 2026 13:19
@Zaimwa9
Zaimwa9 requested review from talissoncosta and removed request for a team August 26, 2026 13:19
@vercel

vercel Bot commented Aug 26, 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 28, 2026 12:28pm
flagsmith-frontend-staging Ready Ready Preview Aug 28, 2026 12:28pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Aug 28, 2026 12:28pm

Request Review

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The API stores last_synced_at, returns membership counts, and supports cohort PATCH updates. The frontend adds cohort query and update hooks, expanded types, reusable CSV preview and upload controls, and a CSV cohort detail interface. Users can edit CSV cohort fields, upload replacement identifiers, monitor synchronisation progress, and update metadata. Segment selectors exclude cohorts pending deletion and show cohort source badges. Tests and OpenAPI documentation cover the new behaviour.

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

Merge Risk: 🟠 High · up to 34688

CSV re-synchronisation can change feature-targeting membership, but concurrent uploads may produce an unintended combined result and the new editing flow may bypass the existing approval process for segment changes. These high-impact correctness and authorization risks should be resolved or explicitly accepted before merging.


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 26, 2026

Copy link
Copy Markdown
Contributor

Docker builds report

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

@Zaimwa9

Zaimwa9 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

@github-actions

github-actions Bot commented Aug 26, 2026

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  38.2 seconds
commit  3468816
info  🔄 Run: #19923 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  32.7 seconds
commit  3468816
info  🔄 Run: #19923 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.8 seconds
commit  3468816
info  🔄 Run: #19923 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  40.2 seconds
commit  3468816
info  🔄 Run: #19923 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  1 minute, 3 seconds
commit  b43eb61
info  🔄 Run: #19922 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  31.6 seconds
commit  b43eb61
info  🔄 Run: #19922 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  45.5 seconds
commit  b43eb61
info  🔄 Run: #19922 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  33.5 seconds
commit  b43eb61
info  🔄 Run: #19922 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  55.1 seconds
commit  2dff072
info  🔄 Run: #19904 (attempt 1)

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

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

passed  1 passed

Details

stats  1 test across 1 suite
duration  19.8 seconds
commit  2dff072
info  🔄 Run: #19904 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  39.6 seconds
commit  2dff072
info  🔄 Run: #19904 (attempt 1)

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

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

passed  2 passed

Details

stats  2 tests across 2 suites
duration  40.3 seconds
commit  2dff072
info  🔄 Run: #19904 (attempt 1)

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Visual Regression

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

Comment thread frontend/web/components/modals/CreateSegment.tsx Outdated
Comment thread frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.tsx Outdated
@themis-blindfold

Copy link
Copy Markdown
Contributor

⚖️ Themis review: 🟠 Fix before merge

The CSV cohort detail view needs two fixes before merge: preserve read-only access in the replacement view, and report synchronisation progress from stable work totals rather than mutable membership state. Completed unit, lint, UI, image, and preview checks passed; E2E jobs were still running.

Area Score
🎯 Correctness 2/5
🧪 Test coverage 2/5
📐 Code quality 3/5
🚀 Product impact 3/5

🟠 Majors

  • frontend/web/components/modals/CreateSegment.tsx:806 — CSV cohort details bypass the page's read-only mode.
  • frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.tsx:64 — removal-only synchronisations display incorrect progress.
📝 Walkthrough
  • Cohort API client - adds retrieve and PATCH endpoints with cache invalidation.
  • CSV cohort detail - replaces the rules editor with editable metadata, sync state, and polling.
  • Re-synchronisation - extracts the chosen CSV column, validates the generated upload, and submits it as a normalised CSV.
  • Segment surfaces - marks cohort options, hides pending deletions, and shares the preview component.
🧪 How to verify
  1. With Manage Segments, rename a CSV cohort segment and re-upload a CSV; verify the list and breadcrumb refresh.
  2. Without Manage Segments, open a CSV cohort segment directly and verify all mutation controls are unavailable.
  3. Re-sync a 1,000-member cohort to a 100-member CSV and verify progress advances meaningfully through removal work.
  4. Run cd frontend && npm run test:unit -- --runInBand common/utils/__tests__/csv.test.ts.

Automate: add component tests for read-only controls and add-only, remove-only, and mixed synchronisation progress.

Local CSV utility tests could not be started because the checkout lacks frontend dependencies.

Product take: This is a solid operational improvement for cohort-managed segments, but misleading progress and unavailable permissions make the primary management flow unreliable until fixed.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

A resync button should know which way the members are heading · reviewed at d4e34f7

@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-resync branch from c30addb to a5f02fe Compare August 26, 2026 13:49
@Zaimwa9
Zaimwa9 requested a review from a team as a code owner August 26, 2026 13:49
@Zaimwa9
Zaimwa9 requested review from khvn26 and removed request for a team August 26, 2026 13:49
@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-resync-frontend branch from d4e34f7 to c385cad Compare August 26, 2026 13:50
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Aug 26, 2026
@Zaimwa9

Zaimwa9 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

@themis-blindfold review

Comment thread frontend/common/types/responses.ts Outdated
@themis-blindfold

Copy link
Copy Markdown
Contributor

⚖️ Themis review: 🟠 Fix before merge

The new cohort detail screen bypasses the page's read-only permission and reports a fixed, misleading progress percentage for removal-only synchronisations; both active major findings remain unresolved. The completed CI suite is green. Local typecheck could not be rerun because the TypeScript compiler is not installed in this checkout.

Area Score
🎯 Correctness 2/5
🧪 Test coverage 2/5
📐 Code quality 3/5
🚀 Product impact 4/5

🟠 Majors

  • frontend/web/components/modals/CreateSegment.tsx: view-only users can submit cohort mutations.
  • frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.tsx: removal-only synchronisations do not show advancing progress.

🧹 Nits

  • frontend/common/types/responses.ts: Mixpanel is missing from the cohort source-type union.
📝 Walkthrough
  • Cohort detail - replaces the rules editor for CSV-managed segments with metadata, status, and update controls.
  • CSV synchronisation - reuses upload and preview components to send a normalised single-column CSV.
  • Cohort service - adds retrieve and PATCH requests and cache invalidation for the detail view.
🧪 How to verify
  1. Open a CSV cohort segment as a user without Manage Segments and confirm no name, description, or upload mutation can be submitted.
  2. Re-synchronise a 1,000-member cohort down to 100 members and confirm the progress bar advances through the removals to completion.
  3. Fetch a Mixpanel-managed segment and confirm its cohort source type is accepted by the frontend API types.
  4. Run cd frontend && npm run typecheck in a dependency-complete checkout.
    Automate: Add component tests for the read-only controls, polling/progress states, and source-type response fixtures.

Product take: A solid improvement to CSV cohort management, but view-only roles and removal-heavy synchronisations cannot be trusted until the two major issues are fixed.

🧭 Assumptions & unverified claims

No unverified assumptions or claims.

Two threads still need their cohort moment · reviewed at c385cad

Comment thread frontend/web/components/CsvPreview/CsvPreview.scss Outdated
Comment thread frontend/web/components/CsvUpload/CsvUpload.scss Outdated
Comment thread frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.scss Outdated
@Zaimwa9
Zaimwa9 force-pushed the feat/cohort-resync-frontend branch from 5a0375f to 2dff072 Compare August 28, 2026 07:52
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request labels Aug 28, 2026
Base automatically changed from feat/cohort-resync to main August 28, 2026 11:11
@Zaimwa9
Zaimwa9 dismissed talissoncosta’s stale review August 28, 2026 11:11

The base branch was changed.

@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates labels Aug 28, 2026
@github-actions github-actions Bot added feature New feature or request and removed feature New feature or request docs Documentation updates labels Aug 28, 2026
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (0f0e09a) to head (3468816).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8387   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files        1620     1621    +1     
  Lines       66018    66102   +84     
=======================================
+ Hits        65234    65318   +84     
  Misses        784      784           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@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: 1148b737-93ba-47d2-bf29-d2b685e491c9

📥 Commits

Reviewing files that changed from the base of the PR and between bbc4bd1 and b43eb61.

📒 Files selected for processing (25)
  • api/cohorts/migrations/0005_cohort_last_synced_at.py
  • api/cohorts/models.py
  • api/cohorts/serializers.py
  • api/cohorts/services.py
  • api/cohorts/views.py
  • api/tests/unit/cohorts/test_views.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md
  • frontend/common/services/useCohort.ts
  • frontend/common/types/requests.ts
  • frontend/common/types/responses.ts
  • frontend/common/utils/csv.ts
  • frontend/web/components/CsvPreview/CsvPreview.scss
  • frontend/web/components/CsvPreview/CsvPreview.tsx
  • frontend/web/components/CsvPreview/index.ts
  • frontend/web/components/CsvUpload/CsvUpload.tsx
  • frontend/web/components/SegmentSelect.tsx
  • frontend/web/components/modals/CreateSegment.tsx
  • frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.scss
  • frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.tsx
  • frontend/web/components/segments/CohortSegmentDetail/CohortCsvSync.tsx
  • frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.scss
  • frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.tsx
  • frontend/web/components/segments/CohortSegmentDetail/index.ts
  • frontend/web/components/segments/SegmentRow/SegmentRow.tsx
  • openapi.yaml
💤 Files with no reviewable changes (2)
  • frontend/web/components/modals/CreateSegmentFromCsv/CreateSegmentFromCsv.scss
  • frontend/web/components/segments/SegmentRow/SegmentRow.tsx

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

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

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

Caution

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

⚠️ Outside diff range comments (2)
frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.tsx (2)

74-84: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Reset synchronisation progress when the cohort changes.

When the same CohortSegmentDetail instance receives a new cohort, syncTotal remains from the previous cohort. A lower pendingCount does not replace it because the effect applies Math.max(total, pendingCount). Key the snapshot by cohort identity and initialise it from the new cohort’s pending work.


86-89: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Reset the form baseline when the segment identity changes.

When SegmentPage changes the route, the existing component can receive a different segment. If both segments have the same name and description, this effect does not reset the local form values. Include segment.id in the dependency list.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7c42fc81-f8c7-426f-ad51-71fa8d82118e

📥 Commits

Reviewing files that changed from the base of the PR and between b43eb61 and 3468816.

📒 Files selected for processing (3)
  • frontend/web/components/modals/CreateSegment.tsx
  • frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.scss
  • frontend/web/components/segments/CohortSegmentDetail/CohortSegmentDetail.tsx

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

@Zaimwa9
Zaimwa9 merged commit 7cb90aa into main Aug 28, 2026
40 checks passed
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