diff --git a/src/seed_tools/utils/study_json_utils.ts b/src/seed_tools/utils/study_json_utils.ts index ff77221d..032a147b 100644 --- a/src/seed_tools/utils/study_json_utils.ts +++ b/src/seed_tools/utils/study_json_utils.ts @@ -6,6 +6,7 @@ import { promises as fs } from 'fs'; import JSON5 from 'json5'; import { Study } from '../../proto/generated/study'; +import { channelToString, platformToString } from './serializers'; export interface Options { isChromium?: boolean; @@ -50,7 +51,7 @@ export function parseStudies( ): Study[] { const jsonStudies = JSON5.parse( studyArrayString, - jsonStudyReviever.bind(null, options), + jsonStudyReviewer.bind(null, options), ); if (!Array.isArray(jsonStudies)) { throw new Error('Root element must be an array'); @@ -86,29 +87,6 @@ export function stringifyStudies(studies: Study[], options?: Options): string { ); } -export function replaceChannels( - channels: string[] | undefined, - isChromium: boolean, -): string[] | undefined { - if (isChromium) return channels; - - return channels?.map((channel) => { - switch (channel) { - case 'CANARY': - return 'NIGHTLY'; - case 'STABLE': - return 'RELEASE'; - } - return channel; - }); -} - -export function replacePlatforms( - platforms: string[] | undefined, -): string[] | undefined { - return platforms?.map((platform) => platform.replace(/^PLATFORM_/, '')); -} - function jsonStudyReplacer( options: Options | undefined, key: string, @@ -120,17 +98,19 @@ function jsonStudyReplacer( return new Date(value * 1000).toISOString(); } case 'channel': { - return replaceChannels(value, options?.isChromium === true); + return value.map((c: string) => + channelToString(c, options?.isChromium === true), + ); } case 'platform': { - return replacePlatforms(value); + return value.map((p: string) => platformToString(p)); } default: return value; } } -function jsonStudyReviever( +function jsonStudyReviewer( options: Options | undefined, key: string, value: any, diff --git a/src/web/app/study_model.ts b/src/web/app/study_model.ts index f7cd84f4..bf0ac613 100644 --- a/src/web/app/study_model.ts +++ b/src/web/app/study_model.ts @@ -16,9 +16,9 @@ import { Study_Platform, } from '../../proto/generated/study'; import { - replaceChannels, - replacePlatforms, -} from '../../seed_tools/utils/study_json_utils'; + channelToString, + platformToString, +} from '../../seed_tools/utils/serializers'; import { ExperimentModel } from './experiment_model'; export class StudyModel { @@ -62,19 +62,14 @@ export class StudyModel { } platforms(): string[] | undefined { - const string_platforms = this.filter()?.platform?.map( - (p) => Study_Platform[p], + return this.filter()?.platform?.map((p) => + platformToString(Study_Platform[p]), ); - return replacePlatforms(string_platforms); } channels(): string[] | undefined { - const string_channels = this.filter()?.channel?.map( - (c) => Study_Channel[c], - ); - return replaceChannels( - string_channels, - this.seedType === SeedType.UPSTREAM, + return this.filter()?.channel?.map((c) => + channelToString(Study_Channel[c], this.seedType === SeedType.UPSTREAM), ); }