Skip to content

Commit

Permalink
Chore: Remove optional chaining for submissions and initialize defaul…
Browse files Browse the repository at this point in the history
…t values

Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 authored and backportbot[bot] committed Feb 5, 2025
1 parent 1e9d4eb commit 0ee598d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/components/Results/ResultsSummary.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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 @@ -130,7 +130,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 @@ -168,7 +168,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 @@ -186,7 +186,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 @@ -216,7 +216,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 @@ -105,7 +105,7 @@
<p>
{{
t('forms', '{amount} responses', {
amount: form.submissions?.length ?? 0,
amount: submissions.length ?? 0,
})
}}
</p>
Expand Down Expand Up @@ -230,19 +230,19 @@
<!-- Summary view for visualization -->
<section v-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 @@ -376,6 +376,9 @@ export default {
return {
activeResponseView: responseViews[0],

questions: [],
submissions: [],

isDownloadActionOpened: false,
loadingResults: true,

Expand Down Expand Up @@ -441,7 +444,7 @@ export default {
},

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

/**
Expand Down Expand Up @@ -523,8 +526,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 @@ -674,10 +677,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 @@ -702,7 +705,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

0 comments on commit 0ee598d

Please sign in to comment.