|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | | -const dotProp = require('dot-prop'); |
| 15 | +import * as dotProp from 'dot-prop'; |
16 | 16 | import {Filter, RawFilter} from './filter'; |
17 | 17 | import { |
18 | 18 | CreateRulesCallback, |
@@ -46,6 +46,41 @@ export interface RowProperties { |
46 | 46 | reqOpts: TabularApiSurfaceRequest; |
47 | 47 | } |
48 | 48 |
|
| 49 | +function getNestedValue(obj: any, path: any) { |
| 50 | + if (!obj || typeof obj !== 'object' || !path) { |
| 51 | + return undefined; |
| 52 | + } |
| 53 | + |
| 54 | + const keys = path.split('.'); |
| 55 | + let current = obj; |
| 56 | + |
| 57 | + for (const key of keys) { |
| 58 | + if (current && typeof current === 'object' && key in current) { |
| 59 | + current = current[key]; |
| 60 | + } else { |
| 61 | + return undefined; // Path not found |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + return current; |
| 66 | +} |
| 67 | + |
| 68 | +function getValueFromData(data: any, column: any) { |
| 69 | + const path = column.replace(':', '.'); |
| 70 | + const nestedValue = getNestedValue(data, path); |
| 71 | + |
| 72 | + if ( |
| 73 | + Array.isArray(nestedValue) && |
| 74 | + nestedValue.length > 0 && |
| 75 | + nestedValue[0] && |
| 76 | + 'value' in nestedValue[0] |
| 77 | + ) { |
| 78 | + return nestedValue[0].value; |
| 79 | + } |
| 80 | + |
| 81 | + return undefined; // Or handle the case where the path or structure is not as expected |
| 82 | +} |
| 83 | + |
49 | 84 | /** |
50 | 85 | * RowDataUtils is a class containing functionality needed by the Row and |
51 | 86 | * AuthorizedView classes. Its static methods need to be contained in a class |
@@ -247,7 +282,7 @@ class RowDataUtils { |
247 | 282 | return; |
248 | 283 | } |
249 | 284 | const data = this.formatFamilies_Util(resp!.row!.families!); |
250 | | - const value = dotProp.get(data, column.replace(':', '.'))[0].value; |
| 285 | + const value = getValueFromData(data, column); |
251 | 286 |
|
252 | 287 | callback(null, value, resp); |
253 | 288 | }); |
|
0 commit comments