Skip to content

Commit 921d751

Browse files
committed
refactor: improve validation handling in jsonforms-renderer and schemas-bar components
- Enhanced the getSchemaValidations method to better manage schema-specific validations and normalize error paths. - Updated the getTabValidations method to utilize a recursive function for more robust validation checks. - Added logic to handle additionalFields validations in the identity table component during error responses.
1 parent a37d6d7 commit 921d751

File tree

4 files changed

+84
-17
lines changed

4 files changed

+84
-17
lines changed

apps/web/src/components/core/jsonforms-renderer.vue

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,61 @@ export default defineNuxtComponent({
196196
}
197197
},
198198
getSchemaValidations(): any[] {
199-
let validationList: any = []
200-
if (!this.schemaName) {
201-
validationList = this.validations || []
202-
} else {
203-
validationList = this.validations[this.schemaName] || []
199+
const rootValidations = this.validations || {}
200+
const hasSchemaScopedValidation = Boolean(this.schemaName && rootValidations?.[this.schemaName])
201+
const isFlatValidationMap = Object.values(rootValidations).every((value) => typeof value === 'string' || Array.isArray(value))
202+
203+
const scopedValidations = !this.schemaName
204+
? rootValidations
205+
: hasSchemaScopedValidation
206+
? rootValidations[this.schemaName]
207+
: isFlatValidationMap
208+
? rootValidations
209+
: {}
210+
211+
const entries: Array<{ path: string; message: string }> = []
212+
213+
const collectValidationEntries = (value: unknown, path = ''): void => {
214+
if (value == null) return
215+
216+
if (typeof value === 'string') {
217+
const message = value.trim()
218+
if (message) entries.push({ path, message })
219+
return
220+
}
221+
222+
if (Array.isArray(value)) {
223+
for (const item of value) {
224+
if (typeof item === 'string' && item.trim()) {
225+
entries.push({ path, message: item.trim() })
226+
}
227+
}
228+
return
229+
}
230+
231+
if (typeof value === 'object') {
232+
for (const [key, child] of Object.entries(value as Record<string, unknown>)) {
233+
const nextPath = path ? `${path}.${key}` : key
234+
collectValidationEntries(child, nextPath)
235+
}
236+
}
204237
}
205238
206-
const errorObject: ErrorObject[] = []
207-
for (const key in validationList) {
208-
errorObject.push({
209-
message: validationList[key],
210-
instancePath: `/${key}`,
239+
collectValidationEntries(scopedValidations)
240+
241+
return entries.map((entry) => {
242+
const normalizedPath = entry.path
243+
.split('.')
244+
.filter(Boolean)
245+
.join('/')
246+
247+
return {
248+
message: entry.message,
249+
instancePath: normalizedPath ? `/${normalizedPath}` : '',
211250
keyword: 'type',
212251
params: {},
213-
} as any)
214-
}
215-
216-
return errorObject
252+
} as ErrorObject
253+
})
217254
},
218255
readonlyRenderer(): boolean {
219256
return this.readonly || /1|true|on|yes/i.test(String(this.$route.query.readonly).toLowerCase())

apps/web/src/components/pages/identities/schemas-bar.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,15 @@ export default defineNuxtComponent({
163163
},
164164
methods: {
165165
getTabValidations(tab: string) {
166-
return this.validations?.hasOwnProperty(tab) ? 'red' : false
166+
const hasValidation = (value: unknown): boolean => {
167+
if (value == null) return false
168+
if (typeof value === 'string') return value.trim().length > 0
169+
if (Array.isArray(value)) return value.length > 0
170+
if (typeof value === 'object') return Object.values(value as Record<string, unknown>).some(hasValidation)
171+
return false
172+
}
173+
174+
return hasValidation(this.validations?.[tab]) ? 'red' : false
167175
},
168176
addSchema(schema) {
169177
if (!this.identity.additionalFields) {

apps/web/src/pages/identities/table/[_id].vue

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ export default defineNuxtComponent({
148148
body: sanitizedIdentity,
149149
})
150150
151+
if (this.identity?.additionalFields?.validations) {
152+
this.identity.additionalFields.validations = {}
153+
}
154+
151155
if (this.isNew) {
152156
this.$router.push('/identities/table')
153157
}
@@ -169,6 +173,24 @@ export default defineNuxtComponent({
169173
icon: 'mdi-alert-circle-outline',
170174
})
171175
console.error('Erreur lors de la sauvegarde de l identité:', error)
176+
177+
if (error?.response?._data?.validations) {
178+
if (!this.identity.additionalFields) {
179+
this.identity.additionalFields = {
180+
attributes: {},
181+
objectClasses: [],
182+
validations: {},
183+
}
184+
}
185+
186+
if (!this.identity.additionalFields.validations) {
187+
this.identity.additionalFields.validations = {}
188+
}
189+
190+
this.identity.additionalFields.validations = {
191+
...error.response._data.validations,
192+
}
193+
}
172194
}
173195
},
174196
async sync() {

apps/web/src/pages/settings/health.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ export default defineNuxtComponent({
407407
return 'Maintenance inactive, support open source sur GitHub.'
408408
}
409409
if (supportKeyVerificationStatus.value === 'valid') {
410-
return 'Contrat de maintenance actif.'
410+
return 'Support & maintenance actif.'
411411
}
412412
if (supportKeyVerificationStatus.value === 'checking' || supportKeyVerificationStatus.value === 'idle') {
413413
return 'Verification de la clé de maintenance en cours...'
414414
}
415-
return 'Contrat de maintenance configuré, mais clé de maintenance invalide.'
415+
return 'Support & maintenance configuré, mais clé de maintenance invalide.'
416416
})
417417
418418
const { data, pending, error, refresh } = useHttp<HealthHttpResponse>('/core/health', {

0 commit comments

Comments
 (0)