Skip to content

Commit

Permalink
[Lens] Fix crash on chart type change via suggestions (#173523)
Browse files Browse the repository at this point in the history
## Summary

Use the correct `activeVisualization` on chart type change by
suggestions:


![esql_dashboard_crash_fixed](https://github.com/elastic/kibana/assets/924948/6142647f-6a74-4f95-8ebb-df984624b596)
  • Loading branch information
dej611 authored Dec 18, 2023
1 parent 43413ea commit 99f3001
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ export function LensEditConfigurationFlyout({
const [isLayerAccordionOpen, setIsLayerAccordionOpen] = useState(true);
const [isSuggestionsAccordionOpen, setIsSuggestionsAccordionOpen] = useState(false);
const datasourceState = attributes.state.datasourceStates[datasourceId];
const activeVisualization = visualizationMap[attributes.visualizationType];
const activeDatasource = datasourceMap[datasourceId];
const { datasourceStates, visualization, isLoading, annotationGroups } = useLensSelector(
(state) => state.lens
);
// use the latest activeId, but fallback to attributes
const activeVisualization =
visualizationMap[visualization.activeId ?? attributes.visualizationType];
const framePublicAPI = useLensSelector((state) => selectFramePublicAPI(state, datasourceMap));
const suggestsLimitedColumns = activeDatasource?.suggestsLimitedColumns?.(datasourceState);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,13 @@ export function SuggestionPanel({
const framePublicAPI = useLensSelector((state) => selectFramePublicAPI(state, datasourceMap));
const changesApplied = useLensSelector(selectChangesApplied);
// get user's selection from localStorage, this key defines if the suggestions panel will be hidden or not
const initialAccordionStatusValue =
typeof isAccordionOpen !== 'undefined' ? !Boolean(isAccordionOpen) : false;
const initialAccordionStatusValue = isAccordionOpen != null ? !Boolean(isAccordionOpen) : false;
const [hideSuggestions, setHideSuggestions] = useLocalStorage(
LOCAL_STORAGE_SUGGESTIONS_PANEL,
initialAccordionStatusValue
);
useEffect(() => {
if (typeof isAccordionOpen !== 'undefined') {
if (isAccordionOpen != null) {
setHideSuggestions(!Boolean(isAccordionOpen));
}
}, [isAccordionOpen, setHideSuggestions]);
Expand Down

0 comments on commit 99f3001

Please sign in to comment.