Skip to content

Commit

Permalink
[Lens][Visualize] Adds option to disable cursor sync on dashboards (#…
Browse files Browse the repository at this point in the history
…143355)

* [Lens][Visualize] Disable cursor sync on dashboard level option

* Increase XY limits as it fails for 1B :)

* Fix jest tests

* Apply PR nit
  • Loading branch information
stratoula authored Oct 17, 2022
1 parent 12acbac commit 46c1250
Show file tree
Hide file tree
Showing 55 changed files with 183 additions and 29 deletions.
2 changes: 2 additions & 0 deletions docs/user/dashboard/dashboard.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ Apply a set of design options to the entire dashboard.

* *Sync color pallettes across panels* — Applies the same color palette to all panels on the dashboard.

* *Sync cursor across panels* — When you hover your cursor over a *Lens*, *TSVB*, aggregation-based, or *Timelion* XY chart and a heatmap chart, the cursor on all other related dashboard charts automatically appear.

* *Sync tooltips across panels* — When you hover your cursor over a *Lens*, *TSVB*, aggregation-based, or *Timelion* XY chart, the tooltips on all other related dashboard charts automatically appear.

[float]
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pageLoadAssetSize:
expressions: 140958
expressionShape: 34008
expressionTagcloud: 27505
expressionXY: 38000
expressionXY: 38500
features: 21723
fieldFormats: 65209
files: 22673
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const heatmapFunction = (): HeatmapExpressionFunctionDefinition => ({
handlers.getExecutionContext?.()?.description,
},
syncTooltips: handlers?.isSyncTooltipsEnabled?.() ?? false,
syncCursor: handlers?.isSyncCursorEnabled?.() ?? true,
},
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export interface HeatmapExpressionProps {
data: Datatable;
args: HeatmapArguments;
syncTooltips: boolean;
syncCursor: boolean;
}

export interface HeatmapRender {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export type HeatmapRenderProps = HeatmapExpressionProps & {
uiState: PersistedState;
interactive: boolean;
syncTooltips: boolean;
syncCursor: boolean;
renderComplete: IInterpreterRenderHandlers['done'];
};
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe('HeatmapComponent', function () {
formatFactory: formatService.deserialize,
interactive: true,
syncTooltips: false,
syncCursor: true,
renderComplete: jest.fn(),
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
uiState,
interactive,
syncTooltips,
syncCursor,
renderComplete,
}) => {
const chartRef = useRef<Chart>(null);
Expand Down Expand Up @@ -576,7 +577,7 @@ export const HeatmapComponent: FC<HeatmapRenderProps> = memo(
noResults={
<EmptyPlaceholder icon={IconChartHeatmap} renderComplete={onRenderChange} />
}
onPointerUpdate={handleCursorUpdate}
onPointerUpdate={syncCursor ? handleCursorUpdate : undefined}
externalPointerEvents={{
tooltip: { visible: syncTooltips },
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const heatmapRenderer: (
interactive={isInteractive()}
chartsActiveCursorService={plugins.charts.activeCursor}
syncTooltips={config.syncTooltips}
syncCursor={config.syncCursor}
/>
</div>
</KibanaThemeProvider>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe('layeredXyVis', () => {
args: { ...rest, layers: [sampleExtendedLayer] },
syncColors: false,
syncTooltips: false,
syncCursor: true,
canNavigateToLens: false,
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const layeredXyVisFn: LayeredXyVisFn['fn'] = async (data, args, handlers)
canNavigateToLens: Boolean(handlers.variables.canNavigateToLens),
syncColors: handlers?.isSyncColorsEnabled?.() ?? false,
syncTooltips: handlers?.isSyncTooltipsEnabled?.() ?? false,
syncCursor: handlers?.isSyncCursorEnabled?.() ?? true,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('xyVis', () => {
canNavigateToLens: false,
syncColors: false,
syncTooltips: false,
syncCursor: true,
},
});
});
Expand Down Expand Up @@ -350,6 +351,7 @@ describe('xyVis', () => {
canNavigateToLens: false,
syncColors: false,
syncTooltips: false,
syncCursor: true,
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const xyVisFn: XyVisFn['fn'] = async (data, args, handlers) => {
canNavigateToLens: Boolean(handlers.variables.canNavigateToLens),
syncColors: handlers?.isSyncColorsEnabled?.() ?? false,
syncTooltips: handlers?.isSyncTooltipsEnabled?.() ?? false,
syncCursor: handlers?.isSyncCursorEnabled?.() ?? true,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { XYProps } from './expression_functions';
export interface XYChartProps {
args: XYProps;
syncTooltips: boolean;
syncCursor: boolean;
syncColors: boolean;
canNavigateToLens?: boolean;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ describe('XYChart component', () => {
onSelectRange,
syncColors: false,
syncTooltips: false,
syncCursor: true,
useLegacyTimeAxis: false,
eventAnnotationService: eventAnnotationServiceMock,
renderComplete: jest.fn(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export type XYChartRenderProps = Omit<XYChartProps, 'canNavigateToLens'> & {
renderMode: RenderMode;
syncColors: boolean;
syncTooltips: boolean;
syncCursor: boolean;
eventAnnotationService: EventAnnotationServiceType;
renderComplete: () => void;
uiState?: PersistedState;
Expand Down Expand Up @@ -199,6 +200,7 @@ export function XYChart({
interactive = true,
syncColors,
syncTooltips,
syncCursor,
useLegacyTimeAxis,
renderComplete,
uiState,
Expand Down Expand Up @@ -753,7 +755,7 @@ export function XYChart({
/>
}
onRenderChange={onRenderChange}
onPointerUpdate={handleCursorUpdate}
onPointerUpdate={syncCursor ? handleCursorUpdate : undefined}
externalPointerEvents={{
tooltip: { visible: syncTooltips, placement: Placement.Right },
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export const getXyChartRenderer = ({
renderMode={handlers.getRenderMode()}
syncColors={config.syncColors}
syncTooltips={config.syncTooltips}
syncCursor={config.syncCursor}
uiState={handlers.uiState as PersistedState}
renderComplete={renderComplete}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ describe('calculateMinInterval', () => {
beforeEach(() => {
const { layers, ...restArgs } = sampleArgs().args;

xyProps = { args: { ...restArgs, layers }, syncColors: false, syncTooltips: false };
xyProps = {
args: { ...restArgs, layers },
syncColors: false,
syncTooltips: false,
syncCursor: true,
};
layer = xyProps.args.layers[0] as DataLayerConfig;
layer.xScaleType = 'time';
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface InheritedChildInput extends IndexSignature {
id: string;
searchSessionId?: string;
syncColors?: boolean;
syncCursor?: boolean;
syncTooltips?: boolean;
executionContext?: KibanaExecutionContext;
}
Expand Down Expand Up @@ -351,6 +352,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
filters,
searchSessionId,
syncColors,
syncCursor,
syncTooltips,
executionContext,
} = this.input;
Expand All @@ -371,6 +373,7 @@ export class DashboardContainer extends Container<InheritedChildInput, Dashboard
searchSessionId,
syncColors,
syncTooltips,
syncCursor,
executionContext,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class DashboardContainerFactoryDefinition
isFullScreenMode: false,
useMargins: true,
syncColors: true,
syncCursor: true,
syncTooltips: true,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const getDashboardState = (state?: Partial<DashboardState>): DashboardState => {
useMargins: true,
syncColors: false,
syncTooltips: false,
syncCursor: true,
},
panels: {
panel_1: {
Expand Down Expand Up @@ -99,6 +100,7 @@ describe('Dashboard state diff function', () => {
useMargins: false,
syncColors: false,
syncTooltips: false,
syncCursor: true,
},
})
).toEqual(['options']);
Expand All @@ -111,6 +113,7 @@ describe('Dashboard state diff function', () => {
useMargins: true,
syncColors: undefined,
syncTooltips: undefined,
syncCursor: true,
} as unknown as DashboardOptions,
})
).toEqual([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export const dashboardStateSlice = createSlice({
setSyncColors: (state, action: PayloadAction<boolean>) => {
state.options.syncColors = action.payload;
},
setSyncCursor: (state, action: PayloadAction<boolean>) => {
state.options.syncCursor = action.payload;
},
setSyncTooltips: (state, action: PayloadAction<boolean>) => {
state.options.syncTooltips = action.payload;
},
Expand Down Expand Up @@ -128,6 +131,7 @@ export const {
setTimeRange,
setSyncColors,
setSyncTooltips,
setSyncCursor,
setUseMargins,
setViewMode,
setFilters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
setStateFromSaveModal,
setSyncColors,
setSyncTooltips,
setSyncCursor,
setUseMargins,
setViewMode,
useDashboardDispatch,
Expand Down Expand Up @@ -402,6 +403,10 @@ export function DashboardTopNav({
onSyncColorsChange: (isChecked: boolean) => {
dispatchDashboardStateChange(setSyncColors(isChecked));
},
syncCursor: currentState.options.syncCursor ?? true,
onSyncCursorChange: (isChecked: boolean) => {
dispatchDashboardStateChange(setSyncCursor(isChecked));
},
syncTooltips: Boolean(currentState.options.syncTooltips),
onSyncTooltipsChange: (isChecked: boolean) => {
dispatchDashboardStateChange(setSyncTooltips(isChecked));
Expand Down
74 changes: 53 additions & 21 deletions src/plugins/dashboard/public/application/top_nav/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface Props {
onHidePanelTitlesChange: (hideTitles: boolean) => void;
syncColors: boolean;
onSyncColorsChange: (syncColors: boolean) => void;
syncCursor: boolean;
onSyncCursorChange: (syncCursor: boolean) => void;
syncTooltips: boolean;
onSyncTooltipsChange: (syncTooltips: boolean) => void;
}
Expand All @@ -26,6 +28,7 @@ interface State {
useMargins: boolean;
hidePanelTitles: boolean;
syncColors: boolean;
syncCursor: boolean;
syncTooltips: boolean;
}

Expand All @@ -34,6 +37,7 @@ export class OptionsMenu extends Component<Props, State> {
useMargins: this.props.useMargins,
hidePanelTitles: this.props.hidePanelTitles,
syncColors: this.props.syncColors,
syncCursor: this.props.syncCursor,
syncTooltips: this.props.syncTooltips,
};

Expand All @@ -59,6 +63,12 @@ export class OptionsMenu extends Component<Props, State> {
this.setState({ syncColors: isChecked });
};

handleSyncCursorChange = (evt: any) => {
const isChecked = evt.target.checked;
this.props.onSyncCursorChange(isChecked);
this.setState({ syncCursor: isChecked });
};

handleSyncTooltipsChange = (evt: any) => {
const isChecked = evt.target.checked;
this.props.onSyncTooltipsChange(isChecked);
Expand Down Expand Up @@ -89,27 +99,49 @@ export class OptionsMenu extends Component<Props, State> {
data-test-subj="dashboardPanelTitlesCheckbox"
/>
</EuiFormRow>

<EuiFormRow>
<EuiSwitch
label={i18n.translate('dashboard.topNav.options.syncColorsBetweenPanelsSwitchLabel', {
defaultMessage: 'Sync color palettes across panels',
})}
checked={this.state.syncColors}
onChange={this.handleSyncColorsChange}
data-test-subj="dashboardSyncColorsCheckbox"
/>
</EuiFormRow>

<EuiFormRow>
<EuiSwitch
label={i18n.translate('dashboard.topNav.options.syncTooltipsBetweenPanelsSwitchLabel', {
defaultMessage: 'Sync tooltips across panels',
})}
checked={this.state.syncTooltips}
onChange={this.handleSyncTooltipsChange}
data-test-subj="dashboardSyncTooltipsCheckbox"
/>
<EuiFormRow label="Sync across panels">
<>
<EuiFormRow>
<EuiSwitch
label={i18n.translate(
'dashboard.topNav.options.syncColorsBetweenPanelsSwitchLabel',
{
defaultMessage: 'Sync color palettes across panels',
}
)}
checked={this.state.syncColors}
onChange={this.handleSyncColorsChange}
data-test-subj="dashboardSyncColorsCheckbox"
/>
</EuiFormRow>
<EuiFormRow>
<EuiSwitch
label={i18n.translate(
'dashboard.topNav.options.syncCursorBetweenPanelsSwitchLabel',
{
defaultMessage: 'Sync cursor across panels',
}
)}
checked={this.state.syncCursor}
onChange={this.handleSyncCursorChange}
data-test-subj="dashboardSyncCursorCheckbox"
/>
</EuiFormRow>
<EuiFormRow>
<EuiSwitch
label={i18n.translate(
'dashboard.topNav.options.syncTooltipsBetweenPanelsSwitchLabel',
{
defaultMessage: 'Sync tooltips across panels',
}
)}
checked={this.state.syncTooltips}
disabled={!Boolean(this.state.syncCursor)}
onChange={this.handleSyncTooltipsChange}
data-test-subj="dashboardSyncTooltipsCheckbox"
/>
</EuiFormRow>
</>
</EuiFormRow>
</EuiForm>
);
Expand Down
Loading

0 comments on commit 46c1250

Please sign in to comment.