Skip to content

Commit

Permalink
[Bug fix] Metrics datasource (#2242)
Browse files Browse the repository at this point in the history
* set default datasource to null and prevent rendering until it is set

Signed-off-by: Adam Tackett <[email protected]>

* prevent invalid api call

Signed-off-by: Adam Tackett <[email protected]>

---------

Signed-off-by: Adam Tackett <[email protected]>
Co-authored-by: Adam Tackett <[email protected]>
  • Loading branch information
TackAdam and Adam Tackett authored Nov 5, 2024
1 parent 10e6636 commit 397a867
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions public/components/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const Home = ({
// Side bar constants
const [selectedDataSource, setSelectedDataSource] = useState<OptionType[]>([]);
const [selectedOTIndex, setSelectedOTIndex] = useState([]);
const [dataSourceMDSId, setDataSourceMDSId] = useState<string>('');
const [dataSourceMDSId, setDataSourceMDSId] = useState<string | null>(null);
const [reloadSidebar, setReloadSidebar] = useState<boolean>(false);

useEffect(() => {
Expand All @@ -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));
Expand Down Expand Up @@ -111,7 +111,7 @@ export const Home = ({
path={['/:id', '/']}
render={(routerProps) => (
<div>
{reloadSidebar && (
{(dataSourceEnabled ? dataSourceMDSId !== null : true) && reloadSidebar && (
<EuiPage>
<EuiPageBody component="div">
<TopMenu />
Expand All @@ -133,6 +133,7 @@ export const Home = ({
selectedOTIndex={selectedOTIndex}
setSelectedOTIndex={setSelectedOTIndex}
dataSourceMDSId={dataSourceMDSId}
dataSourceEnabled={dataSourceEnabled}
/>
</EuiResizablePanel>

Expand Down
9 changes: 8 additions & 1 deletion public/components/metrics/sidebar/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ interface SideBarMenuProps {
selectedOTIndex: React.SetStateAction<Array<{}>>;
setSelectedOTIndex: React.Dispatch<React.SetStateAction<unknown>>;
additionalSelectedMetricId?: string;
dataSourceMDSId: string;
dataSourceMDSId: string | null;
dataSourceEnabled: boolean;
}
export const Sidebar = ({
selectedDataSource,
Expand All @@ -49,6 +50,7 @@ export const Sidebar = ({
setSelectedOTIndex,
additionalSelectedMetricId,
dataSourceMDSId,
dataSourceEnabled,
}: SideBarMenuProps) => {
const dispatch = useDispatch();
const [availableOTDocuments, setAvailableOTDocuments] = useState([]);
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 397a867

Please sign in to comment.