Skip to content
This repository was archived by the owner on Apr 6, 2022. It is now read-only.

Commit 02afd99

Browse files
committed
Fix compatibility with Normandy API
Fixes #9
1 parent c02ca1c commit 02afd99

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

extension/content/RecipesPage.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ import api from "./api";
77
const PAGE_SIZE = 10;
88
const normandy = browser.experiments.normandy;
99

10+
function convertToV1Recipe(v3Recipe) {
11+
// Normandy expects a v1-style recipe, but we have a v3-style recipe. Convert it.
12+
return {
13+
id: v3Recipe.id,
14+
name: v3Recipe.latest_revision.name,
15+
enabled: v3Recipe.latest_revision.enabled,
16+
is_approved: v3Recipe.latest_revision.is_approved,
17+
revision_id: v3Recipe.latest_revision.id,
18+
action: v3Recipe.latest_revision.action.name,
19+
arguments: v3Recipe.latest_revision.arguments,
20+
filter_expression: v3Recipe.latest_revision.filter_expression,
21+
};
22+
}
23+
1024
export default class RecipesPage extends React.Component {
1125
constructor(props) {
1226
super(props);
@@ -108,15 +122,19 @@ class Recipe extends React.Component {
108122

109123
async componentDidMount() {
110124
const { recipe } = this.props;
111-
let filterMatches = await normandy.checkRecipeFilter(recipe);
125+
let filterMatches = await normandy.checkRecipeFilter(convertToV1Recipe(recipe));
112126
this.setState({ filterMatches });
113127
}
114128

115129
render() {
116130
const { recipe, ...panelProps } = this.props;
117-
const { id, filter_expression, arguments: arguments_ } = recipe;
118131
const { filterMatches } = this.state;
119132

133+
const {
134+
id,
135+
latest_revision: { filter_expression, arguments: arguments_ },
136+
} = recipe;
137+
120138
return (
121139
<Collapse.Panel
122140
{...panelProps}
@@ -145,7 +163,7 @@ class Recipe extends React.Component {
145163
class RecipeHeader extends React.Component {
146164
render() {
147165
const { filterMatches, recipe } = this.props;
148-
const { id, name, enabled } = recipe;
166+
const { id, latest_revision: { name, enabled } } = recipe;
149167

150168
return (
151169
<div className="recipe-header">
@@ -212,22 +230,10 @@ class RunRecipeButton extends React.Component {
212230
this.handleClick = this.handleClick.bind(this);
213231
}
214232

215-
async handleClick() {
233+
async handleClick(ev) {
216234
const { recipe } = this.props;
217235
this.setState({ running: true });
218-
// Normandy expects a v1-style recipe, but we have a v3-style recipe. Convert it.
219-
const currentRevision = recipe.approved_revision || recipe.latest_revision;
220-
const v1Recipe = {
221-
id: recipe.id,
222-
name: currentRevision.recipe.name,
223-
enabled: currentRevision.recipe.enabled,
224-
is_approved: currentRevision.recipe.is_approved,
225-
revision_id: currentRevision.id,
226-
action: currentRevision.recipe.action.name,
227-
arguments: currentRevision.recipe.arguments,
228-
filter_expression: currentRevision.recipe.filter_expression,
229-
};
230-
await normandy.runRecipe(v1Recipe);
236+
await normandy.runRecipe(convertToV1Recipe(recipe));
231237
this.setState({ running: false });
232238
}
233239

0 commit comments

Comments
 (0)