Skip to content

Conversation

@willdurand
Copy link
Member

@willdurand willdurand commented Oct 2, 2017

Fix mozilla/addons#10854
Fix mozilla/addons-frontend#3319


This PR ensures we use an internal addon representation and exposes a themeData property to this internal representation. It helped fixing an issue with collections not displaying a preview (because the collections reducer uses internal addon representation).

(Note: I am aware of mozilla/addons#10819 but did not want to open a big PR)

Before:

screen shot 2017-10-02 at 23 52 04

After:

screen shot 2017-10-03 at 00 51 36

@willdurand willdurand requested a review from kumar303 October 2, 2017 22:52
@codecov-io
Copy link

codecov-io commented Oct 2, 2017

Codecov Report

Merging #3320 into master will decrease coverage by 0.02%.
The diff coverage is 90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    mozilla/addons-frontend#3320      +/-   ##
==========================================
- Coverage   95.57%   95.55%   -0.03%     
==========================================
  Files         166      166              
  Lines        3163     3169       +6     
  Branches      632      634       +2     
==========================================
+ Hits         3023     3028       +5     
- Misses        120      121       +1     
  Partials       20       20
Impacted Files Coverage Δ
src/core/types/addons.js 0% <ø> (ø) ⬆️
src/amo/components/SearchResult/index.js 100% <100%> (ø) ⬆️
src/core/reducers/search.js 100% <100%> (ø) ⬆️
src/amo/reducers/addonsByAuthors.js 100% <100%> (ø) ⬆️
src/amo/reducers/landing.js 100% <100%> (ø) ⬆️
src/core/reducers/addons.js 97.67% <83.33%> (-2.33%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a1c06c4...e63c910. Read the comment docs.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup!

type LoadOtherAddonsByAuthorsParams = {|
slug: string,
addons: Array<AddonType>,
addons: Array<ExternalAddonType>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, good catch

version: apiAddon.theme_data.version,
}),
// We should be using this property.
themeData: removeUndefinedProps({ ...apiAddon.theme_data }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be themeData: apiAddon.theme_data because removeUndefinedProps() was only necessary to make the spread not override existing property values with undefined.

version: apiAddon.theme_data.version,
}),
// We should be using this property.
themeData: removeUndefinedProps({ ...apiAddon.theme_data }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to introduce a mapper and call this like themeData: createInternalThemeData(apiAddon) because of several reasons:

  • Even though it adds verbosity, I think it's helpful to see all the fields assigned one by one
  • When a new field is added to the API, we won't introduce the new field by surprise
  • We already have to fix the mapping for one of the fields (description) because of a bug
  • We may need to re-map others later on too.

You can move all of this stuff into a new createInternalThemeData() function.

expect(state.featured.results)
.toEqual([{ slug: 'foo' }, { slug: 'food' }]);
.toEqual([
createInternalAddon({ slug: 'foo' }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should both be { ...fakeAddon, slug: '...' }

updateURL: apiAddon.theme_data.updateURL,
version: apiAddon.theme_data.version,
}),
// We should be using this property.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to put a comment up above where theme_data gets merged into addon saying "use addon.themeData[themeProp] instead of addon[themeProp]"

loadAddons(createFetchAddonResult(theme).entities));

const expectedTheme = {
const expectedTheme = createInternalAddon({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not use createInternalAddon(). This test is a bit weird but the intention of it was to manually recreate the theme addon to test that the mapper is doing what we expect it to. If you use createInternalAddon() then this test is pointless since it relies on that for the mapping. Instead of manually creating the entire theme addon, the test was using some spreads for the mapped properties that exactly match the original. Maybe it needs some comments to clarify this?

const { results } = getNextState();
expect(results).toEqual([{ slug: 'foo' }, { slug: 'food' }]);
expect(results).toEqual([
createInternalAddon({ slug: 'foo' }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't mark each one but a couple more of these need to change to { ...fakeAddon, slug: '...' }

windows: undefined,
},
isRestartRequired: false,
themeData,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, this is an old test and it's not very useful. It may be worth just using createInternalAddon({ ...fakeDiscoAddon, ... }) for the assertions here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we are not using the internal addon representation here, or I don't understand how it works right now :/

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, should be ok now.

@willdurand willdurand requested a review from kumar303 October 3, 2017 17:23
@willdurand
Copy link
Member Author

@kumar303 updated the code, thanks for your comments! ready for a second look.

Copy link
Contributor

@kumar303 kumar303 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks

@willdurand willdurand merged commit 3d5f3d1 into mozilla:master Oct 3, 2017
@willdurand willdurand deleted the fix-collection-theme branch October 3, 2017 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No preview of theme in collection view

3 participants