-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Lens] Improves error messages when in Dashboard #90668
Merged
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1f08396
:fire: Remove unused frame API from signature
dej611 c428ac9
:sparkles: Show Lens validation errors in dashboard
dej611 fa208ea
Merge branch 'master' into fix/86278
kibanamachine 6fa7501
:white_check_mark: Add functional test
dej611 c0c78e3
:lipstick: Integrate feedback
dej611 a4f0edf
:label: Narrow down the type to be used in embeddables
dej611 34ec35d
:label: Add palettes to the minimal set of frameAPI to load
dej611 a971da9
Merge branch 'master' into fix/86278
kibanamachine e901240
:fire: Remove the palettes service from the embeddable dependencies
dej611 32426a0
Merge branch 'fix/86278' of github.com:dej611/kibana into fix/86278
dej611 fd7e430
Revert ":label: Add palettes to the minimal set of frameAPI to load"
dej611 926052f
:label: Fix types after removal
dej611 18922cd
:lipstick: Refactor embeddable layout for errors
dej611 673fe2a
:lipstick: Show the more message only for multiple errors
dej611 a1aab98
:bug: Fix functional test
dej611 84e67e7
Merge branch 'master' into fix/86278
kibanamachine d140471
Merge branch 'master' into fix/86278
kibanamachine 2e84b4a
:ok_hand: Integrate feedback
dej611 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import { SavedObjectReference } from 'kibana/public'; | ||
import { Ast } from '@kbn/interpreter/common'; | ||
import { PaletteRegistry } from 'src/plugins/charts/public'; | ||
import { | ||
Datasource, | ||
DatasourcePublicAPI, | ||
|
@@ -18,6 +19,9 @@ import { | |
import { buildExpression } from './expression_helpers'; | ||
import { Document } from '../../persistence/saved_object_store'; | ||
import { VisualizeFieldContext } from '../../../../../../src/plugins/ui_actions/public'; | ||
import { getActiveDatasourceIdFromDoc } from './state_management'; | ||
import { ErrorMessage } from '../types'; | ||
import { getMissingCurrentDatasource, getMissingVisualizationTypeError } from '../error_helper'; | ||
|
||
export async function initializeDatasources( | ||
datasourceMap: Record<string, Datasource>, | ||
|
@@ -71,16 +75,22 @@ export function createDatasourceLayers( | |
export async function persistedStateToExpression( | ||
datasources: Record<string, Datasource>, | ||
visualizations: Record<string, Visualization>, | ||
doc: Document | ||
): Promise<Ast | null> { | ||
doc: Document, | ||
palettes: PaletteRegistry | ||
): Promise<{ ast: Ast | null; errors: ErrorMessage[] | undefined }> { | ||
const { | ||
state: { visualization: visualizationState, datasourceStates: persistedDatasourceStates }, | ||
visualizationType, | ||
references, | ||
title, | ||
description, | ||
} = doc; | ||
if (!visualizationType) return null; | ||
if (!visualizationType) { | ||
return { | ||
ast: null, | ||
errors: [{ shortMessage: '', longMessage: getMissingVisualizationTypeError() }], | ||
}; | ||
} | ||
const visualization = visualizations[visualizationType!]; | ||
const datasourceStates = await initializeDatasources( | ||
datasources, | ||
|
@@ -97,29 +107,42 @@ export async function persistedStateToExpression( | |
|
||
const datasourceLayers = createDatasourceLayers(datasources, datasourceStates); | ||
|
||
return buildExpression({ | ||
title, | ||
description, | ||
const datasourceId = getActiveDatasourceIdFromDoc(doc); | ||
if (datasourceId == null) { | ||
return { | ||
ast: null, | ||
errors: [{ shortMessage: '', longMessage: getMissingCurrentDatasource() }], | ||
}; | ||
} | ||
const validationResult = validateDatasourceAndVisualization( | ||
datasources[datasourceId], | ||
datasourceStates[datasourceId].state, | ||
visualization, | ||
visualizationState, | ||
datasourceMap: datasources, | ||
datasourceStates, | ||
datasourceLayers, | ||
}); | ||
{ datasourceLayers, availablePalettes: palettes } | ||
); | ||
|
||
return { | ||
ast: buildExpression({ | ||
title, | ||
description, | ||
visualization, | ||
visualizationState, | ||
datasourceMap: datasources, | ||
datasourceStates, | ||
datasourceLayers, | ||
}), | ||
errors: validationResult, | ||
}; | ||
} | ||
|
||
export const validateDatasourceAndVisualization = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just realizing this function is only operating on a single datasource - I guess this is something we have to revisit once we introduce additional datasource that can be active at the same time (like SQL). Nothing for this PR though. |
||
currentDataSource: Datasource | null, | ||
currentDatasourceState: unknown | null, | ||
currentVisualization: Visualization | null, | ||
currentVisualizationState: unknown | undefined, | ||
frameAPI: FramePublicAPI | ||
): | ||
| Array<{ | ||
shortMessage: string; | ||
longMessage: string; | ||
}> | ||
| undefined => { | ||
frameAPI: Pick<FramePublicAPI, 'datasourceLayers' | 'activeData' | 'availablePalettes'> | ||
): ErrorMessage[] | undefined => { | ||
const layersGroups = currentVisualizationState | ||
? currentVisualization | ||
?.getLayerIds(currentVisualizationState) | ||
|
@@ -141,7 +164,7 @@ export const validateDatasourceAndVisualization = ( | |
: undefined; | ||
|
||
const visualizationValidationErrors = currentVisualizationState | ||
? currentVisualization?.getErrorMessages(currentVisualizationState, frameAPI) | ||
? currentVisualization?.getErrorMessages(currentVisualizationState) | ||
: undefined; | ||
|
||
if (datasourceValidationErrors?.length || visualizationValidationErrors?.length) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strict equality works here, I'm surprised the linter allows ==
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any particular meaning for
null
andundefined
here, or do they have the same meaning?eslint has a special option for
null
orundefined
case in the ruleeqeqeq
, which is usually enabled.As in steps 2 and 3 of the ECMA262 Abstract Equality spec the
==
operator treat them the same exact way. So unless specific distinct meaning of the two there's no difference.