Skip to content

Commit

Permalink
Cirrus has enrolments as an array
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinnl committed Jan 16, 2025
1 parent 2b7d8d7 commit d4a959a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/app/hooks/useGlean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ export const useGlean = () => {
typeof experimentData["Enrollments"] !== "undefined"
) {
(data as GleanMetricMap["button"]["click"]).nimbus_user_id =
experimentData["Enrollments"]["nimbus_user_id"];
experimentData["Enrollments"][0]?.nimbus_user_id;
(data as GleanMetricMap["button"]["click"]).nimbus_app_id =
experimentData["Enrollments"]["app_id"];
experimentData["Enrollments"][0]?.app_id;
(data as GleanMetricMap["button"]["click"]).nimbus_experiment =
experimentData["Enrollments"]["experiment"];
experimentData["Enrollments"][0]?.experiment;
(data as GleanMetricMap["button"]["click"]).nimbus_branch =
experimentData["Enrollments"]["branch"];
experimentData["Enrollments"][0]?.branch;
(data as GleanMetricMap["button"]["click"]).nimbus_experiment_type =
experimentData["Enrollments"]["experiment_type"];
experimentData["Enrollments"][0]?.experiment_type;
(data as GleanMetricMap["button"]["click"]).nimbus_is_preview =
experimentData["Enrollments"]["is_preview"].toString();
experimentData["Enrollments"][0]?.is_preview.toString();
} else {
console.warn("No experiment data available for Glean");
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default async function RootLayout({
previewMode: nimbusPreviewMode === "true",
});

const nimbus_user_id = experimentData["Enrollments"]?.nimbus_user_id;
const nimbus_user_id = experimentData["Enrollments"]?.[0]?.nimbus_user_id;
if (
typeof nimbus_user_id !== "undefined" &&
nimbus_user_id !== experimentationId
Expand Down
58 changes: 31 additions & 27 deletions src/scripts/build/nimbusTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,19 @@ function getFallbackObject(nimbusConfig) {
);

const defaultExperimentData = `
"Features": {
Features: {
${featureFallbackDefs.join("\n")}
},
"Enrollments": {
"nimbus_user_id": "-1",
"app_id": "-1",
"experiment": "-1",
"branch": "-1",
"experiment_type": "-1",
"is_preview": false
}`;
Enrollments: [
{
nimbus_user_id: "-1",
app_id: "-1",
experiment: "-1",
branch: "-1",
experiment_type: "-1",
is_preview: false
}
]`;
return `export const defaultExperimentData: ExperimentData = {\n${defaultExperimentData}};\n`;
}

Expand All @@ -129,17 +131,19 @@ function getLocalOverrides(nimbusConfig) {
);

const localExperimentData = `
"Features": {
Features: {
${featureLocalOverridesDefs.join("\n")}
},
"Enrollments": {
"nimbus_user_id": "-1",
"app_id": "-1",
"experiment": "-1",
"branch": "-1",
"experiment_type": "-1",
"is_preview": false
}`;
Enrollments: [
{
nimbus_user_id: "-1",
app_id: "-1",
experiment: "-1",
branch: "-1",
experiment_type: "-1",
is_preview: false
}
]`;

return `export const localExperimentData: ExperimentData = {\n${localExperimentData}};\n`;
}
Expand All @@ -160,15 +164,15 @@ function getFeaturesTypeDef(nimbusConfig) {
});

const experimentDataType = `{
"Features": {${featureDefs.join("")}};
"Enrollments": {
"nimbus_user_id": string,
"app_id": string,
"experiment": string,
"branch": string,
"experiment_type": string,
"is_preview": boolean
};
Features: {${featureDefs.join("")}};
Enrollments: Array<{
nimbus_user_id: string,
app_id: string,
experiment: string,
branch: string,
experiment_type: string,
is_preview: boolean
}>;
};`;

const experimentDataTypeDef = `/** Status of experiments, as setup in Experimenter */\nexport type ExperimentData = ${experimentDataType}`;
Expand Down

0 comments on commit d4a959a

Please sign in to comment.