[ML] Fix Total feature importance section not expandable when set to False (#92450)
This commit is contained in:
parent
e1166999e0
commit
accf6b8c2e
2 changed files with 14 additions and 6 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
import './expandable_section.scss';
|
||||
|
||||
import React, { FC, ReactNode, useCallback } from 'react';
|
||||
import React, { FC, ReactNode, useCallback, useMemo } from 'react';
|
||||
|
||||
import {
|
||||
EuiBadge,
|
||||
|
@ -58,11 +58,15 @@ export const ExpandableSection: FC<ExpandableSectionProps> = ({
|
|||
docsLink,
|
||||
urlStateKey,
|
||||
}) => {
|
||||
const [pageUrlState, setPageUrlState] = useExplorationUrlState();
|
||||
const overrides = useMemo(
|
||||
() => (isExpandedDefault !== undefined ? { [urlStateKey]: isExpandedDefault } : undefined),
|
||||
[urlStateKey, isExpandedDefault]
|
||||
);
|
||||
const [pageUrlState, setPageUrlState] = useExplorationUrlState(overrides);
|
||||
|
||||
const isExpanded =
|
||||
isExpandedDefault !== undefined &&
|
||||
pageUrlState[urlStateKey] === getDefaultExplorationPageUrlState()[urlStateKey]
|
||||
pageUrlState[urlStateKey] === getDefaultExplorationPageUrlState(overrides)[urlStateKey]
|
||||
? isExpandedDefault
|
||||
: pageUrlState[urlStateKey];
|
||||
|
||||
|
|
|
@ -9,8 +9,11 @@ import { usePageUrlState } from '../../../../util/url_state';
|
|||
import { ML_PAGES } from '../../../../../../common/constants/ml_url_generator';
|
||||
import { SEARCH_QUERY_LANGUAGE } from '../../../../../../common/constants/search';
|
||||
import { ExplorationPageUrlState } from '../../../../../../common/types/ml_url_generator';
|
||||
import { isPopulatedObject } from '../../../../../../common/util/object_utils';
|
||||
|
||||
export function getDefaultExplorationPageUrlState(): ExplorationPageUrlState {
|
||||
export function getDefaultExplorationPageUrlState(
|
||||
overrides?: Partial<ExplorationPageUrlState>
|
||||
): ExplorationPageUrlState {
|
||||
return {
|
||||
queryText: '',
|
||||
queryLanguage: SEARCH_QUERY_LANGUAGE.KUERY,
|
||||
|
@ -21,12 +24,13 @@ export function getDefaultExplorationPageUrlState(): ExplorationPageUrlState {
|
|||
feature_importance: true,
|
||||
results: true,
|
||||
splom: true,
|
||||
...(isPopulatedObject(overrides) ? overrides : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function useExplorationUrlState() {
|
||||
export function useExplorationUrlState(overrides?: Partial<ExplorationPageUrlState>) {
|
||||
return usePageUrlState<ExplorationPageUrlState>(
|
||||
ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION,
|
||||
getDefaultExplorationPageUrlState()
|
||||
getDefaultExplorationPageUrlState(overrides)
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue