Skip to content

Commit e0a42c6

Browse files
committed
Fix incrementing logic on new cohort names
1 parent 2f25a13 commit e0a42c6

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

frontend/src/components/experiment_dashboard/cohort_list.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ export class Component extends MobxLitElement {
134134
}
135135

136136
private renderHeader() {
137-
const getCohortName = (length: number) => {
138-
return this.experimentManager.getNextCohortName(length);
137+
const getCohortName = (offset: number) => {
138+
return this.experimentManager.getNextCohortName(offset);
139139
};
140140

141141
return html`
@@ -155,9 +155,7 @@ export class Component extends MobxLitElement {
155155
?loading=${this.experimentManager.isWritingCohort}
156156
@click=${() => {
157157
this.analyticsService.trackButtonClick(ButtonClick.COHORT_ADD);
158-
const name = getCohortName(
159-
this.experimentManager.cohortList.length,
160-
);
158+
const name = getCohortName(0);
161159
this.experimentManager.createCohort({}, name);
162160
}}
163161
>
@@ -170,12 +168,11 @@ export class Component extends MobxLitElement {
170168
variant="tonal"
171169
?loading=${this.experimentManager.isWritingCohort}
172170
@click=${() => {
173-
const numCohorts = this.experimentManager.cohortList.length;
174171
[...Array(5).keys()].forEach((key) => {
175172
this.analyticsService.trackButtonClick(
176173
ButtonClick.COHORT_ADD,
177174
);
178-
const name = getCohortName(numCohorts + key);
175+
const name = getCohortName(key);
179176
this.experimentManager.createCohort({}, name);
180177
});
181178
}}
@@ -189,12 +186,11 @@ export class Component extends MobxLitElement {
189186
variant="tonal"
190187
?loading=${this.experimentManager.isWritingCohort}
191188
@click=${() => {
192-
const numCohorts = this.experimentManager.cohortList.length;
193189
[...Array(10).keys()].forEach((key) => {
194190
this.analyticsService.trackButtonClick(
195191
ButtonClick.COHORT_ADD,
196192
);
197-
const name = getCohortName(numCohorts + key);
193+
const name = getCohortName(key);
198194
this.experimentManager.createCohort({}, name);
199195
});
200196
}}

frontend/src/services/experiment.manager.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,27 @@ export class ExperimentManager extends Service {
369369
}
370370

371371
// Return name for next cohort based on number of cohorts
372-
getNextCohortName(numCohorts = this.cohortList.length) {
372+
getNextCohortName(offset = 0) {
373373
const hasTransfer = this.sp.experimentService.stages.find(
374374
(stage) => stage.kind === StageKind.TRANSFER,
375375
);
376-
if (numCohorts > 0 || !hasTransfer) {
377-
return `Cohort ${String(numCohorts).padStart(2, '0')}`;
376+
377+
if (this.cohortList.length === 0 && hasTransfer) {
378+
return 'Lobby';
378379
}
379-
return 'Lobby';
380+
381+
let maxNum = -1;
382+
this.cohortList.forEach((cohort) => {
383+
const match = cohort.metadata.name.match(/^Cohort (\d+)$/);
384+
if (match) {
385+
const num = parseInt(match[1], 10);
386+
if (!isNaN(num) && num > maxNum) {
387+
maxNum = num;
388+
}
389+
}
390+
});
391+
392+
return `Cohort ${String(maxNum + 1 + offset).padStart(2, '0')}`;
380393
}
381394

382395
isFullCohort(cohort: CohortConfig) {

0 commit comments

Comments
 (0)