Skip to content

Commit

Permalink
Added retries count for each mode in respondent page (#1546)
Browse files Browse the repository at this point in the history
  • Loading branch information
devduarte authored and bcardiff committed Nov 14, 2019
1 parent 45a536e commit d6b2b6b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 14 deletions.
33 changes: 25 additions & 8 deletions test/controllers/respondent_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ defmodule Ask.RespondentControllerTest do

alias Ask.{QuotaBucket, Survey, SurveyLogEntry, Response, Respondent, ShortLink, Stats, ActivityLog}


@empty_stats %{
"attempts" => nil,
"total_call_time" => nil,
"total_call_time_seconds" => nil,
"total_received_sms" => 0,
"total_sent_sms" => 0
}

describe "normal" do
setup :user

Expand Down Expand Up @@ -40,7 +49,8 @@ defmodule Ask.RespondentControllerTest do
"value" => response.value,
"name" => response.field_name
}
]
],
"stats" => @empty_stats
}]
end

Expand Down Expand Up @@ -1054,7 +1064,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Exercises"
}
]
],
"stats" => @empty_stats
},
%{
"id" => respondent_2.id,
Expand All @@ -1071,7 +1082,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Smokes"
}
]
],
"stats" => @empty_stats
}
]
end
Expand Down Expand Up @@ -1110,7 +1122,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Exercises"
}
]
],
"stats" => @empty_stats
}
]
end
Expand Down Expand Up @@ -1144,7 +1157,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Smokes"
}
]
],
"stats" => @empty_stats
}
]
end
Expand Down Expand Up @@ -1178,7 +1192,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Smokes"
}
]
],
"stats" => @empty_stats
}
]
end
Expand Down Expand Up @@ -1267,7 +1282,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Perfect Number"
}
]
],
"stats" => @empty_stats
},
%{
"id" => respondent_2.id,
Expand All @@ -1285,7 +1301,8 @@ defmodule Ask.RespondentControllerTest do
"value" => "No",
"name" => "Smokes"
}
]
],
"stats" => @empty_stats
}
]
end
Expand Down
20 changes: 19 additions & 1 deletion web/static/js/components/respondents/RespondentIndex.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import RespondentRow from './RespondentRow'
import * as routes from '../../routes'
import { modeLabel } from '../../questionnaire.mode'
import find from 'lodash/find'
import flatten from 'lodash/flatten'
import { translate } from 'react-i18next'

type Props = {
Expand Down Expand Up @@ -109,6 +110,22 @@ class RespondentIndex extends Component<Props, State> {
this.props.actions.sortRespondentsBy(projectId, surveyId, name)
}

getModes(surveyModes) {
return [...new Set(flatten(surveyModes))]
}

getModeAttempts() {
const {survey, sortBy, sortAsc, t} = this.props
let modes = this.getModes(survey.mode)
let attemptsHeader = modes.map(function(mode) {
const capitalize = str => str.charAt(0).toUpperCase() + str.slice(1)
let modeTitle = capitalize(mode) + ' ' + 'Attempts'
return <SortableHeader key={mode} text={t(modeTitle)} property='stats' sortBy={sortBy} sortAsc={sortAsc} onClick={name => this.sortBy(name)} />
}
)
return attemptsHeader
}

resultsAccessLink() {
const {survey} = this.props
return find(survey.links, (link) => link.name == `survey/${survey.id}/results`)
Expand Down Expand Up @@ -336,7 +353,6 @@ class RespondentIndex extends Component<Props, State> {
</li>
)
}

return (
<div className='white'>
<div dangerouslySetInnerHTML={{
Expand Down Expand Up @@ -390,6 +406,7 @@ class RespondentIndex extends Component<Props, State> {
{variantHeader}
<th>{t('Disposition')}</th>
<SortableHeader text={t('Date')} property='date' sortBy={sortBy} sortAsc={sortAsc} onClick={name => this.sortBy(name)} />
{this.getModeAttempts()}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -423,6 +440,7 @@ class RespondentIndex extends Component<Props, State> {
respondent={respondent}
responses={responses}
variantColumn={variantColumn}
surveyModes={this.getModes(survey.mode)}
/>
})}
</tbody>
Expand Down
22 changes: 18 additions & 4 deletions web/static/js/components/respondents/RespondentRow.jsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
// @flow
import React, { Component } from 'react'
import React, {Component} from 'react'
import dateformat from 'dateformat'
import languageNames from 'language-names'
import capitalize from 'lodash/capitalize'

type Props = {
respondent: Respondent,
responses: Response[],
variantColumn: ?React$Element<*>
variantColumn: ?React$Element<*>,
surveyModes: string[]
};

class RespondentRow extends Component<Props> {
render() {
const { respondent, responses, variantColumn } = this.props

getModeAttemptsValues() {
const {respondent, surveyModes} = this.props
let modeValueRow = surveyModes.map(function(element, index) {
let modeValue = 0
if (respondent.stats.attempts) {
modeValue = respondent.stats.attempts[element] ? respondent.stats.attempts[element] : 0
}
return <td key={index}>{modeValue}</td>
})
return modeValueRow
}

render() {
const {respondent, responses, variantColumn} = this.props
return (
<tr key={respondent.id}>
<td> {respondent.phoneNumber}</td>
Expand All @@ -33,6 +46,7 @@ class RespondentRow extends Component<Props> {
<td>
{respondent.date ? dateformat(new Date(respondent.date), 'mmm d, yyyy HH:MM') : '-'}
</td>
{this.getModeAttemptsValues()}
</tr>
)
}
Expand Down
15 changes: 14 additions & 1 deletion web/static/js/decls/survey.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,20 @@ export type Respondent = {
disposition: Disposition,
date: ?string,
responses: Response[],
questionnaireId: number
questionnaireId: number,
stats: Stats
};

export type Attempts = {
sms: number,
ivr: number
};

export type Stats = {
attempts: Attempts,
totalSentSms: number,
totalReceivedSms: number,
totalCallTime: number
};

export type Integration = {
Expand Down
2 changes: 2 additions & 0 deletions web/views/respondent_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule Ask.RespondentView do
survey_id: respondent.survey_id,
mode: respondent.mode,
effective_modes: respondent.effective_modes,
stats: respondent.stats,
questionnaire_id: respondent.questionnaire_id,
responses: responses,
disposition: respondent.disposition,
Expand All @@ -40,6 +41,7 @@ defmodule Ask.RespondentView do
phone_number: respondent.hashed_number,
survey_id: respondent.survey_id,
effective_modes: respondent.effective_modes,
stats: respondent.stats,
mode: respondent.mode,
questionnaire_id: respondent.questionnaire_id,
responses: responses,
Expand Down

0 comments on commit d6b2b6b

Please sign in to comment.