(searchFilter: SandDance.searchExpression.Search, columns: powerbiVisualsApi.DataViewMetadataColumn[], data: object[])
| 6 | import { SandDance } from '@msrvida/sanddance-explorer'; |
| 7 | |
| 8 | export function convertFilter(searchFilter: SandDance.searchExpression.Search, columns: powerbiVisualsApi.DataViewMetadataColumn[], data: object[]) { |
| 9 | const selectedIds: powerbiVisualsApi.extensibility.ISelectionId[] = []; |
| 10 | const filters: powerbiModels.IFilter[] = []; |
| 11 | const groups = SandDance.searchExpression.ensureSearchExpressionGroupArray(searchFilter); |
| 12 | groups.forEach(group => |
| 13 | group.expressions.forEach(ex => { |
| 14 | if (!ex) return; |
| 15 | if (ex.name === SandDance.constants.GL_ORDINAL) { |
| 16 | // it would be ideal to filter to a single row identity, but the PoerBI API currently does not let us do that. |
| 17 | // so, we will filter to data points that have the same values |
| 18 | const dataPoint = getDataPoint(<number>ex.value, data); |
| 19 | if (dataPoint) { |
| 20 | filterSimilar(dataPoint, columns, filters); |
| 21 | // then we will select this data point |
| 22 | selectedIds.push(dataPoint[SandDance.constants.FieldNames.PowerBISelectionId]); |
| 23 | } |
| 24 | } else { |
| 25 | const column = columns.filter(c => c.displayName === ex.name)[0]; |
| 26 | if (column) { |
| 27 | const advancedFilter = convertExpressionToAdvancedFilter(ex, column); |
| 28 | if (advancedFilter) { |
| 29 | filters.push(advancedFilter.toJSON()); |
| 30 | } |
| 31 | } |
| 32 | } |
| 33 | }), |
| 34 | ); |
| 35 | return { filters, selectedIds }; |
| 36 | } |
| 37 | |
| 38 | function getDataPoint(GL_ORDINAL: number, data: object[]) { |
| 39 | for (let i = 0; i < data.length; i++) { |
no test coverage detected