@@ -4,7 +4,11 @@ import { oneLine } from 'common-tags';
44import { ADDON_TYPE_THEME } from 'core/constants' ;
55import type { ErrorHandlerType } from 'core/errorHandler' ;
66import log from 'core/logger' ;
7- import type { AddonType , ExternalAddonType } from 'core/types/addons' ;
7+ import type {
8+ AddonType ,
9+ ExternalAddonType ,
10+ ThemeData ,
11+ } from 'core/types/addons' ;
812
913
1014export const LOAD_ADDONS = 'LOAD_ADDONS' ;
@@ -80,6 +84,42 @@ export function removeUndefinedProps(object: Object): Object {
8084 return newObject;
8185}
8286
87+ export function createInternalThemeData(
88+ apiAddon: ExternalAddonType
89+ ): ThemeData | null {
90+ if (!apiAddon.theme_data) {
91+ return null;
92+ }
93+
94+ return {
95+ accentcolor: apiAddon.theme_data.accentcolor,
96+ author: apiAddon.theme_data.author,
97+ category: apiAddon.theme_data.category,
98+
99+ // TODO: Set this back to apiAddon.theme_data.description after
100+ // https://github.com/mozilla/addons-frontend/issues/1416 is fixed.
101+ // theme_data will contain ` description : 'None '` when the description is
102+ // actually ` null ` and we don't want to set that on the addon itself so we
103+ // reset it in case it's been overwritten.
104+ //
105+ // See also https://github.com/mozilla/addons-server/issues/5650.
106+ description: apiAddon.description,
107+
108+ detailURL: apiAddon.theme_data.detailURL,
109+ footer: apiAddon.theme_data.footer,
110+ footerURL: apiAddon.theme_data.footerURL,
111+ header: apiAddon.theme_data.header,
112+ headerURL: apiAddon.theme_data.headerURL,
113+ iconURL: apiAddon.theme_data.iconURL,
114+ id: apiAddon.theme_data.id,
115+ name: apiAddon.theme_data.name,
116+ previewURL: apiAddon.theme_data.previewURL,
117+ textcolor: apiAddon.theme_data.textcolor,
118+ updateURL: apiAddon.theme_data.updateURL,
119+ version: apiAddon.theme_data.version,
120+ };
121+ }
122+
83123export function createInternalAddon(
84124 apiAddon: ExternalAddonType
85125): AddonType {
@@ -138,41 +178,21 @@ export function createInternalAddon(
138178 };
139179
140180 if (addon.type === ADDON_TYPE_THEME && apiAddon.theme_data) {
141- // This merges theme_data into the addon.
142- // TODO: Let's stop doing that because it's confusing. Lots of
143- // deep button / install code will need to be fixed.
144- addon = {
145- ...addon,
146- ...removeUndefinedProps({
147- accentcolor: apiAddon.theme_data.accentcolor,
148- author: apiAddon.theme_data.author,
149- category: apiAddon.theme_data.category,
150-
151- // TODO: Set this back to apiAddon.theme_data.description after
152- // https://github.com/mozilla/addons-frontend/issues/1416
153- // is fixed.
154- // theme_data will contain ` description : 'None '` when the
155- // description
156- // is actually ` null ` and we don't want to set that on the addon
157- // itself so we reset it in case it's been overwritten.
158- //
159- // See also https://github.com/mozilla/addons-server/issues/5650.
160- description: apiAddon.description,
161-
162- detailURL: apiAddon.theme_data.detailURL,
163- footer: apiAddon.theme_data.footer,
164- footerURL: apiAddon.theme_data.footerURL,
165- header: apiAddon.theme_data.header,
166- headerURL: apiAddon.theme_data.headerURL,
167- iconURL: apiAddon.theme_data.iconURL,
168- id: apiAddon.theme_data.id,
169- name: apiAddon.theme_data.name,
170- previewURL: apiAddon.theme_data.previewURL,
171- textcolor: apiAddon.theme_data.textcolor,
172- updateURL: apiAddon.theme_data.updateURL,
173- version: apiAddon.theme_data.version,
174- }),
175- };
181+ const themeData = createInternalThemeData(apiAddon);
182+
183+ if (themeData !== null) {
184+ // This merges theme_data into the addon.
185+ //
186+ // TODO: Let's stop doing that because it's confusing. Lots of deep
187+ // button/install code will need to be fixed.
188+ //
189+ // Use addon.themeData[themeProp] instead of addon[themeProp].
190+ addon = {
191+ ...addon,
192+ ...removeUndefinedProps(themeData),
193+ themeData,
194+ };
195+ }
176196 }
177197
178198 if (apiAddon.current_version && apiAddon.current_version.files.length > 0) {
0 commit comments