From 397a867026f17fd297023c9ea2effda72fc7a62f Mon Sep 17 00:00:00 2001 From: Adam Tackett <105462877+TackAdam@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:42:47 -0800 Subject: [PATCH] [Bug fix] Metrics datasource (#2242) * set default datasource to null and prevent rendering until it is set Signed-off-by: Adam Tackett * prevent invalid api call Signed-off-by: Adam Tackett --------- Signed-off-by: Adam Tackett Co-authored-by: Adam Tackett --- public/components/metrics/index.tsx | 7 ++++--- public/components/metrics/sidebar/sidebar.tsx | 9 ++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/public/components/metrics/index.tsx b/public/components/metrics/index.tsx index 348e79f8c9..493a9f5521 100644 --- a/public/components/metrics/index.tsx +++ b/public/components/metrics/index.tsx @@ -55,7 +55,7 @@ export const Home = ({ // Side bar constants const [selectedDataSource, setSelectedDataSource] = useState([]); const [selectedOTIndex, setSelectedOTIndex] = useState([]); - const [dataSourceMDSId, setDataSourceMDSId] = useState(''); + const [dataSourceMDSId, setDataSourceMDSId] = useState(null); const [reloadSidebar, setReloadSidebar] = useState(false); useEffect(() => { @@ -77,7 +77,7 @@ export const Home = ({ const dispatch = useDispatch(); const onSelectedDataSource = async (dataSources: DataSourceOption[]) => { - const id = dataSources[0] ? dataSources[0].id : ''; + const id = dataSources[0] ? dataSources[0].id : null; setDataSourceMDSId(id); debounce(() => { dispatch(setSelectedDataSourceMDSId(id)); @@ -111,7 +111,7 @@ export const Home = ({ path={['/:id', '/']} render={(routerProps) => (
- {reloadSidebar && ( + {(dataSourceEnabled ? dataSourceMDSId !== null : true) && reloadSidebar && ( @@ -133,6 +133,7 @@ export const Home = ({ selectedOTIndex={selectedOTIndex} setSelectedOTIndex={setSelectedOTIndex} dataSourceMDSId={dataSourceMDSId} + dataSourceEnabled={dataSourceEnabled} /> diff --git a/public/components/metrics/sidebar/sidebar.tsx b/public/components/metrics/sidebar/sidebar.tsx index 460f4626c0..b2bcb2b156 100644 --- a/public/components/metrics/sidebar/sidebar.tsx +++ b/public/components/metrics/sidebar/sidebar.tsx @@ -40,7 +40,8 @@ interface SideBarMenuProps { selectedOTIndex: React.SetStateAction>; setSelectedOTIndex: React.Dispatch>; additionalSelectedMetricId?: string; - dataSourceMDSId: string; + dataSourceMDSId: string | null; + dataSourceEnabled: boolean; } export const Sidebar = ({ selectedDataSource, @@ -49,6 +50,7 @@ export const Sidebar = ({ setSelectedOTIndex, additionalSelectedMetricId, dataSourceMDSId, + dataSourceEnabled, }: SideBarMenuProps) => { const dispatch = useDispatch(); const [availableOTDocuments, setAvailableOTDocuments] = useState([]); @@ -95,6 +97,11 @@ export const Sidebar = ({ }, [selectedMetrics, selectedMetricsIds, dataSourceMDSId]); useEffect(() => { + // If data source is enabled but is still null prevent the invalid call + if (dataSourceEnabled && dataSourceMDSId === null) { + return; + } + if (selectedOTIndex.length > 0 && selectedDataSource[0]?.label === 'OpenTelemetry') { const fetchOtelDocuments = async () => { try {