diff --git a/client-src/elements/chromedash-ot-creation-page.ts b/client-src/elements/chromedash-ot-creation-page.ts index 067344a4..e7c7c81a 100644 --- a/client-src/elements/chromedash-ot-creation-page.ts +++ b/client-src/elements/chromedash-ot-creation-page.ts @@ -356,15 +356,16 @@ export class ChromedashOTCreationPage extends LitElement { this.featureId ); // We only need the single stage changes. - const stageSubmitBody = featureSubmitBody.stages[0] as Object; + const stageSubmitBody = featureSubmitBody.stages[0]; - // Add on the appropriate use counter prefix. - const useCounterPrefix = - this.webfeatureUseCounterType === USE_COUNTER_TYPE_WEBFEATURE - ? '' - : 'WebDXFeature::'; - stageSubmitBody['ot_webfeature_use_counter'].value = - `${useCounterPrefix}${stageSubmitBody['ot_webfeature_use_counter'].value}`; + if ('ot_webfeature_use_counter' in stageSubmitBody) { + // Add on the appropriate use counter prefix. + const useCounterPrefix = + this.webfeatureUseCounterType === USE_COUNTER_TYPE_WEBFEATURE + ? '' + : 'WebDXFeature::'; + stageSubmitBody.ot_webfeature_use_counter.value = `${useCounterPrefix}${stageSubmitBody.ot_webfeature_use_counter.value}`; + } this.submitting = true; window.csClient diff --git a/client-src/elements/utils.ts b/client-src/elements/utils.ts index d6172174..dea7db05 100644 --- a/client-src/elements/utils.ts +++ b/client-src/elements/utils.ts @@ -541,21 +541,22 @@ export interface FieldInfo { checkMessage?: string; } -/** - * @typedef {Object} UpdateSubmitBody - * @property {Object.} feature_changes An object with feature changes. - * key=field name, value=new field value. - * @property {Array.} stages The list of changes to specific stages. - * @property {boolean} has_changes Whether any valid changes are present for submission. - */ +interface UpdateSubmitBody { + feature_changes: FeatureUpdateInfo; + stages: StageUpdateInfo[]; + has_changes: boolean; +} -/** - * Prepare feature/stage changes to be submitted. - * @param {Array.} fieldValues List of fields in the form. - * @param {number} featureId The ID of the feature being updated. - * @return {UpdateSubmitBody} Formatted body of new PATCH request. - */ -export function formatFeatureChanges(fieldValues, featureId) { +interface StageUpdateInfo { + [stageField: string]: any; +} + +interface FeatureUpdateInfo { + [featureField: string]: any; +} + +// Prepare feature/stage changes to be submitted. +export function formatFeatureChanges(fieldValues, featureId): UpdateSubmitBody { let hasChanges = false; const featureChanges = {id: featureId}; // Multiple stages can be mutated, so this object is a stage of stages.