Skip to content

Commit

Permalink
Merge pull request #197 from politics-rewired/politics-rewired/script…
Browse files Browse the repository at this point in the history
…-options

Add script options
  • Loading branch information
bchrobot authored Jun 26, 2019
2 parents 1df8e51 + 2d19d4e commit 9da9a02
Show file tree
Hide file tree
Showing 38 changed files with 649 additions and 293 deletions.
48 changes: 48 additions & 0 deletions migrations/20190625124200_add_interaction_step_script_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Add script_options column to interaction_step
exports.up = function(knex, Promise) {
return knex.schema
.alterTable("interaction_step", table => {
table.specificType("script_options", "text ARRAY").nullable();
})
.then(() =>
// Backfill values
knex("interaction_step").update({
script_options: knex.raw("ARRAY[script]")
})
)
.then(() =>
// Make not nullable
knex.schema.alterTable("interaction_step", table => {
table
.specificType("script_options", "text ARRAY")
.notNullable()
.alter();
})
)
.then(() =>
knex.schema.alterTable("interaction_step", table => {
table.dropColumn("script");
})
);
};

// Drop script_options column to interaction_step
exports.down = function(knex, Promise) {
return knex.schema
.alterTable("interaction_step", table => {
table
.text("script")
.notNullable()
.defaultTo("");
})
.then(() =>
knex("interaction_step").update({
script: knex.raw("script_options[0]")
})
)
.then(() =>
knex.schema.alterTable("interaction_step", table => {
table.dropColumn("script_options");
})
);
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
"react-async-script": "^0.6.0",
"react-chartjs": "^0.7.3",
"react-dom": "^15.6.1",
"react-formal": "^0.18.5",
"react-formal": "^0.25.4",
"react-router": "^2.5.2",
"react-router-redux": "^4.0.5",
"react-select": "^2.0.0",
Expand All @@ -153,7 +153,7 @@
"webpack-manifest-plugin": "^1.3.2",
"winston": "^3.2.1",
"winston-mongodb": "^4.0.3",
"yup": "^0.19.0"
"yup": "^0.27.0"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/api/interaction-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const schema = `
id: ID!
question: Question
questionText: String
script: String
scriptOptions: [String]!
answerOption: String
parentInteractionId: String
isDeleted: Boolean
Expand Down
2 changes: 1 addition & 1 deletion src/api/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const rootSchema = `
input InteractionStepInput {
id: String
questionText: String
script: String
scriptOptions: [String]!
answerOption: String
answerActions: String
parentInteractionId: String
Expand Down
2 changes: 2 additions & 0 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Form from "react-formal";
import GSTextField from "./forms/GSTextField";
import GSDateField from "./forms/GSDateField";
import GSScriptField from "./forms/GSScriptField";
import GSScriptOptionsField from "./forms/GSScriptOptionsField";
import GSSelectField from "./forms/GSSelectField";

// Needed for MaterialUI
Expand All @@ -20,6 +21,7 @@ Form.addInputTypes({
date: GSDateField,
email: GSTextField,
script: GSScriptField,
scriptOptions: GSScriptOptionsField,
select: GSSelectField
});

Expand Down
8 changes: 7 additions & 1 deletion src/components/AssignmentTexterSurveys.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import PropTypes from "prop-types";
import React, { Component } from "react";
import sample from "lodash/sample";

import { grey50 } from "material-ui/styles/colors";
import { Card, CardHeader, CardText } from "material-ui/Card";
import MenuItem from "material-ui/MenuItem";
Expand Down Expand Up @@ -34,7 +36,11 @@ class AssignmentTexterSurveys extends Component {
const answerOption = interactionStep.question.answerOptions[answerIndex];

const { nextInteractionStep } = answerOption;
return nextInteractionStep ? nextInteractionStep.script : null;
if (nextInteractionStep) {
const { scriptOptions } = nextInteractionStep;
return sample(scriptOptions);
}
return null;
}

handleExpandChange = newExpandedState => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CampaignAutoassignModeForm.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import PropTypes from "prop-types";
import yup from "yup";
import * as yup from "yup";
import Form from "react-formal";
import Toggle from "material-ui/Toggle";

Expand Down
2 changes: 1 addition & 1 deletion src/components/CampaignBasicsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Form from "react-formal";
import moment from "moment";
import CampaignFormSectionHeading from "./CampaignFormSectionHeading";
import GSForm from "./forms/GSForm";
import yup from "yup";
import * as yup from "yup";
import Toggle from "material-ui/Toggle";
import ColorPicker from "material-ui-color-picker";
import { dataTest } from "../lib/attributes";
Expand Down
2 changes: 1 addition & 1 deletion src/components/CampaignCannedResponseForm.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type from "prop-types";
import React from "react";
import { StyleSheet, css } from "aphrodite";
import yup from "yup";
import * as yup from "yup";
import GSForm from "./forms/GSForm";
import Form from "react-formal";
import FlatButton from "material-ui/FlatButton";
Expand Down
2 changes: 1 addition & 1 deletion src/components/CampaignCannedResponsesForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Divider from "material-ui/Divider";
import CampaignFormSectionHeading from "./CampaignFormSectionHeading";
import DeleteIcon from "material-ui/svg-icons/action/delete";
import IconButton from "material-ui/IconButton";
import yup from "yup";
import * as yup from "yup";
import CreateIcon from "material-ui/svg-icons/content/create";
import theme from "../styles/theme";
import { StyleSheet, css } from "aphrodite";
Expand Down
2 changes: 1 addition & 1 deletion src/components/CampaignContactsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import WarningIcon from "material-ui/svg-icons/alert/warning";
import ErrorIcon from "material-ui/svg-icons/alert/error";
import theme from "../styles/theme";
import { StyleSheet, css } from "aphrodite";
import yup from "yup";
import * as yup from "yup";
import { dataTest } from "../lib/attributes";

const checkIcon = <CheckIcon color={theme.colors.green} />;
Expand Down
Loading

0 comments on commit 9da9a02

Please sign in to comment.