Skip to content

Commit

Permalink
Merge branch 'main' into kbn-107678-fail-start-on-unknown-so-types
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Nov 12, 2021
2 parents 112e95a + 64e0aaf commit ad4a3ff
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
6 changes: 0 additions & 6 deletions src/plugins/telemetry/server/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
SavedObjectsClientContract,
SavedObjectsClient,
CoreStart,
ICustomClusterClient,
} from '../../../core/server';
import {
getTelemetryChannelEndpoint,
Expand Down Expand Up @@ -53,7 +52,6 @@ export class FetcherTask {
private isSending = false;
private internalRepository?: SavedObjectsClientContract;
private telemetryCollectionManager?: TelemetryCollectionManagerPluginStart;
private elasticsearchClient?: ICustomClusterClient;

constructor(initializerContext: PluginInitializerContext<TelemetryConfigType>) {
this.config$ = initializerContext.config.create();
Expand All @@ -67,7 +65,6 @@ export class FetcherTask {
) {
this.internalRepository = new SavedObjectsClient(savedObjects.createInternalRepository());
this.telemetryCollectionManager = telemetryCollectionManager;
this.elasticsearchClient = elasticsearch.createClient('telemetry-fetcher');

this.intervalId = timer(this.initialCheckDelayMs, this.checkIntervalMs).subscribe(() =>
this.sendIfDue()
Expand All @@ -78,9 +75,6 @@ export class FetcherTask {
if (this.intervalId) {
this.intervalId.unsubscribe();
}
if (this.elasticsearchClient) {
this.elasticsearchClient.close();
}
}

private async areAllCollectorsReady() {
Expand Down
5 changes: 5 additions & 0 deletions x-pack/plugins/lens/common/expressions/datatable/datatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface DatatableArgs {
columns: ColumnConfigArg[];
sortingColumnId: SortingState['columnId'];
sortingDirection: SortingState['direction'];
fitRowToContent?: boolean;
}

export const getDatatable = (
Expand Down Expand Up @@ -57,6 +58,10 @@ export const getDatatable = (
types: ['string'],
help: '',
},
fitRowToContent: {
types: ['boolean'],
help: '',
},
},
async fn(...args) {
/** Build optimization: prevent adding extra code into initial bundle **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useContext, useEffect } from 'react';
import { EuiDataGridCellValueElementProps } from '@elastic/eui';
import { IUiSettingsClient } from 'kibana/public';
import classNames from 'classnames';
import type { FormatFactory } from '../../../common';
import { getOriginalId } from '../../../common/expressions';
import type { ColumnConfig } from '../../../common/expressions';
Expand All @@ -18,7 +19,8 @@ export const createGridCell = (
formatters: Record<string, ReturnType<FormatFactory>>,
columnConfig: ColumnConfig,
DataContext: React.Context<DataContextType>,
uiSettings: IUiSettingsClient
uiSettings: IUiSettingsClient,
fitRowToContent?: boolean
) => {
// Changing theme requires a full reload of the page, so we can cache here
const IS_DARK_THEME = uiSettings.get('theme:darkMode');
Expand All @@ -28,6 +30,9 @@ export const createGridCell = (
const content = formatters[columnId]?.convert(rowValue, 'html');
const currentAlignment = alignments && alignments[columnId];
const alignmentClassName = `lnsTableCell--${currentAlignment}`;
const className = classNames(alignmentClassName, {
lnsTableCell: !fitRowToContent,
});

const { colorMode, palette } =
columnConfig.columns.find(({ columnId: id }) => id === columnId) || {};
Expand Down Expand Up @@ -75,7 +80,7 @@ export const createGridCell = (
*/
dangerouslySetInnerHTML={{ __html: content }} // eslint-disable-line react/no-danger
data-test-subj="lnsTableCellContent"
className={`lnsTableCell ${alignmentClassName}`}
className={className}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,15 @@ export const DatatableComponent = (props: DatatableRenderProps) => {
}, [firstTableRef, onRowContextMenuClick, columnConfig, hasAtLeastOneRowClickAction]);

const renderCellValue = useMemo(
() => createGridCell(formatters, columnConfig, DataContext, props.uiSettings),
[formatters, columnConfig, props.uiSettings]
() =>
createGridCell(
formatters,
columnConfig,
DataContext,
props.uiSettings,
props.args.fitRowToContent
),
[formatters, columnConfig, props.uiSettings, props.args.fitRowToContent]
);

const columnVisibility = useMemo(
Expand Down Expand Up @@ -349,6 +356,13 @@ export const DatatableComponent = (props: DatatableRenderProps) => {
<EuiDataGrid
aria-label={dataGridAriaLabel}
data-test-subj="lnsDataTable"
rowHeightsOptions={
props.args.fitRowToContent
? {
defaultHeight: 'auto',
}
: undefined
}
columns={columns}
columnVisibility={columnVisibility}
trailingControlColumns={trailingControlColumns}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFlexGroup, EuiFormRow, EuiSwitch } from '@elastic/eui';
import { ToolbarPopover } from '../../shared_components';
import type { VisualizationToolbarProps } from '../../types';
import type { DatatableVisualizationState } from '../visualization';

export function DataTableToolbar(props: VisualizationToolbarProps<DatatableVisualizationState>) {
const { state, setState } = props;

const onChange = useCallback(() => {
const current = state.fitRowToContent ?? false;
setState({
...state,
fitRowToContent: !current,
});
}, [setState, state]);

return (
<EuiFlexGroup gutterSize="none" justifyContent="spaceBetween" responsive={false}>
<ToolbarPopover
title={i18n.translate('xpack.lens.table.valuesVisualOptions', {
defaultMessage: 'Visual options',
})}
type="visualOptions"
groupPosition="none"
buttonDataTestSubj="lnsVisualOptionsButton"
>
<EuiFormRow
label={i18n.translate('xpack.lens.table.visualOptionsFitRowToContentLabel', {
defaultMessage: 'Fit row to content',
})}
display="columnCompressedSwitch"
>
<EuiSwitch
compressed
data-test-subj="lens-legend-auto-height-switch"
label=""
showLabel={false}
checked={Boolean(state.fitRowToContent)}
onChange={onChange}
/>
</EuiFormRow>
</ToolbarPopover>
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import { getStopsForFixedMode } from '../shared_components';
import { LayerType, layerTypes } from '../../common';
import { getDefaultSummaryLabel } from '../../common/expressions';
import type { ColumnState, SortingState } from '../../common/expressions';

import { DataTableToolbar } from './components/toolbar';
export interface DatatableVisualizationState {
columns: ColumnState[];
layerId: string;
layerType: LayerType;
sorting?: SortingState;
fitRowToContent?: boolean;
}

const visualizationLabel = i18n.translate('xpack.lens.datatable.label', {
Expand Down Expand Up @@ -389,6 +390,7 @@ export const getDatatableVisualization = ({
}),
sortingColumnId: [state.sorting?.columnId || ''],
sortingDirection: [state.sorting?.direction || 'none'],
fitRowToContent: [state.fitRowToContent ?? false],
},
},
],
Expand All @@ -399,6 +401,15 @@ export const getDatatableVisualization = ({
return undefined;
},

renderToolbar(domElement, props) {
render(
<I18nProvider>
<DataTableToolbar {...props} />
</I18nProvider>,
domElement
);
},

onEditAction(state, event) {
switch (event.data.action) {
case 'sort':
Expand Down

0 comments on commit ad4a3ff

Please sign in to comment.