Skip to content

Commit ed1b01c

Browse files
committed
PB-2027: fix code so that marker/text test passes
simplifying a bit the useFieldValidation composable, and trying to maintain reactivity of props given there, even if it is two components down (EmailInput calls TextInput which calls useFieldValidation)
1 parent e3a6230 commit ed1b01c

File tree

10 files changed

+320
-349
lines changed

10 files changed

+320
-349
lines changed

packages/viewer/src/modules/infobox/components/styling/DrawingStyleMediaLink.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const emit = defineEmits<{
1717
}>()
1818
1919
const { t } = useI18n()
20-
const generatedMediaLink = ref<string | undefined>(undefined)
21-
const linkDescription = ref<string | undefined>(undefined)
20+
const generatedMediaLink = ref<string>()
21+
const linkDescription = ref<string>()
2222
const isFormValid = ref<boolean>(false)
2323
const activateValidation = ref<boolean>(false)
2424
@@ -117,14 +117,14 @@ function onUrlValidate(result: TextInputValidateResult): void {
117117
placeholder="paste_url"
118118
:validate="validateUrl"
119119
data-cy="drawing-style-media-url"
120-
@keydown.enter="addLink()"
120+
@keydown.enter="addLink"
121121
@validate="onUrlValidate"
122122
>
123123
<button
124124
class="btn btn-default btn-outline-group rounded-0 rounded-end"
125125
type="button"
126126
data-cy="drawing-style-media-generate-button"
127-
@click="addLink()"
127+
@click="addLink"
128128
>
129129
{{ t('add') }}
130130
</button>

packages/viewer/src/store/modules/drawing/actions/closeDrawing.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export default async function closeDrawing(this: DrawingStore, dispatcher: Actio
4141
await debounceSaveDrawing({ debounceTime: 0, retryOnError: false })
4242
}
4343

44-
4544
if (this.layer.config) {
4645
// flagging the layer as not edited anymore (not displayed on the map by the drawing module anymore)
4746
if (!this.online) {
@@ -62,13 +61,7 @@ export default async function closeDrawing(this: DrawingStore, dispatcher: Actio
6261

6362
delete this.layer.config
6463
}
65-
this.toggleDrawingOverlay(
66-
{
67-
show: false,
68-
},
69-
dispatcher
70-
)
71-
64+
this.overlay.show = false
7265
this.edit.featureType = undefined
7366
this.layer.ol?.getSource()?.clear()
7467

packages/viewer/src/utils/components/EmailInput.vue

Lines changed: 85 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,104 +6,100 @@ import { useComponentUniqueId } from '@/utils/composables/useComponentUniqueId'
66
import { useFieldValidation } from '@/utils/composables/useFieldValidation'
77
import { isValidEmail } from '@/utils/utils'
88
9-
const props = withDefaults(defineProps<{
10-
/** Label to add above the field */
11-
label?: string
12-
/** Description to add below the input */
13-
description?: string
14-
/** Mark the field as disable */
15-
disabled?: boolean
16-
/**
17-
* Placeholder text
18-
*
19-
* NOTE: this should be a translation key
20-
*/
21-
placeholder?: string
22-
/** Field is required and will be marked as invalid if empty */
23-
required?: boolean
24-
/**
25-
* Mark the field as valid
26-
*
27-
* This can be used if the field requires some external validation. When not set or set to
28-
* undefined this props is ignored.
29-
*
30-
* NOTE: this props is ignored when activate-validation is false
31-
*/
32-
validMarker?: boolean | undefined
33-
/**
34-
* Valid message Message that will be added in green below the field once the validation has
35-
* been done and the field is valid.
36-
*/
37-
validMessage?: string
38-
/**
39-
* Mark the field as invalid
40-
*
41-
* This can be used if the field requires some external validation. When not set or set to
42-
* undefined this props is ignored.
43-
*
44-
* NOTE: this props is ignored when activate-validation is false
45-
*/
46-
invalidMarker?: boolean | undefined
47-
/**
48-
* Invalid message Message that will be added in red below the field once the validation has
49-
* been done and the field is invalid.
50-
*
51-
* NOTE: this message is overwritten if the internal validation failed (not allow file type or
52-
* file too big or required empty file)
53-
*/
54-
invalidMessage?: string
55-
/**
56-
* Mark the field has validated.
57-
*
58-
* As long as the flag is false, no validation is run and no validation marks are set. Also the
59-
* props is-invalid and is-valid are ignored.
60-
*/
61-
activateValidation?: boolean
62-
/**
63-
* Validate function to run when the input changes The function should return an object of type
64-
* `{valid: Boolean, invalidMessage: String}`. The `invalidMessage` string should be a
65-
* translation key.
66-
*
67-
* NOTE: this function is called each time the field is modified
68-
*/
69-
validate?: ((_value?: string) => { valid: boolean; invalidMessage: string }) | undefined
70-
dataCy?: string
71-
}>(), {
72-
validMarker: undefined,
73-
invalidMarker: undefined,
74-
})
9+
const props = withDefaults(
10+
defineProps<{
11+
/** Label to add above the field */
12+
label?: string
13+
/** Description to add below the input */
14+
description?: string
15+
/** Mark the field as disable */
16+
disabled?: boolean
17+
/**
18+
* Placeholder text
19+
*
20+
* NOTE: this should be a translation key
21+
*/
22+
placeholder?: string
23+
/** Field is required and will be marked as invalid if empty */
24+
required?: boolean
25+
/**
26+
* Mark the field as valid
27+
*
28+
* This can be used if the field requires some external validation. When not set or set to
29+
* undefined this props is ignored.
30+
*
31+
* NOTE: this props is ignored when activate-validation is false
32+
*/
33+
validMarker?: boolean | undefined
34+
/**
35+
* Valid message Message that will be added in green below the field once the validation has
36+
* been done and the field is valid.
37+
*/
38+
validMessage?: string
39+
/**
40+
* Mark the field as invalid
41+
*
42+
* This can be used if the field requires some external validation. When not set or set to
43+
* undefined this props is ignored.
44+
*
45+
* NOTE: this props is ignored when activate-validation is false
46+
*/
47+
invalidMarker?: boolean | undefined
48+
/**
49+
* Invalid message Message that will be added in red below the field once the validation has
50+
* been done and the field is invalid.
51+
*
52+
* NOTE: this message is overwritten if the internal validation failed (not allow file type
53+
* or file too big or required empty file)
54+
*/
55+
invalidMessage?: string
56+
/**
57+
* Mark the field has validated.
58+
*
59+
* As long as the flag is false, no validation is run and no validation marks are set. Also
60+
* the props is-invalid and is-valid are ignored.
61+
*/
62+
activateValidation?: boolean
63+
/**
64+
* Validate function to run when the input changes The function should return an object of
65+
* type `{valid: Boolean, invalidMessage: String}`. The `invalidMessage` string should be a
66+
* translation key.
67+
*
68+
* NOTE: this function is called each time the field is modified
69+
*/
70+
validate?: ((_value?: string) => { valid: boolean; invalidMessage: string }) | undefined
71+
dataCy?: string
72+
}>(),
73+
{
74+
validMarker: undefined,
75+
invalidMarker: undefined,
76+
}
77+
)
7578
76-
const {
77-
label,
78-
description,
79-
disabled,
80-
placeholder,
81-
dataCy,
82-
} = toRefs(props)
79+
const { label, description, disabled, placeholder, dataCy } = toRefs(props)
8380
8481
const inputEmailId = useComponentUniqueId('email-input')
8582
8683
const model = defineModel<string>({ default: '' })
87-
const emits = defineEmits(['change', 'validate', 'focusin', 'focusout', 'keydown.enter'])
84+
const emits = defineEmits<{
85+
change: [void]
86+
validate: [isValid: boolean]
87+
focusin: [void]
88+
focusout: [void]
89+
'keydown.enter': [void]
90+
}>()
8891
const { t } = useI18n()
8992
9093
const {
9194
value,
9295
validMarker: computedValidMarker,
9396
invalidMarker: computedInvalidMarker,
94-
validMessage: computedValidMessage,
9597
invalidMessage: computedInvalidMessage,
96-
required: computedRequired,
9798
onFocus,
98-
} = useFieldValidation(
99-
props,
100-
model,
101-
emits as (_event: string, ..._args: unknown[]) => void,
102-
{
103-
customValidate: validateEmail,
104-
requiredInvalidMessage: 'no_email',
105-
}
106-
)
99+
} = useFieldValidation(props, model, emits, {
100+
customValidate: validateEmail,
101+
requiredInvalidMessage: 'no_email',
102+
})
107103
108104
const emailInputElement = useTemplateRef<HTMLInputElement>('emailInputElement')
109105
@@ -129,7 +125,7 @@ defineExpose({ focus })
129125
<label
130126
v-if="label"
131127
class="mb-2"
132-
:class="{ 'fw-bolder': computedRequired }"
128+
:class="{ 'fw-bolder': required }"
133129
:for="inputEmailId"
134130
data-cy="email-input-label"
135131
>
@@ -146,7 +142,7 @@ defineExpose({ focus })
146142
}"
147143
type="email"
148144
class="form-control"
149-
:required="computedRequired"
145+
:required="required"
150146
:placeholder="placeholder ? t(placeholder) : ''"
151147
data-cy="email-input"
152148
@focusin="onFocus($event, true)"
@@ -161,11 +157,11 @@ defineExpose({ focus })
161157
{{ t(computedInvalidMessage) }}
162158
</div>
163159
<div
164-
v-if="computedValidMessage"
160+
v-if="validMessage"
165161
class="valid-feedback"
166162
data-cy="email-input-valid-feedback"
167163
>
168-
{{ t(computedValidMessage) }}
164+
{{ t(validMessage) }}
169165
</div>
170166
<div
171167
v-if="description"

packages/viewer/src/utils/components/FileInput.vue

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const inputFileId = useComponentUniqueId('file-input')
115115
const { t } = useI18n()
116116
const model = defineModel<File | undefined>({ default: undefined })
117117
const emits = defineEmits<{
118-
change: []
118+
change: [void]
119119
validate: [isValid: boolean]
120120
}>()
121121
@@ -161,23 +161,11 @@ const {
161161
value,
162162
validMarker: computedValidMarker,
163163
invalidMarker: computedInvalidMarker,
164-
validMessage: computedValidMessage,
165164
invalidMessage: computedInvalidMessage,
166-
} = useFieldValidation<File>(
167-
validationProps,
168-
model,
169-
(event: string, ...args: unknown[]) => {
170-
if (event === 'change') {
171-
emits('change')
172-
} else if (event === 'validate') {
173-
emits('validate', args[0] as boolean)
174-
}
175-
},
176-
{
177-
customValidate: validateFile,
178-
requiredInvalidMessage: 'no_file',
179-
}
180-
)
165+
} = useFieldValidation<File>(validationProps, model, emits, {
166+
customValidate: validateFile,
167+
requiredInvalidMessage: 'no_file',
168+
})
181169
182170
const filePathInfo = computed(() =>
183171
value.value ? `${value.value.name}, ${value.value.size / 1000} kb` : ''
@@ -254,11 +242,11 @@ function onFileSelected(evt: Event): void {
254242
}}
255243
</div>
256244
<div
257-
v-if="computedValidMessage"
245+
v-if="validMessage"
258246
class="valid-feedback"
259247
data-cy="file-input-valid-feedback"
260248
>
261-
{{ t(computedValidMessage) }}
249+
{{ t(validMessage) }}
262250
</div>
263251
</div>
264252
<div

0 commit comments

Comments
 (0)