(item: T, definition: TableFieldDefinition<T>)
| 225 | } |
| 226 | |
| 227 | const getDisplayValueFor = <T extends object>(item: T, definition: TableFieldDefinition<T>): string | undefined => { |
| 228 | if (typeof definition === 'object' && 'value' in definition) { |
| 229 | return definition.value(item) |
| 230 | } |
| 231 | |
| 232 | if (typeof definition !== 'object' || 'prop' in definition) { |
| 233 | const propertyName = typeof definition !== 'object' ? definition : definition.prop |
| 234 | return stringFromUnknown(item[propertyName]) |
| 235 | } |
| 236 | |
| 237 | // The DefinitelyTyped type for the second parameter doesn't match what lodash actually |
| 238 | // takes so we cast it to the DefinitelyTyped type. |
| 239 | const matches = at(item, definition.path as unknown as keyof T) |
| 240 | if (matches.length === 0) { |
| 241 | logger.debug(`did not find match for ${definition.path} in ${JSON.stringify(item)}`) |
| 242 | return '' |
| 243 | } |
| 244 | if (matches.length > 1) { |
| 245 | logger.warn(`found more than one match for ${definition.path} in ${JSON.stringify(item)}`) |
| 246 | } |
| 247 | return matches.map(value => stringFromUnknown(value)).join(', ') |
| 248 | } |
| 249 | |
| 250 | const newOutputTable = (options?: Partial<TableOptions>): Table => { |
| 251 | const configuredOptions = { ...tableOptions } |
no test coverage detected