in packages/attribute-slicer-powerbi/src/AttributeSlicerVisual.ts [258:333]
private loadDataFromVisualUpdate(
isDataLoad: boolean,
dv: powerbiVisualsApi.DataView,
pbiState: AttributeSlicerVisualState,
) {
// Load data if the data has definitely changed, sometimes however it hasn't actually changed
// ie search for Microsof then Microsoft
if (dv) {
if (this.shouldLoadDataIntoSlicer(pbiState, isDataLoad)) {
const data = this.convertData(dv, pbiState);
log("Loading data from PBI");
this.data = data;
const filteredData = this.data.items.slice(0);
// If we are appending data for the attribute slicer
if (
this.loadDeferred &&
this.mySlicer.data &&
!this.loadDeferred.search
) {
// we only need to give it the new items
this.loadDeferred.resolve(
filteredData.slice(this.mySlicer.data.length),
);
delete this.loadDeferred;
// Recompute the rendered values, cause otherwise only half will have the updated values
// because the min/max of all the columns change when new data is added.
computeRenderedValues(<any>this.mySlicer.data);
this.mySlicer.refresh();
} else {
this.mySlicer.data = filteredData;
// Restore selection
this.mySlicer.selectedItems = (pbiState.selectedItems || []).slice(0); // Make a copy
delete this.loadDeferred;
}
const columnNames: string[] = [];
lodashForown(
lodashGet(dv, "categorical.categories"),
(value, key: any) => {
columnNames.push(value.source.queryName);
},
);
// Only clear selection IF
// We've already loaded a dataset, and the user has changed the dataset to something else
if (
this.currentCategory &&
!lodashIsequal(this.currentCategory, columnNames)
) {
// This will really be undefined behaviour for pbi-stateful
// because this indicates the user changed datasets
if (!lodashIsequal(pbiState.selectedItems, [])) {
log("Clearing Selection, Categories Changed");
pbiState.selectedItems = [];
this.onSelectionChanged([]);
}
if (pbiState.searchText !== "") {
log("Clearing Search, Categories Changed");
pbiState.searchText = "";
this.onSearchPerformed("");
}
}
this.currentCategory = columnNames;
}
} else {
this.mySlicer.data = [];
pbiState.selectedItems = [];
}
}