Skip to content

Commit

Permalink
Use dimName instead of chartID for FilterStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
kum-deepak committed Mar 16, 2024
1 parent b8331d2 commit 6281be9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## 5.0.0-alpha2
* Change minimum chart size from 200x200to 25x25
* Change minimum chart size from 200x200to 25x25.
* Use dimName instead of chartID for FilterStorage.

## 5.0.0-alpha1
* Port to typescript.
Expand Down
12 changes: 6 additions & 6 deletions src/core/filter-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class FilterStorage implements IFilterStorage {
l.onFiltersChanged(filters);
});

const chartIds = listenerChain.map(lsnr => lsnr.chartId);
const chartIds = listenerChain.map(lsnr => lsnr.dimName);
this._filterChangeListener.call('filter-changed', this, {
chartIds,
filters: this._filters.get(storageKey),
Expand Down Expand Up @@ -108,7 +108,7 @@ export class FilterStorage implements IFilterStorage {
if (listener) {
const filters = this._filters.get(listener.storageKey);
if (filters && filters.length > 0) {
const entry = this._serializeFilters(listener.chartId, filters);
const entry = this._serializeFilters(listener.dimName, filters);
if (includeStorageKey) {
entry.storageKey = listener.storageKey;
}
Expand All @@ -127,7 +127,7 @@ export class FilterStorage implements IFilterStorage {
entries.map(entry => {
// Find a listenerChain that has same chartId registered
const listenerChain = listenerChains.find((lsnrsChain: IFilterListenerParams[]) =>
lsnrsChain.find(listener => listener.chartId === entry.chartId)
lsnrsChain.find(listener => listener.dimName === entry.dimName)
);

// convert to appropriate dc IFilter objects
Expand All @@ -150,18 +150,18 @@ export class FilterStorage implements IFilterStorage {
}
}

private _serializeFilters(chartId: string, filters: any[]): ISerializedFilters {
private _serializeFilters(dimName: string, filters: any[]): ISerializedFilters {
if (typeof filters[0].isFiltered !== 'function') {
return {
chartId,
dimName,
filterType: 'Simple',
values: [...filters], // defensively clone
};
}

const filtersWithType: IFilter[] = filters;
return {
chartId,
dimName,
filterType: filtersWithType[0].filterType,
values: filtersWithType.map(f => f.serialize()),
};
Expand Down
2 changes: 1 addition & 1 deletion src/core/i-filter-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ISerializedFilters } from './i-serialized-filters.js';
export interface IFilterListenerParams {
storageKey: any;
onFiltersChanged: (filters) => void;
chartId: string;
dimName: string;
primaryChart: boolean;
applyFilters: (filters) => void;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/i-serialized-filters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ISerializedFilters {
chartId: string;
dimName: string;
filterType: string;
values: any[];
storageKey?: any;
Expand Down
1 change: 1 addition & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface MinimalCFDimension {
// filterAll(): this; // unused
top(k: number): any[];
bottom(k: number): any[];
name?: string;
}

export interface CFGrouping {
Expand Down
12 changes: 11 additions & 1 deletion src/data/filter-storage-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IFilterStorage } from '../core/i-filter-storage.js';
export interface IFilterStorageConf extends ICFFilterHandlerConf {
readonly filterStorage?: IFilterStorage;
readonly chartId?: string;
readonly dimName?: string;
readonly primaryChart?: boolean;
readonly shareFilters?: boolean;
readonly onFiltersChanged?: (filters) => void;
Expand All @@ -27,10 +28,19 @@ export class FilterStorageHelper extends CFFilterHandler {

public configure(conf: IFilterStorageConf): this {
super.configure(conf);
if ('dimName' in conf) {
if (typeof this._conf.dimension === 'object') {
this._conf.dimension.name = conf.dimName;
}
}
this._ensureListenerRegistered();
return this;
}

get dimName(): string {
return this._conf.dimension?.name || this._conf.chartId;
}

private _ensureListenerRegistered() {
if (!this._conf.filterStorage) {
return;
Expand All @@ -53,7 +63,7 @@ export class FilterStorageHelper extends CFFilterHandler {
this._listenerRegToken = this._conf.filterStorage.registerFilterListener({
storageKey,
onFiltersChanged: this._conf.onFiltersChanged,
chartId: this._conf.chartId,
dimName: this.dimName,
primaryChart: this._conf.primaryChart,
applyFilters: filters => this.applyFilters(),
});
Expand Down

0 comments on commit 6281be9

Please sign in to comment.