Skip to content

Commit 5cdb005

Browse files
authored
Merge pull request #3255 from nextcloud/refactor/errorMessage
refactor: move error handling to Question component with NcNoteCard
2 parents d8dffa0 + 44710bd commit 5cdb005

5 files changed

Lines changed: 38 additions & 51 deletions

File tree

src/components/Questions/Question.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@
147147
v-html="computedDescription" />
148148
<!-- eslint-enable vue/no-v-html -->
149149
</div>
150+
<NcNoteCard v-if="hasError" :id="errorId" type="error">
151+
{{ errorMessage }}
152+
</NcNoteCard>
150153
</div>
151154

152155
<!-- Question content -->
@@ -160,6 +163,7 @@ import NcActionCheckbox from '@nextcloud/vue/components/NcActionCheckbox'
160163
import NcActionInput from '@nextcloud/vue/components/NcActionInput'
161164
import NcActions from '@nextcloud/vue/components/NcActions'
162165
import NcButton from '@nextcloud/vue/components/NcButton'
166+
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
163167
import IconAlertCircleOutline from 'vue-material-design-icons/AlertCircleOutline.vue'
164168
import IconArrowDown from 'vue-material-design-icons/ArrowDown.vue'
165169
import IconArrowUp from 'vue-material-design-icons/ArrowUp.vue'
@@ -191,6 +195,7 @@ export default {
191195
NcActionCheckbox,
192196
NcActionInput,
193197
NcButton,
198+
NcNoteCard,
194199
},
195200
196201
inject: ['$markdownit'],
@@ -260,6 +265,11 @@ export default {
260265
type: Boolean,
261266
default: false,
262267
},
268+
269+
errorMessage: {
270+
type: String,
271+
default: null,
272+
},
263273
},
264274
265275
emits: [
@@ -314,6 +324,14 @@ export default {
314324
hasDescription() {
315325
return this.description !== ''
316326
},
327+
328+
hasError() {
329+
return !!this.errorMessage
330+
},
331+
332+
errorId() {
333+
return `q${this.index}_error`
334+
},
317335
},
318336
319337
// Ensure description is sized correctly on initial render

src/components/Questions/QuestionFile.vue

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
v-bind="questionProps"
99
:titlePlaceholder="answerType.titlePlaceholder"
1010
:warningInvalid="answerType.warningInvalid"
11+
:errorMessage="errorMessage"
1112
v-on="commonListeners">
1213
<template #actions>
1314
<template v-if="!allowedFileTypesDialogOpened">
@@ -78,10 +79,6 @@
7879
</template>
7980
</template>
8081

81-
<NcNoteCard v-if="hasError" :id="errorId" type="error">
82-
{{ errorMessage }}
83-
</NcNoteCard>
84-
8582
<div class="question__content">
8683
<ul>
8784
<NcListItem
@@ -160,7 +157,6 @@ import NcActionSeparator from '@nextcloud/vue/components/NcActionSeparator'
160157
import NcButton from '@nextcloud/vue/components/NcButton'
161158
import NcListItem from '@nextcloud/vue/components/NcListItem'
162159
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
163-
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
164160
import IconChevronLeft from 'vue-material-design-icons/ChevronLeft.vue'
165161
import IconFileDocumentAlert from 'vue-material-design-icons/FileDocumentAlertOutline.vue'
166162
import IconFile from 'vue-material-design-icons/FileOutline.vue'
@@ -205,7 +201,6 @@ export default {
205201
NcButton,
206202
NcListItem,
207203
NcLoadingIcon,
208-
NcNoteCard,
209204
Question,
210205
},
211206
@@ -215,7 +210,6 @@ export default {
215210
data() {
216211
return {
217212
fileTypes,
218-
errorMessage: null,
219213
fileLoading: false,
220214
maxFileSizeUnit: Object.keys(FILE_SIZE_UNITS)[0],
221215
maxFileSizeValue: '',
@@ -254,14 +248,6 @@ export default {
254248
255249
return t('forms', 'All file types are allowed.')
256250
},
257-
258-
hasError() {
259-
return !!this.errorMessage
260-
},
261-
262-
errorId() {
263-
return `q${this.index}_error`
264-
},
265251
},
266252
267253
mounted() {

src/components/Questions/QuestionGrid.vue

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,13 @@
1010
:warningInvalid="answerType.warningInvalid"
1111
:contentValid="contentValid"
1212
:shiftDragHandle="shiftDragHandle"
13+
:errorMessage="errorMessage"
1314
v-on="commonListeners">
1415
<template v-if="readOnly">
1516
<fieldset
1617
:name="name || undefined"
1718
:aria-labelledby="titleId"
1819
:aria-describedby="description ? descriptionId : undefined">
19-
<NcNoteCard v-if="hasError" :id="errorId" type="error">
20-
{{ errorMessage }}
21-
</NcNoteCard>
22-
2320
<table class="answer-grid">
2421
<thead>
2522
<tr>
@@ -181,7 +178,6 @@ import { VueDraggable as Draggable } from 'vue-draggable-plus'
181178
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
182179
import NcInputField from '@nextcloud/vue/components/NcInputField'
183180
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
184-
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
185181
import AnswerInput from './AnswerInput.vue'
186182
import Question from './Question.vue'
187183
import QuestionMixin from '../../mixins/QuestionMixin.js'
@@ -197,7 +193,6 @@ export default {
197193
NcCheckboxRadioSwitch,
198194
NcInputField,
199195
NcLoadingIcon,
200-
NcNoteCard,
201196
Question,
202197
},
203198
@@ -206,11 +201,6 @@ export default {
206201
207202
data() {
208203
return {
209-
/**
210-
* The shown error message
211-
*/
212-
errorMessage: null,
213-
214204
isDragging: false,
215205
isLoading: false,
216206
questionTypes: [
@@ -227,18 +217,10 @@ export default {
227217
return this.answerType.unique === true
228218
},
229219
230-
hasError() {
231-
return !!this.errorMessage
232-
},
233-
234220
shiftDragHandle() {
235221
return !this.readOnly && this.options.length !== 0 && !this.isLastEmpty
236222
},
237223
238-
errorId() {
239-
return `q${this.index}_error`
240-
},
241-
242224
questionType() {
243225
return this.extraSettings?.questionType ?? GridCellType.Radio
244226
},

src/components/Questions/QuestionMultiple.vue

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:warningInvalid="answerType.warningInvalid"
1111
:contentValid="contentValid"
1212
:shiftDragHandle="shiftDragHandle"
13+
:errorMessage="errorMessage"
1314
v-on="commonListeners">
1415
<template #actions>
1516
<NcActionCheckbox
@@ -72,9 +73,6 @@
7273
:name="name || undefined"
7374
:aria-labelledby="titleId"
7475
:aria-describedby="description ? descriptionId : undefined">
75-
<NcNoteCard v-if="hasError" :id="errorId" type="error">
76-
{{ errorMessage }}
77-
</NcNoteCard>
7876
<NcCheckboxRadioSwitch
7977
v-for="answer in choices"
8078
:key="answer.id"
@@ -186,7 +184,6 @@ import NcActionInput from '@nextcloud/vue/components/NcActionInput'
186184
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
187185
import NcInputField from '@nextcloud/vue/components/NcInputField'
188186
import NcLoadingIcon from '@nextcloud/vue/components/NcLoadingIcon'
189-
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
190187
import IconCheckboxBlankOutline from 'vue-material-design-icons/CheckboxBlankOutline.vue'
191188
import IconContentPaste from 'vue-material-design-icons/ContentPaste.vue'
192189
import IconRadioboxBlank from 'vue-material-design-icons/RadioboxBlank.vue'
@@ -215,7 +212,6 @@ export default {
215212
NcCheckboxRadioSwitch,
216213
NcInputField,
217214
NcLoadingIcon,
218-
NcNoteCard,
219215
OptionInputDialog,
220216
Question,
221217
},
@@ -225,10 +221,6 @@ export default {
225221
226222
data() {
227223
return {
228-
/**
229-
* The shown error message
230-
*/
231-
errorMessage: null,
232224
/**
233225
* This is used to cache the "other" answer, meaning if the user:
234226
* checks "other" types text, unchecks "other" and then re-check "other" the typed text is preserved
@@ -249,10 +241,6 @@ export default {
249241
return this.answerType.unique === true
250242
},
251243
252-
hasError() {
253-
return !!this.errorMessage
254-
},
255-
256244
shiftDragHandle() {
257245
return !this.readOnly && this.options.length !== 0 && !this.isLastEmpty
258246
},
@@ -272,10 +260,6 @@ export default {
272260
return this.isUnique ? this.values?.[0] : this.values
273261
},
274262
275-
errorId() {
276-
return `q${this.index}_error`
277-
},
278-
279263
allowOtherAnswer() {
280264
return this.extraSettings?.allowOtherAnswer ?? false
281265
},

src/mixins/QuestionMixin.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,15 @@ export default {
184184
Question,
185185
},
186186

187+
data() {
188+
return {
189+
/**
190+
* The shown error message
191+
*/
192+
errorMessage: null,
193+
}
194+
},
195+
187196
computed: {
188197
questionProps() {
189198
const props = { ...this.$props }
@@ -204,6 +213,14 @@ export default {
204213
return 'q' + this.index + '_desc'
205214
},
206215

216+
hasError() {
217+
return !!this.errorMessage
218+
},
219+
220+
errorId() {
221+
return 'q' + this.index + '_error'
222+
},
223+
207224
/**
208225
* Listeners for all questions to forward
209226
*/

0 commit comments

Comments
 (0)