[Infra] Fix control filters loading (#189050)

fixes [189049](https://github.com/elastic/kibana/issues/189049)

## Summary

Fix a problem when loading the control filters when data view is still
loading


https://github.com/user-attachments/assets/f98dd4ae-72c6-4e19-9f25-99ff6a1e752c

### How to test
- Start a local Kibana instance
- Navigate to Infrastructure > Host
- Performa a full page refresh

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Carlos Crespo 2024-07-25 11:09:24 +02:00 committed by GitHub
parent 9e71c7e830
commit b99c392b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -40,21 +40,24 @@ export const ControlsContent: React.FC<Props> = ({
const [controlPanels, setControlPanels] = useControlPanels(dataView);
const subscriptions = useRef<Subscription>(new Subscription());
const getInitialInput = useCallback(async () => {
const initialInput: Partial<ControlGroupInput> = {
id: dataView?.id ?? '',
viewMode: ViewMode.VIEW,
chainingSystem: 'HIERARCHICAL',
controlStyle: 'oneLine',
defaultControlWidth: 'small',
panels: controlPanels,
filters,
query,
timeRange,
};
const getInitialInput = useCallback(
(loadedDataView: DataView) => async () => {
const initialInput: Partial<ControlGroupInput> = {
id: loadedDataView.id,
viewMode: ViewMode.VIEW,
chainingSystem: 'HIERARCHICAL',
controlStyle: 'oneLine',
defaultControlWidth: 'small',
panels: controlPanels,
filters,
query,
timeRange,
};
return { initialInput };
}, [controlPanels, dataView?.id, filters, query, timeRange]);
return { initialInput };
},
[controlPanels, filters, query, timeRange]
);
const loadCompleteHandler = useCallback(
(controlGroup: ControlGroupAPI) => {
@ -90,10 +93,14 @@ export const ControlsContent: React.FC<Props> = ({
};
}, []);
if (!dataView) {
return null;
}
return (
<ControlGroupContainer>
<ControlGroupRenderer
getCreationOptions={getInitialInput}
getCreationOptions={getInitialInput(dataView)}
ref={loadCompleteHandler}
timeRange={timeRange}
query={query}