Skip to content

Commit 97e2dc8

Browse files
[Lens] Extend Datasource props validation with VisualizationGroups (#82607)
* ✨ First pass with visualization validation + error messages * 🔥 Remove indexpattern error handling for now * 🏷️ Fix type issues * ✅ Add getErrorMessage test for data table * ✅ Add tests for pie and metric error messages * 🌐 Fix i18n checks issues * 🐛 Fix last issue * ✅ Add more tests for the XY visualization validation code * 👌 Included all feedback from first review * ✏️ Off by one message * 🌐 Fix i18n duplicate id * 🌐 Fix last i18n issue * 🐛 Fixed a hook reflow issue * ♻️+✅ Reworked validation flow + tests * 🏷️ Fix type issue * 🐛 Improved XY corner cases validation logic * 🐛 Fix empty datatable scenario * ✨ + ✅ Improved error messages for invalid datasources + tests * 🌐 Add missing i18n translation * 🏷️ Fix type issues * 🌐 Fix i18n issues * ✨ Filter out suggestions which fail to build * 🚚 Migrate datatable validation logic to the building phase, handling it as building state * 🏷️ Fix type issue * ✏️ Add comment for future enhancements * ✏️ Updated comment * :world_with_meridians: Refactor axis labels * 🌐 Reworked few validation messages * 🐛 Fix break down validation + percentage charts * ✅ Align tests with new validation logic * ♻️ Fix suggestion panel validation to match main panel * 🌐 Fix i18n issues * 🔧 Fix some refs for validation checks in suggestions * 🐛 Fix missing key prop in multiple errors scenario * 🐛 Fix swtich issue from XY to partition * 🌐 Fix i18n messages and aligned tests * 🐛 Fix suggestions switching bug * :refactor: Add more validation + refactored validation logic in a single place * ✏️ Add note about lint hooks disable rule * 🚨 Fix linting issue * 🏗️ Add infra API for datasource advanced validation * ✅ Align tests with new API * ✅ Fix type issues in tests * 👌 Early exists added * ✨ Add layers groups to the API * ✅ Fix some broken test after the validation change * 👌 Move to disctionary shape Co-authored-by: Kibana Machine <[email protected]>
1 parent 09aec4d commit 97e2dc8

File tree

7 files changed

+39
-7
lines changed

7 files changed

+39
-7
lines changed

x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_panel.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ export function LayerPanel(
451451
columnId: activeId,
452452
filterOperations: activeGroup.filterOperations,
453453
suggestedPriority: activeGroup?.suggestedPriority,
454+
dimensionGroups: groups,
454455
setState: (newState: unknown) => {
455456
props.updateAll(
456457
datasourceId,

x-pack/plugins/lens/public/editor_frame_service/editor_frame/editor_frame.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,8 @@ describe('editor_frame', () => {
601601
setDatasourceState(updatedState);
602602
});
603603

604-
expect(mockVisualization.getConfiguration).toHaveBeenCalledTimes(2);
604+
// validation requires to calls this getConfiguration API
605+
expect(mockVisualization.getConfiguration).toHaveBeenCalledTimes(6);
605606
expect(mockVisualization.getConfiguration).toHaveBeenLastCalledWith(
606607
expect.objectContaining({
607608
state: updatedState,
@@ -680,7 +681,8 @@ describe('editor_frame', () => {
680681
setDatasourceState({});
681682
});
682683

683-
expect(mockVisualization.getConfiguration).toHaveBeenCalledTimes(2);
684+
// validation requires to calls this getConfiguration API
685+
expect(mockVisualization.getConfiguration).toHaveBeenCalledTimes(6);
684686
expect(mockVisualization.getConfiguration).toHaveBeenLastCalledWith(
685687
expect.objectContaining({
686688
frame: expect.objectContaining({
@@ -1193,7 +1195,8 @@ describe('editor_frame', () => {
11931195
instance.find('[data-test-subj="lnsSuggestion"]').at(2).simulate('click');
11941196
});
11951197

1196-
expect(mockVisualization.getConfiguration).toHaveBeenCalledTimes(1);
1198+
// validation requires to calls this getConfiguration API
1199+
expect(mockVisualization.getConfiguration).toHaveBeenCalledTimes(4);
11971200
expect(mockVisualization.getConfiguration).toHaveBeenCalledWith(
11981201
expect.objectContaining({
11991202
state: suggestionVisState,

x-pack/plugins/lens/public/editor_frame_service/editor_frame/state_helpers.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
import { SavedObjectReference } from 'kibana/public';
88
import { Ast } from '@kbn/interpreter/common';
9-
import { Datasource, DatasourcePublicAPI, FramePublicAPI, Visualization } from '../../types';
9+
import {
10+
Datasource,
11+
DatasourcePublicAPI,
12+
FramePublicAPI,
13+
Visualization,
14+
VisualizationDimensionGroupConfig,
15+
} from '../../types';
1016
import { buildExpression } from './expression_helpers';
1117
import { Document } from '../../persistence/saved_object_store';
1218
import { VisualizeFieldContext } from '../../../../../../src/plugins/ui_actions/public';
@@ -104,8 +110,24 @@ export const validateDatasourceAndVisualization = (
104110
longMessage: string;
105111
}>
106112
| undefined => {
113+
const layersGroups =
114+
currentVisualizationState &&
115+
currentVisualization
116+
?.getLayerIds(currentVisualizationState)
117+
.reduce<Record<string, VisualizationDimensionGroupConfig[]>>((memo, layerId) => {
118+
const groups = currentVisualization?.getConfiguration({
119+
frame: frameAPI,
120+
layerId,
121+
state: currentVisualizationState,
122+
}).groups;
123+
if (groups) {
124+
memo[layerId] = groups;
125+
}
126+
return memo;
127+
}, {});
128+
107129
const datasourceValidationErrors = currentDatasourceState
108-
? currentDataSource?.getErrorMessages(currentDatasourceState)
130+
? currentDataSource?.getErrorMessages(currentDatasourceState, layersGroups)
109131
: undefined;
110132

111133
const visualizationValidationErrors = currentVisualizationState

x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
174174
} as unknown) as DataPublicPluginStart['fieldFormats'],
175175
} as unknown) as DataPublicPluginStart,
176176
core: {} as CoreSetup,
177+
dimensionGroups: [],
177178
};
178179

179180
jest.clearAllMocks();

x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/droppable.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
146146
} as unknown) as DataPublicPluginStart['fieldFormats'],
147147
} as unknown) as DataPublicPluginStart,
148148
core: {} as CoreSetup,
149+
dimensionGroups: [],
149150
};
150151

151152
jest.clearAllMocks();

x-pack/plugins/lens/public/indexpattern_datasource/indexpattern.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export function getIndexPatternDatasource({
343343
getDatasourceSuggestionsFromCurrentState,
344344
getDatasourceSuggestionsForVisualizeField,
345345

346-
getErrorMessages(state) {
346+
getErrorMessages(state, layersGroups) {
347347
if (!state) {
348348
return;
349349
}

x-pack/plugins/lens/public/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ export interface Datasource<T = unknown, P = unknown> {
184184
) => Array<DatasourceSuggestion<T>>;
185185

186186
getPublicAPI: (props: PublicAPIProps<T>) => DatasourcePublicAPI;
187-
getErrorMessages: (state: T) => Array<{ shortMessage: string; longMessage: string }> | undefined;
187+
getErrorMessages: (
188+
state: T,
189+
layersGroups?: Record<string, VisualizationDimensionGroupConfig[]>
190+
) => Array<{ shortMessage: string; longMessage: string }> | undefined;
188191
/**
189192
* uniqueLabels of dimensions exposed for aria-labels of dragged dimensions
190193
*/
@@ -242,6 +245,7 @@ export type DatasourceDimensionEditorProps<T = unknown> = DatasourceDimensionPro
242245
setState: StateSetter<T>;
243246
core: Pick<CoreSetup, 'http' | 'notifications' | 'uiSettings'>;
244247
dateRange: DateRange;
248+
dimensionGroups: VisualizationDimensionGroupConfig[];
245249
};
246250

247251
export type DatasourceDimensionTriggerProps<T> = DatasourceDimensionProps<T> & {

0 commit comments

Comments
 (0)