Skip to content

Commit 1911670

Browse files
committed
Add showParticipantNumber option.
1 parent f5c89e3 commit 1911670

File tree

7 files changed

+56
-8
lines changed

7 files changed

+56
-8
lines changed

docs/assets/api/schemas.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,6 +1450,9 @@
14501450
"type": "string"
14511451
}
14521452
]
1453+
},
1454+
"showParticipantNumber": {
1455+
"type": "boolean"
14531456
}
14541457
}
14551458
},

frontend/src/components/stages/profile_stage_editor.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import '../../pair-components/textarea';
2+
import '@material/web/checkbox/checkbox.js';
23
import '@material/web/radio/radio';
34

45
import {MobxLitElement} from '@adobe/lit-mobx';
@@ -8,11 +9,7 @@ import {customElement, property} from 'lit/decorators.js';
89
import {core} from '../../core/core';
910
import {ExperimentEditor} from '../../services/experiment.editor';
1011

11-
import {
12-
ProfileType,
13-
ProfileStageConfig,
14-
StageKind,
15-
} from '@deliberation-lab/utils';
12+
import {ProfileType, ProfileStageConfig} from '@deliberation-lab/utils';
1613

1714
import {styles} from './profile_stage_editor.scss';
1815

@@ -99,6 +96,29 @@ export class ProfileStageEditorComponent extends MobxLitElement {
9996
></md-radio>
10097
<label>🐱 Generate anonymous animal-themed profiles</label>
10198
</div>
99+
${this.stage.profileType === ProfileType.ANONYMOUS_ANIMAL
100+
? html`
101+
<label class="checkbox-wrapper">
102+
<md-checkbox
103+
touch-target="wrapper"
104+
?checked=${this.stage.showParticipantNumber}
105+
?disabled=${!this.experimentEditor.canEditStages}
106+
@click=${() => {
107+
if (!this.stage) return;
108+
this.experimentEditor.updateStage({
109+
...this.stage,
110+
showParticipantNumber: !this.stage.showParticipantNumber,
111+
});
112+
}}
113+
>
114+
</md-checkbox>
115+
<span
116+
>Include numeric ID in name (e.g., Bear123 instead of
117+
Bear)</span
118+
>
119+
</label>
120+
`
121+
: nothing}
102122
<div class="profile-option">
103123
<md-radio
104124
name="profile-type"

functions/src/participant.endpoints.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,16 @@ export const createParticipant = onCall(async (request) => {
140140
) as ProfileStageConfig | undefined;
141141
const profileType =
142142
profileStage?.profileType || ProfileType.ANONYMOUS_ANIMAL;
143-
144-
setProfile(numParticipants, participantConfig, true, profileType);
143+
const showParticipantNumber =
144+
profileStage?.showParticipantNumber ?? false;
145+
146+
setProfile(
147+
numParticipants,
148+
participantConfig,
149+
true,
150+
profileType,
151+
showParticipantNumber,
152+
);
145153
} else {
146154
setProfile(numParticipants, participantConfig, false);
147155
}

scripts/deliberate_lab/types.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ class ProfileStageConfig(BaseModel):
391391
descriptions: StageTextConfig
392392
progress: StageProgressConfig
393393
profileType: ProfileType
394+
showParticipantNumber: bool | None = None
394395

395396

396397
class Strategy(StrEnum):

utils/src/participant.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export function setProfile(
191191
config: ParticipantProfileExtended,
192192
setAnonymousProfile = false,
193193
profileType: ProfileType = ProfileType.ANONYMOUS_ANIMAL,
194+
showParticipantNumber = false,
194195
) {
195196
const generateProfileFromSet = (
196197
profileSet: {name: string; avatar: string}[],
@@ -229,6 +230,13 @@ export function setProfile(
229230
const profileNature = generateProfileFromSet(PROFILE_SET_NATURE);
230231
const profileAnonymousParticipant = generateAnonymousParticipantProfile();
231232

233+
// Append random numerics to profile names (e.g., "Bear123" instead of "Bear")
234+
if (showParticipantNumber) {
235+
profileAnimal1.name = `${profileAnimal1.name}${randomNumber}`;
236+
profileAnimal2.name = `${profileAnimal2.name}${randomNumber}`;
237+
profileNature.name = `${profileNature.name}${randomNumber}`;
238+
}
239+
232240
config.anonymousProfiles[PROFILE_SET_ANIMALS_1_ID] = profileAnimal1;
233241
config.anonymousProfiles[PROFILE_SET_ANIMALS_2_ID] = profileAnimal2;
234242
config.anonymousProfiles[PROFILE_SET_NATURE_ID] = profileNature;
@@ -259,7 +267,12 @@ export function setProfile(
259267
config.avatar = participantProfile.avatar;
260268
} else if (profileType === ProfileType.ANONYMOUS_ANIMAL) {
261269
// Use animal profile (default)
262-
config.name = `${mainProfile.name}${mainProfile.repeat === 0 ? '' : ` ${mainProfile.repeat + 1}`}`;
270+
if (showParticipantNumber) {
271+
// Name already has numeric suffix (e.g., "Bear1234")
272+
config.name = mainProfile.name;
273+
} else {
274+
config.name = `${mainProfile.name}${mainProfile.repeat === 0 ? '' : ` ${mainProfile.repeat + 1}`}`;
275+
}
263276
config.avatar = mainProfile.avatar;
264277
}
265278
// Note: ProfileType.DEFAULT should not reach here as setAnonymousProfile would be false

utils/src/stages/profile_stage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export enum ProfileType {
2222
export interface ProfileStageConfig extends BaseStageConfig {
2323
kind: StageKind.PROFILE;
2424
profileType: ProfileType;
25+
showParticipantNumber?: boolean; // e.g., "Bear123" instead of "Bear"
2526
}
2627

2728
// ************************************************************************* //
@@ -39,5 +40,6 @@ export function createProfileStage(
3940
descriptions: config.descriptions ?? createStageTextConfig(),
4041
progress: config.progress ?? createStageProgressConfig(),
4142
profileType: config.profileType ?? ProfileType.DEFAULT,
43+
showParticipantNumber: config.showParticipantNumber ?? true,
4244
};
4345
}

utils/src/stages/profile_stage.validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export const ProfileStageConfigData = Type.Composite(
2323
Type.Literal(ProfileType.ANONYMOUS_ANIMAL),
2424
Type.Literal(ProfileType.ANONYMOUS_PARTICIPANT),
2525
]),
26+
showParticipantNumber: Type.Optional(Type.Boolean()),
2627
},
2728
strict,
2829
),

0 commit comments

Comments
 (0)