diff --git a/client-src/elements/chromedash-form-field.ts b/client-src/elements/chromedash-form-field.ts index 2b17ae2f7fea..fbc02ed4b253 100644 --- a/client-src/elements/chromedash-form-field.ts +++ b/client-src/elements/chromedash-form-field.ts @@ -479,7 +479,9 @@ export class ChromedashFormField extends LitElement { See web feature ${this.value} @@ -493,6 +495,31 @@ export class ChromedashFormField extends LitElement { } } +/** + * enumLabelToFeatureKey converts Webdx enum labels to + * web feature IDs. This function is rewritten from + * https://github.com/GoogleChrome/webstatus.dev/blob/6ae7ecf7c26e2563a6e1685cc6d92fc12bcc7941/lib/gcpspanner/spanneradapters/chromium_historgram_enum_consumer.go#L102-L125 + */ +function enumLabelToFeatureKey(label: string) { + let result = ''; + for (let i = 0; i < label.length; i++) { + const char = label[i]; + if (i === 0) { + result += char.toLowerCase(); + continue; + } + if (char === char.toUpperCase()) { + result += '-' + char.toLowerCase(); + continue; + } + if (i > 0 && /[a-zA-Z]/.test(label[i - 1]) && char >= '0' && char <= '9') { + result += '-'; + } + result += char; + } + return result; +} + /** * Gets the value of a field from a feature entry form, or from the feature. * Looks up the field name in the provided form field values, using the stageOrId