MCPcopy Create free account
hub / github.com/microsoft/SandDance / convertFilter

Function convertFilter

packages/powerbi/src/convertFilter.ts:8–36  ·  view source on GitHub ↗
(searchFilter: SandDance.searchExpression.Search, columns: powerbiVisualsApi.DataViewMetadataColumn[], data: object[])

Source from the content-addressed store, hash-verified

6import { SandDance } from '@msrvida/sanddance-explorer';
7
8export 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
38function getDataPoint(GL_ORDINAL: number, data: object[]) {
39 for (let i = 0; i < data.length; i++) {

Callers 1

constructorMethod · 0.90

Calls 5

getDataPointFunction · 0.85
filterSimilarFunction · 0.85
forEachMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected