( data: any, childPath: string, childLabelProp: string, schema: JsonSchema, rootSchema: JsonSchema, translateFct: Translator, uiSchema: UISchemaElement )
| 1351 | * @param {UISchemaElement} uiSchema the uiSchema of the control |
| 1352 | */ |
| 1353 | export const computeChildLabel = ( |
| 1354 | data: any, |
| 1355 | childPath: string, |
| 1356 | childLabelProp: string, |
| 1357 | schema: JsonSchema, |
| 1358 | rootSchema: JsonSchema, |
| 1359 | translateFct: Translator, |
| 1360 | uiSchema: UISchemaElement |
| 1361 | ): string => { |
| 1362 | const childData = Resolve.data(data, childPath); |
| 1363 | |
| 1364 | if (!childLabelProp) { |
| 1365 | childLabelProp = getFirstPrimitiveProp(schema); |
| 1366 | } |
| 1367 | |
| 1368 | // return early in case there is no prop we can query |
| 1369 | if (!childLabelProp) { |
| 1370 | return ''; |
| 1371 | } |
| 1372 | |
| 1373 | const currentValue = get(childData, childLabelProp); |
| 1374 | |
| 1375 | // in case there is no value, then we can't map it to an enum or oneOf |
| 1376 | if (currentValue === undefined) { |
| 1377 | return ''; |
| 1378 | } |
| 1379 | |
| 1380 | // check whether the value is part of a oneOf or enum and needs to be translated |
| 1381 | const childSchema = Resolve.schema( |
| 1382 | schema, |
| 1383 | '#' + getPropPath(childLabelProp), |
| 1384 | rootSchema |
| 1385 | ); |
| 1386 | |
| 1387 | let enumOption: EnumOption = undefined; |
| 1388 | if (isEnumSchema(childSchema)) { |
| 1389 | enumOption = enumToEnumOptionMapper( |
| 1390 | currentValue, |
| 1391 | translateFct, |
| 1392 | getI18nKeyPrefix( |
| 1393 | childSchema, |
| 1394 | findUiControl(uiSchema, childLabelProp), |
| 1395 | childPath + '.' + childLabelProp |
| 1396 | ) |
| 1397 | ); |
| 1398 | } else if (isOneOfEnumSchema(childSchema)) { |
| 1399 | const oneOfArray = childSchema.oneOf as JsonSchema[]; |
| 1400 | const oneOfSchema = oneOfArray.find((e: JsonSchema) => |
| 1401 | isEqual(e.const, currentValue) |
| 1402 | ); |
| 1403 | |
| 1404 | if (oneOfSchema) { |
| 1405 | enumOption = oneOfToEnumOptionMapper( |
| 1406 | oneOfSchema, |
| 1407 | translateFct, |
| 1408 | getI18nKeyPrefix( |
| 1409 | oneOfSchema, |
| 1410 | undefined, |
no test coverage detected
searching dependent graphs…