Skip to content

Commit

Permalink
split toolbarActions and toolbarDialogAddons config
Browse files Browse the repository at this point in the history
  • Loading branch information
sgratzl committed Mar 27, 2020
1 parent 38172cf commit d80cb77
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/builder/LineUpBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {IToolbarAction, IToolbarDialogAddon} from '../ui';
export default class LineUpBuilder {
protected readonly options: Partial<ITaggleOptions> = {
renderers: {},
toolbar: {},
toolbarActions: {},
toolbarDialogAddons: {},
flags: {}
};

Expand Down Expand Up @@ -121,7 +122,7 @@ export default class LineUpBuilder {
* @param action
*/
registerToolbarAction(id: string, action: IToolbarAction) {
this.options.toolbar![id] = action;
this.options.toolbarActions![id] = action;
return this;
}

Expand All @@ -131,7 +132,7 @@ export default class LineUpBuilder {
* @param addon addon description
*/
registerToolbarDialogAddon(id: string, addon: IToolbarDialogAddon) {
this.options.toolbar![id] = addon;
this.options.toolbarDialogAddons![id] = addon;
return this;
}

Expand Down
2 changes: 1 addition & 1 deletion src/builder/adapter/lineup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {equal, isSame, pick} from './utils';


const providerOptions: (keyof IDataProviderOptions | keyof ILocalDataProviderOptions)[] = ['singleSelection', 'filterGlobally', 'columnTypes', 'taskExecutor', 'jumpToSearchResult'];
const lineupOptions: (keyof IBuilderAdapterProps)[] = ['animated', 'sidePanel', 'sidePanelCollapsed', 'hierarchyIndicator', 'defaultSlopeGraphMode', 'summaryHeader', 'expandLineOnHover', 'overviewMode', 'renderers', 'canRender', 'toolbar', 'rowHeight', 'rowPadding', 'groupHeight', 'groupPadding', 'dynamicHeight', 'labelRotation', 'ignoreUnsupportedBrowser'];
const lineupOptions: (keyof IBuilderAdapterProps)[] = ['animated', 'sidePanel', 'sidePanelCollapsed', 'hierarchyIndicator', 'defaultSlopeGraphMode', 'summaryHeader', 'expandLineOnHover', 'overviewMode', 'renderers', 'canRender', 'toolbarActions', 'toolbarDialogAddons', 'rowHeight', 'rowPadding', 'groupHeight', 'groupPadding', 'dynamicHeight', 'labelRotation', 'ignoreUnsupportedBrowser'];

interface IRankingContext {
builders: IBuilderAdapterRankingProps[];
Expand Down
24 changes: 13 additions & 11 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {renderers} from './renderer/renderers';
import {toolbarActions} from './ui/toolbar';
import {toolbarActions, toolbarDialogAddons} from './ui/toolbar';
import {Column, Ranking, IGroupData, IGroupItem} from './model';
import {IDataProvider} from './provider';
import {ICellRendererFactory, ERenderMode} from './renderer';
Expand Down Expand Up @@ -52,8 +52,8 @@ export interface ILineUpFlags {
advancedUIFeatures: boolean;
}

export interface IToolbarLookup {
[key: string]: IToolbarAction | IToolbarDialogAddon;
export interface IToolbarLookup<T> {
[key: string]: T;
}

export interface ILineUpOptions {
Expand Down Expand Up @@ -144,16 +144,17 @@ export interface ILineUpOptions {
/**
* register custom toolbar actions and dialog addons
*/
toolbar: IToolbarLookup;
toolbarActions: IToolbarLookup<IToolbarAction>;
toolbarDialogAddons: IToolbarLookup<IToolbarDialogAddon>;

/**
* hook for postprocess the toolbar actions for a column
*/
resolveToolbarActions: (col: Column, keys: string[], lookup: IToolbarLookup) => IToolbarAction[];
resolveToolbarActions: (col: Column, keys: string[], lookup: IToolbarLookup<IToolbarAction>) => IToolbarAction[];
/**
* hook for postprocess the toolbar dialog addons for a column
*/
resolveToolbarDialogAddons: (col: Column, keys: string[], lookup: IToolbarLookup) => IToolbarDialogAddon[];
resolveToolbarDialogAddons: (col: Column, keys: string[], lookup: IToolbarLookup<IToolbarDialogAddon>) => IToolbarDialogAddon[];

/**
* register custom renderer factories
Expand Down Expand Up @@ -194,25 +195,25 @@ export interface ILineUpLike {
destroy(): void;
}

function resolveToolbarActions(col: Column, keys: string[], lookup: IToolbarLookup) {
function resolveToolbarActions(col: Column, keys: string[], lookup: IToolbarLookup<IToolbarAction>) {
const actions: IToolbarAction[] = [];

keys.forEach((key) => {
if (lookup.hasOwnProperty(key)) {
actions.push(<IToolbarAction>lookup[key]);
actions.push(lookup[key]);
} else {
console.warn(`cannot find toolbar action of type: "${col.desc.type}" with key "${key}"`);
}
});
return actions;
}

function resolveToolbarDialogAddons(col: Column, keys: string[], lookup: IToolbarLookup) {
function resolveToolbarDialogAddons(col: Column, keys: string[], lookup: IToolbarLookup<IToolbarDialogAddon>) {
const actions: IToolbarDialogAddon[] = [];

keys.forEach((key) => {
if (lookup.hasOwnProperty(key)) {
actions.push(<IToolbarDialogAddon>lookup[key]);
actions.push(lookup[key]);
} else {
console.warn(`cannot find toolbar dialog addon of type: "${col.desc.type}" with key "${key}"`);
}
Expand All @@ -223,7 +224,8 @@ function resolveToolbarDialogAddons(col: Column, keys: string[], lookup: IToolba

export function defaultOptions(): ITaggleOptions {
return {
toolbar: Object.assign({}, toolbarActions),
toolbarActions,
toolbarDialogAddons,
resolveToolbarActions,
resolveToolbarDialogAddons,
renderers: Object.assign({}, renderers),
Expand Down
4 changes: 2 additions & 2 deletions src/ui/EngineRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ export default class EngineRenderer extends AEventDispatcher {
provider: data,
tasks: data.getTaskExecutor(),
dialogManager,
resolveToolbarActions: (col, keys) => this.options.resolveToolbarActions(col, keys, this.options.toolbar),
resolveToolbarDialogAddons: (col, keys) => this.options.resolveToolbarDialogAddons(col, keys, this.options.toolbar),
resolveToolbarActions: (col, keys) => this.options.resolveToolbarActions(col, keys, this.options.toolbarActions),
resolveToolbarDialogAddons: (col, keys) => this.options.resolveToolbarDialogAddons(col, keys, this.options.toolbarDialogAddons),
flags: <ILineUpFlags>this.options.flags,
asElement: domElementCache(parent.ownerDocument!),
renderer: (col: Column, imposer?: IImposer) => {
Expand Down
10 changes: 5 additions & 5 deletions src/ui/toolbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ function toggleCompressExpand(col: Column, evt: MouseEvent, ctx: IRankingHeaderC
}
}

const compress = {
const compress: IToolbarAction = {
title: 'Compress',
enabled: (col: IMultiLevelColumn) => !col.getCollapsed(),
onClick: toggleCompressExpand,
options: {featureCategory: 'model', featureLevel: 'advanced'}
};

const expand = {
const expand: IToolbarAction = {
title: 'Expand',
enabled: (col: IMultiLevelColumn) => col.getCollapsed(),
onClick: toggleCompressExpand,
Expand All @@ -241,7 +241,7 @@ const setShowTopN: IToolbarAction = {
}
};

const toolbarAddons: {[key: string]: IToolbarDialogAddon} = {
export const toolbarDialogAddons: {[key: string]: IToolbarDialogAddon} = {
sortNumber: uiSortMethod(Object.keys(EAdvancedSortMethod)),
sortNumbers: uiSortMethod(Object.keys(EAdvancedSortMethod)),
sortBoxPlot: uiSortMethod(Object.keys(ESortMethod)),
Expand All @@ -264,7 +264,7 @@ const toolbarAddons: {[key: string]: IToolbarDialogAddon} = {
},
};

export const toolbarActions: {[key: string]: IToolbarAction | IToolbarDialogAddon} = Object.assign({
export const toolbarActions: {[key: string]: IToolbarAction} = {
vis,
group,
groupBy,
Expand Down Expand Up @@ -311,7 +311,7 @@ export const toolbarActions: {[key: string]: IToolbarAction | IToolbarDialogAddo
const others = order.filter((d) => !ss.has(d));
ctx.provider.setSelection(others);
}, {featureCategory: 'model', featureLevel: 'advanced'})
}, toolbarAddons);
};

function sortActions(a: IToolbarAction, b: IToolbarAction) {
if (a.options.order === b.options.order) {
Expand Down

0 comments on commit d80cb77

Please sign in to comment.