Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const getMaxValue = (
if (isRespectRanges && paletteParams?.rangeMax) {
const metricValue = accessors?.metric ? getValueFromAccessor(accessors.metric, row) : undefined;
return !metricValue || metricValue < paletteParams?.rangeMax
? paletteParams?.rangeMax
? paletteParams.rangeMax
: metricValue;
}

Expand All @@ -93,16 +93,16 @@ export const getMinValue = (
accessors?: Accessors,
paletteParams?: CustomPaletteParams,
isRespectRanges?: boolean
) => {
): number => {
const currentValue = accessors?.min ? getValueFromAccessor(accessors.min, row) : undefined;
if (currentValue !== undefined && currentValue !== null) {
if (currentValue != null) {
return currentValue;
}

if (isRespectRanges && paletteParams?.rangeMin) {
const metricValue = accessors?.metric ? getValueFromAccessor(accessors.metric, row) : undefined;
return !metricValue || metricValue > paletteParams?.rangeMin
? paletteParams?.rangeMin
? paletteParams.rangeMin
: metricValue;
}

Expand All @@ -121,7 +121,7 @@ export const getMinValue = (

export const getGoalValue = (row?: DatatableRow, accessors?: Accessors) => {
const currentValue = accessors?.goal ? getValueFromAccessor(accessors.goal, row) : undefined;
if (currentValue !== undefined && currentValue !== null) {
if (currentValue != null) {
return currentValue;
}

Expand Down
37 changes: 13 additions & 24 deletions x-pack/plugins/lens/public/datasources/form_based/info_badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* 2.0.
*/

import { EuiFlexGroup, EuiFlexItem, EuiText, useEuiTheme } from '@elastic/eui';
import { css } from '@emotion/react';
import { EuiText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { FormBasedLayer } from '../..';
import { InfoBadge } from '../../shared_components/info_badges/info_badge';
import { FramePublicAPI, VisualizationInfo } from '../../types';
import { getSamplingValue } from './utils';

Expand All @@ -22,38 +22,27 @@ export function ReducedSamplingSectionEntries({
visualizationInfo: VisualizationInfo;
dataViews: FramePublicAPI['dataViews'];
}) {
const { euiTheme } = useEuiTheme();
return (
<>
{layers.map(([id, layer], layerIndex) => {
const dataView = dataViews.indexPatterns[layer.indexPatternId];
const layerInfo = visualizationInfo.layers.find(({ layerId, label }) => layerId === id);
const layerTitle =
visualizationInfo.layers.find(({ layerId }) => layerId === id)?.label ||
layerInfo?.label ||
i18n.translate('xpack.lens.indexPattern.samplingPerLayer.fallbackLayerName', {
defaultMessage: 'Data layer',
});
const layerPalette = layerInfo?.palette;
return (
<li
key={`${layerTitle}-${dataView}-${layerIndex}`}
data-test-subj={`lns-feature-badges-reducedSampling-${layerIndex}`}
css={css`
margin: ${euiTheme.size.base} 0 0;
`}
<InfoBadge
title={layerTitle}
index={layerIndex}
dataView={dataView.id}
palette={layerPalette}
data-test-subj-prefix="lns-feature-badges-reducedSampling"
>
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiText size="s">{layerTitle}</EuiText>
</EuiFlexItem>
<EuiFlexItem
grow={false}
css={css`
padding-right: 0;
`}
>
<EuiText size="s">{`${Number(getSamplingValue(layer)) * 100}%`}</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</li>
<EuiText size="s">{`${Number(getSamplingValue(layer)) * 100}%`}</EuiText>
</InfoBadge>
);
})}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ import { LANGUAGE_ID } from './math_tokenization';
import './formula.scss';
import { FormulaIndexPatternColumn } from '../formula';
import { insertOrReplaceFormulaColumn } from '../parse';
import { filterByVisibleOperation, nonNullable } from '../util';
import { filterByVisibleOperation } from '../util';
import { getColumnTimeShiftWarnings, getDateHistogramInterval } from '../../../../time_shift_utils';
import { getDocumentationSections } from './formula_help';
import { nonNullable } from '../../../../../../utils';

function tableHasData(
activeData: ParamEditorProps<FormulaIndexPatternColumn>['activeData'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import type {
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
import { parseTimeShift } from '@kbn/data-plugin/common';
import moment from 'moment';
import { nonNullable } from '../../../../../../utils';
import { DateRange } from '../../../../../../../common/types';
import type { IndexPattern } from '../../../../../../types';
import { memoizedGetAvailableOperationsByMetadata } from '../../../operations';
import { tinymathFunctions, groupArgsByType, unquotedStringRegex, nonNullable } from '../util';
import { tinymathFunctions, groupArgsByType, unquotedStringRegex } from '../util';
import type { GenericOperationDefinition } from '../..';
import { getFunctionSignatureLabel, getHelpTextContent } from './formula_help';
import { hasFunctionFieldArgument } from '../validation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { i18n } from '@kbn/i18n';
import { uniqBy } from 'lodash';
import { nonNullable } from '../../../../../utils';
import type {
BaseIndexPatternColumn,
FieldBasedOperationErrorMessage,
Expand All @@ -18,7 +19,7 @@ import { runASTValidation, tryToParse } from './validation';
import { WrappedFormulaEditor } from './editor';
import { insertOrReplaceFormulaColumn } from './parse';
import { generateFormula } from './generate';
import { filterByVisibleOperation, nonNullable } from './util';
import { filterByVisibleOperation } from './util';
import { getManagedColumnsFrom } from '../../layer_helpers';
import { generateMissingFieldMessage, getFilter, isColumnFormatted } from '../helpers';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { i18n } from '@kbn/i18n';
import { isObject } from 'lodash';
import type { TinymathAST, TinymathVariable, TinymathLocation } from '@kbn/tinymath';
import { nonNullable } from '../../../../../utils';
import type { DateRange } from '../../../../../../common/types';
import type { IndexPattern } from '../../../../../types';
import {
Expand All @@ -26,7 +27,6 @@ import {
getOperationParams,
groupArgsByType,
mergeWithGlobalFilters,
nonNullable,
} from './util';
import { FormulaIndexPatternColumn, isFormulaIndexPatternColumn } from './formula';
import { getColumnOrder } from '../../layer_helpers';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
TinymathVariable,
} from '@kbn/tinymath';
import type { Query } from '@kbn/es-query';
import { nonNullable } from '../../../../../utils';
import type {
OperationDefinition,
GenericIndexPatternColumn,
Expand Down Expand Up @@ -736,10 +737,6 @@ Example: Average revenue per customer but in some cases customer id is not provi
},
};

export function nonNullable<T>(v: T): v is NonNullable<T> {
return v != null;
}

export function isMathNode(node: TinymathAST | string) {
return isObject(node) && node.type === 'function' && tinymathFunctions[node.name];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
REASON_ID_TYPES,
validateAbsoluteTimeShift,
} from '@kbn/data-plugin/common';
import { nonNullable } from '../../../../../utils';
import { DateRange } from '../../../../../../common/types';
import {
findMathNodes,
Expand All @@ -27,7 +28,6 @@ import {
getValueOrName,
groupArgsByType,
isMathNode,
nonNullable,
tinymathFunctions,
} from './util';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@

import { IUiSettingsClient, SavedObjectReference } from '@kbn/core/public';
import { Ast } from '@kbn/interpreter';
import memoizeOne from 'memoize-one';
import { VisualizeFieldContext } from '@kbn/ui-actions-plugin/public';
import { difference } from 'lodash';
import type { DataViewsContract, DataViewSpec } from '@kbn/data-views-plugin/public';
import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public';
import { DataViewPersistableStateService } from '@kbn/data-views-plugin/common';
import type { TimefilterContract } from '@kbn/data-plugin/public';
import {
import type {
Datasource,
DatasourceLayers,
DatasourceMap,
IndexPattern,
IndexPatternMap,
Expand All @@ -28,9 +26,10 @@ import {
import { buildExpression } from './expression_helpers';
import { Document } from '../../persistence/saved_object_store';
import { getActiveDatasourceIdFromDoc, sortDataViewRefs } from '../../utils';
import type { DatasourceStates, DataViewsState, VisualizationState } from '../../state_management';
import type { DatasourceStates, VisualizationState } from '../../state_management';
import { readFromStorage } from '../../settings_storage';
import { loadIndexPatternRefs, loadIndexPatterns } from '../../data_views_service/loader';
import { getDatasourceLayers } from '../../state_management/utils';

function getIndexPatterns(
references?: SavedObjectReference[],
Expand Down Expand Up @@ -283,30 +282,6 @@ export function initializeDatasources({
return states;
}

export const getDatasourceLayers = memoizeOne(function getDatasourceLayers(
datasourceStates: DatasourceStates,
datasourceMap: DatasourceMap,
indexPatterns: DataViewsState['indexPatterns']
) {
const datasourceLayers: DatasourceLayers = {};
Object.keys(datasourceMap)
.filter((id) => datasourceStates[id] && !datasourceStates[id].isLoading)
.forEach((id) => {
const datasourceState = datasourceStates[id].state;
const datasource = datasourceMap[id];

const layers = datasource.getLayers(datasourceState);
layers.forEach((layer) => {
datasourceLayers[layer] = datasourceMap[id].getPublicAPI({
state: datasourceState,
layerId: layer,
indexPatterns,
});
});
});
return datasourceLayers;
});

export async function persistedStateToExpression(
datasourceMap: DatasourceMap,
visualizations: VisualizationMap,
Expand Down
24 changes: 21 additions & 3 deletions x-pack/plugins/lens/public/embeddable/embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ import {
} from '../app_plugin/get_application_user_messages';
import { MessageList } from '../editor_frame_service/editor_frame/workspace_panel/message_list';
import { EmbeddableFeatureBadge } from './embeddable_info_badges';
import { getDatasourceLayers } from '../state_management/utils';

export type LensSavedObjectAttributes = Omit<Document, 'savedObjectId' | 'type'>;

Expand Down Expand Up @@ -610,7 +611,7 @@ export class Embeddable
visualizationMap: this.deps.visualizationMap,
activeDatasource: this.activeDatasource,
activeDatasourceState: {
isLoading: Boolean(this.activeDatasourceState),
isLoading: !this.activeDatasourceState,
state: this.activeDatasourceState,
},
dataViews: {
Expand All @@ -631,7 +632,16 @@ export class Embeddable
indexPatterns: this.indexPatterns,
indexPatternRefs: this.indexPatternRefs,
},
datasourceLayers: {}, // TODO
datasourceLayers: getDatasourceLayers(
{
[this.activeDatasourceId!]: {
isLoading: !this.activeDatasourceState,
state: this.activeDatasourceState,
},
},
this.deps.datasourceMap,
this.indexPatterns
),
query: this.savedVis.state.query,
filters: mergedSearchContext.filters ?? [],
dateRange: {
Expand All @@ -646,7 +656,8 @@ export class Embeddable
setState: () => {},
frame: frameDatasourceAPI,
visualizationInfo: this.activeVisualization?.getVisualizationInfo?.(
this.activeVisualizationState
this.activeVisualizationState,
frameDatasourceAPI
),
}) ?? []),
...(this.activeVisualization?.getUserMessages?.(this.activeVisualizationState, {
Expand Down Expand Up @@ -802,6 +813,13 @@ export class Embeddable
);

this.activeData = newActiveData;

// Refresh messanges if info type is found as with active data
// these messages can be enriched
if (this._userMessages.some(({ severity }) => severity === 'info')) {
this.loadUserMessages();
this.renderUserMessages();
}
};

private onRender: ExpressionWrapperProps['onRender$'] = () => {
Expand Down
41 changes: 24 additions & 17 deletions x-pack/plugins/lens/public/embeddable/embeddable_info_badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const EmbeddableFeatureBadge = ({ messages }: { messages: UserMessage[] }
title={iconTitle}
size="s"
css={css`
color: ${euiTheme.colors.emptyShade};
color: transparent;
font-size: ${xsFontSize};
height: ${euiTheme.size.l} !important;
.euiButtonEmpty__content {
Expand All @@ -68,22 +68,29 @@ export const EmbeddableFeatureBadge = ({ messages }: { messages: UserMessage[] }
isOpen={isPopoverOpen}
closePopover={closePopover}
>
<div>
{messages.map(({ shortMessage, longMessage }, index) => (
<aside
key={`${shortMessage}-${index}`}
css={css`
padding: ${index > 0 ? 0 : euiTheme.size.base} ${euiTheme.size.base}
${index > 0 ? euiTheme.size.s : 0};
`}
>
{index ? <EuiHorizontalRule margin="s" /> : null}
<EuiTitle size="xxs" css={css`color=${euiTheme.colors.title}`}>
<h3>{shortMessage}</h3>
</EuiTitle>
<ul className="lnsEmbeddablePanelFeatureList">{longMessage}</ul>
</aside>
))}
<div
css={css`
max-width: 280px;
`}
>
{messages.map(({ shortMessage, longMessage }, index) => {
return (
<>
{index ? <EuiHorizontalRule margin="none" /> : null}
<aside
key={`${shortMessage}-${index}`}
css={css`
padding: ${euiTheme.size.base};
`}
>
<EuiTitle size="xxs" css={css`color=${euiTheme.colors.title}`}>
<h3>{shortMessage}</h3>
</EuiTitle>
<ul className="lnsEmbeddablePanelFeatureList">{longMessage}</ul>
</aside>
</>
);
})}
</div>
</EuiPopover>
);
Expand Down
Loading