Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Refactor submission handling in Results.vue #2541

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/components/Results/ResultsSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<meter
:id="`option-${option.questionId}-${option.id}`"
min="0"
:max="submissions?.length"
:max="submissions.length"
:value="option.count" />
</li>
</ol>
Expand Down Expand Up @@ -113,7 +113,7 @@ export default {
})

// Go through submissions to check which options have how many responses
this.submissions?.forEach((submission) => {
this.submissions.forEach((submission) => {
const answers = submission.answers.filter(
(answer) => answer.questionId === this.question.id,
)
Expand Down Expand Up @@ -151,7 +151,7 @@ export default {
questionOptionsStats.forEach((questionOptionsStat) => {
// Fill percentage values
questionOptionsStat.percentage = Math.round(
(100 * questionOptionsStat.count) / this.submissions?.length,
(100 * questionOptionsStat.count) / this.submissions.length,
)
// Mark all best results. First one is best for sure due to sorting
questionOptionsStat.best =
Expand All @@ -169,7 +169,7 @@ export default {
let noResponseCount = 0

// Go through submissions to check which options have how many responses
this.submissions?.forEach((submission) => {
this.submissions.forEach((submission) => {
const answers = submission.answers.filter(
(answer) => answer.questionId === this.question.id,
)
Expand Down Expand Up @@ -199,7 +199,7 @@ export default {

// Calculate no response percentage
const noResponsePercentage = Math.round(
(100 * noResponseCount) / this.submissions?.length,
(100 * noResponseCount) / this.submissions.length,
)
answersModels.unshift({
id: 0,
Expand Down
25 changes: 14 additions & 11 deletions src/views/Results.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<p>
{{
t('forms', '{amount} responses', {
amount: form.submissions?.length ?? 0,
amount: submissions.length ?? 0,
})
}}
</p>
Expand Down Expand Up @@ -193,19 +193,19 @@
<!-- Summary view for visualization -->
<section v-else-if="activeResponseView.id === 'summary'">
<ResultsSummary
v-for="question in form.questions"
v-for="question in questions"
:key="question.id"
:question="question"
:submissions="form.submissions" />
:submissions="submissions" />
</section>

<!-- Responses view for individual responses -->
<section v-else>
<Submission
v-for="submission in form.submissions"
v-for="submission in submissions"
:key="submission.id"
:submission="submission"
:questions="form.questions"
:questions="questions"
:can-delete-submission="canDeleteSubmissions"
@delete="deleteSubmission(submission.id)" />
</section>
Expand Down Expand Up @@ -339,6 +339,9 @@ export default {
return {
activeResponseView: responseViews[0],

questions: [],
submissions: [],

isDownloadActionOpened: false,
loadingResults: true,

Expand Down Expand Up @@ -404,7 +407,7 @@ export default {
},

noSubmissions() {
return this.form.submissions?.length === 0
return this.submissions.length === 0
},

/**
Expand Down Expand Up @@ -486,8 +489,8 @@ export default {
)

// Append questions & submissions
this.$set(this.form, 'submissions', loadedSubmissions)
this.$set(this.form, 'questions', loadedQuestions)
this.submissions = loadedSubmissions
this.questions = loadedQuestions
} catch (error) {
logger.error('Error while loading results', { error })
showError(t('forms', 'There was an error while loading the results'))
Expand Down Expand Up @@ -639,10 +642,10 @@ export default {
),
)
showSuccess(t('forms', 'Submission deleted'))
const index = this.form.submissions.findIndex(
const index = this.submissions.findIndex(
(search) => search.id === id,
)
this.form.submissions.splice(index, 1)
this.submissions.splice(index, 1)
emit('forms:last-updated:set', this.form.id)
} catch (error) {
logger.error(`Error while removing response ${id}`, { error })
Expand All @@ -667,7 +670,7 @@ export default {
id: this.form.id,
}),
)
this.form.submissions = []
this.submissions = []
emit('forms:last-updated:set', this.form.id)
} catch (error) {
logger.error('Error while removing responses', { error })
Expand Down
Loading