Skip to content

Commit bcbaba4

Browse files
committed
Enable flow on src/amo/reducers/utils.js
1 parent 3df25cc commit bcbaba4

File tree

11 files changed

+35
-23
lines changed

11 files changed

+35
-23
lines changed

src/amo/actions/reviews.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export function createInternalReview(
8686
reviewAddon: {
8787
iconUrl: review.addon.icon_url,
8888
id: review.addon.id,
89+
// $FlowIgnore: the add-on's name cannot be falsey.
8990
name: selectLocalizedContent(review.addon.name, lang),
9091
slug: review.addon.slug,
9192
},

src/amo/components/HomepageShelves/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import url from 'url';
33

44
import * as React from 'react';
5+
import invariant from 'invariant';
56

67
import LandingAddonsCard from 'amo/components/LandingAddonsCard';
78
import LoadingText from 'amo/components/LoadingText';
@@ -68,6 +69,9 @@ export const HomepageShelvesBase = (props: InternalProps): React.Node => {
6869
} else {
6970
shelvesContent = shelves.map((shelf) => {
7071
const { addons, addonType, endpoint, footer, title, url: apiUrl } = shelf;
72+
73+
invariant(title, 'title is required');
74+
7175
const shelfKey = title.replace(/\s/g, '-');
7276

7377
const footerText = footer.text

src/amo/pages/AddonInfo/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class AddonInfoBase extends React.Component<InternalProps> {
118118
const needsLicenceText =
119119
addonVersion &&
120120
addonVersion.license &&
121-
addonVersion.license.text === undefined;
121+
addonVersion.license.text === null;
122122
if (
123123
addon &&
124124
addon.currentVersionId &&

src/amo/reducers/addons.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ export const selectLocalizedUrlWithOutgoing = (
195195
): UrlWithOutgoing | null => {
196196
if (url && url.url && url.outgoing) {
197197
return {
198+
// $FlowIgnore: this can't be `null` because we check before.
198199
url: selectLocalizedContent(url.url, lang),
200+
// $FlowIgnore: this can't be `null` because we check before.
199201
outgoing: selectLocalizedContent(url.outgoing, lang),
200202
};
201203
}
@@ -234,6 +236,7 @@ export function createInternalAddon(
234236
last_updated: apiAddon.last_updated,
235237
latest_unlisted_version: apiAddon.latest_unlisted_version,
236238
locale_disambiguation: apiAddon.locale_disambiguation,
239+
// $FlowIgnore: the add-on's name cannot be falsey.
237240
name: selectLocalizedContent(apiAddon.name, lang),
238241
previews: apiAddon.previews
239242
? createInternalPreviews(apiAddon.previews, lang)

src/amo/reducers/autocomplete.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type ExternalSuggestion = {|
2929
export type SuggestionType = {|
3030
addonId: number,
3131
iconUrl: string,
32-
name: string,
32+
name: string | null,
3333
promoted: Array<PromotedType>,
3434
type: string,
3535
url: string,

src/amo/reducers/blocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type ExternalBlockType = {|
2424

2525
export type BlockType = {|
2626
...ExternalBlockType,
27-
name: string,
27+
name: string | null,
2828
|};
2929

3030
export type BlocksState = {|

src/amo/reducers/home.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export type InternalPrimaryHeroShelfExternalAddonType = {|
3939
id: string,
4040
guid: string,
4141
homepage: UrlWithOutgoing | null,
42-
name: string,
42+
name: string | null,
4343
type: string,
4444
|};
4545

@@ -116,18 +116,18 @@ export type ExternalSecondaryHeroShelfType = {|
116116
export type LinkWithTextType = {|
117117
url: string,
118118
outgoing: string,
119-
text: string,
119+
text: string | null,
120120
|};
121121

122122
export type SecondaryHeroModuleType = {|
123123
icon: string,
124-
description: string,
124+
description: string | null,
125125
cta: LinkWithTextType | null,
126126
|};
127127

128128
export type SecondaryHeroShelfType = {|
129-
headline: string,
130-
description: string,
129+
headline: string | null,
130+
description: string | null,
131131
cta: LinkWithTextType | null,
132132
modules: Array<SecondaryHeroModuleType>,
133133
|} | null;
@@ -152,7 +152,7 @@ export type ExternalResultShelfType = {|
152152
|};
153153

154154
export type ResultShelfType = {|
155-
title: string,
155+
title: string | null,
156156
url: string,
157157
endpoint: string,
158158
addonType: AddonTypeType,

src/amo/reducers/utils.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1+
/* @flow */
12
import invariant from 'invariant';
23

34
import type { LocalizedString } from 'amo/types/api';
45

5-
import type { CategoryEntry } from './categories';
6-
import type { ExternalAddonType, PromotedType } from '../types/addons';
6+
import type {
7+
ExternalAddonType,
8+
PartialExternalAddonType,
9+
PromotedType,
10+
} from '../types/addons';
711

812
export const selectLocalizedContent = (
9-
field: LocalizedString,
13+
field: ?LocalizedString,
1014
lang: string,
11-
) => {
15+
): string | null => {
1216
invariant(lang, 'lang must not be empty');
1317
if (!field) {
1418
return null;
@@ -22,9 +26,9 @@ export const selectLocalizedContent = (
2226
};
2327

2428
export const selectCategoryObject = (
25-
apiAddon: ExternalAddonType,
26-
): CategoryEntry => {
27-
return apiAddon.categories;
29+
apiAddon: ExternalAddonType | PartialExternalAddonType,
30+
): Array<string> => {
31+
return apiAddon.categories || [];
2832
};
2933

3034
export const makeInternalPromoted = (

src/amo/reducers/versions.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export type ExternalVersionLicenseType = {|
7777

7878
type PartialVersionLicenseType = {|
7979
name: string | null,
80-
text?: string,
80+
text: string | null,
8181
url: string,
8282
|};
8383

@@ -98,7 +98,7 @@ export type AddonVersionType = {
9898
isStrictCompatibilityEnabled: boolean,
9999
license: VersionLicenseType | null,
100100
file: AddonFileType | null,
101-
releaseNotes?: string,
101+
releaseNotes: string | null,
102102
version: string,
103103
};
104104

@@ -146,7 +146,7 @@ export const createInternalVersion = (
146146
name: selectLocalizedContent(version.license.name, lang),
147147
text:
148148
version.license.text === undefined
149-
? undefined
149+
? null
150150
: selectLocalizedContent(version.license.text, lang),
151151
url: version.license.url,
152152
}

src/amo/types/addons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export type ExternalLanguageToolType = {|
5959

6060
export type LanguageToolType = {|
6161
...ExternalLanguageToolType,
62-
name: string,
62+
name: string | null,
6363
|};
6464

6565
export type PromotedType = {|
@@ -83,7 +83,7 @@ export type PreviewType = {|
8383
thumbnail_h: number,
8484
thumbnail_src: string,
8585
thumbnail_w: number,
86-
title: string,
86+
title: string | null,
8787
w: number,
8888
|};
8989

0 commit comments

Comments
 (0)