From 139d31549035e6b6cfd4f3623344babd8ae69bcd Mon Sep 17 00:00:00 2001 From: Jackie Han Date: Wed, 17 Apr 2024 22:55:26 -0700 Subject: [PATCH] make dataSourceId type safe Signed-off-by: Jackie Han --- public/pages/Dashboard/utils/utils.tsx | 6 +++--- .../DetectorDetail/hooks/useFetchMonitorInfo.ts | 2 +- public/pages/main/Main.tsx | 6 +++--- public/redux/reducers/ad.ts | 14 +++++++------- public/redux/reducers/alerting.ts | 2 +- public/redux/reducers/anomalyResults.ts | 4 ++-- public/redux/reducers/opensearch.ts | 10 +++++----- public/redux/reducers/sampleData.ts | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/public/pages/Dashboard/utils/utils.tsx b/public/pages/Dashboard/utils/utils.tsx index 188cbab9..86414003 100644 --- a/public/pages/Dashboard/utils/utils.tsx +++ b/public/pages/Dashboard/utils/utils.tsx @@ -443,7 +443,7 @@ export const getLatestAnomalyResultsByTimeRange = async ( checkLastIndexOnly: boolean, resultIndex: string, onlyQueryCustomResultIndex: boolean, - dataSourceId = '' + dataSourceId: string ): Promise => { let from = 0; let anomalyResults = [] as object[]; @@ -504,7 +504,7 @@ export const getLatestAnomalyResultsForDetectorsByTimeRange = async ( checkLastIndexOnly: boolean, resultIndex: string, onlyQueryCustomResultIndex: boolean, - dataSourceId = '' + dataSourceId: string ): Promise => { const detectorAndIdMap = buildDetectorAndIdMap(selectedDetectors); let from = 0; @@ -615,7 +615,7 @@ export const getAnomalyDistributionForDetectorsByTimeRange = async ( onlyQueryCustomResultIndex: boolean ) => APIAction, selectedDetectors: DetectorListItem[], - dataSourceId = '', + dataSourceId: string, timeRange: string, dispatch: Dispatch, threshold: number, diff --git a/public/pages/DetectorDetail/hooks/useFetchMonitorInfo.ts b/public/pages/DetectorDetail/hooks/useFetchMonitorInfo.ts index 68938968..220f0570 100644 --- a/public/pages/DetectorDetail/hooks/useFetchMonitorInfo.ts +++ b/public/pages/DetectorDetail/hooks/useFetchMonitorInfo.ts @@ -19,7 +19,7 @@ import { searchMonitors } from '../../../redux/reducers/alerting'; //A hook which gets AD monitor. export const useFetchMonitorInfo = ( detectorId: string, - dataSourceId = '', + dataSourceId: string, dataSourceEnabled: boolean ): { monitor: Monitor | undefined; diff --git a/public/pages/main/Main.tsx b/public/pages/main/Main.tsx index 292270c6..4fc9a0be 100644 --- a/public/pages/main/Main.tsx +++ b/public/pages/main/Main.tsx @@ -52,9 +52,9 @@ export function Main(props: MainProps) { 'from=0&size=20&search=&indices=&sortField=name&sortDirection=asc'; const constructHrefWithDataSourceId = ( - basePath, - existingParams = '', - dataSourceId = '' + basePath: string, + existingParams: string, + dataSourceId: string ) => { const searchParams = new URLSearchParams(existingParams); diff --git a/public/redux/reducers/ad.ts b/public/redux/reducers/ad.ts index ed0aea0f..67e7b558 100644 --- a/public/redux/reducers/ad.ts +++ b/public/redux/reducers/ad.ts @@ -371,7 +371,7 @@ const reducer = handleActions( export const createDetector = ( requestBody: Detector, - dataSourceId = '' + dataSourceId: string ): APIAction => { const url = dataSourceId ? `..${AD_NODE_API.DETECTOR}/${dataSourceId}` @@ -399,7 +399,7 @@ export const validateDetector = ( export const getDetector = ( detectorId: string, - dataSourceId = '' + dataSourceId: string ): APIAction => { const baseUrl = `..${AD_NODE_API.DETECTOR}`; const url = dataSourceId @@ -449,7 +449,7 @@ export const updateDetector = ( export const deleteDetector = ( detectorId: string, - dataSourceId = '' + dataSourceId: string ): APIAction => { const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`; const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl; @@ -463,7 +463,7 @@ export const deleteDetector = ( export const startDetector = ( detectorId: string, - dataSourceId = '' + dataSourceId: string ): APIAction => { const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/start`; const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl; @@ -477,7 +477,7 @@ export const startDetector = ( export const startHistoricalDetector = ( detectorId: string, - dataSourceId = '', + dataSourceId: string, startTime: number, endTime: number ): APIAction => { @@ -503,7 +503,7 @@ export const startHistoricalDetector = ( export const stopDetector = ( detectorId: string, - dataSourceId = '' + dataSourceId: string ): APIAction => { const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/stop/${false}`; const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl; @@ -517,7 +517,7 @@ export const stopDetector = ( export const stopHistoricalDetector = ( detectorId: string, - dataSourceId = '' + dataSourceId: string ): APIAction => { const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`; const url = dataSourceId diff --git a/public/redux/reducers/alerting.ts b/public/redux/reducers/alerting.ts index ece38e43..79bfb3c9 100644 --- a/public/redux/reducers/alerting.ts +++ b/public/redux/reducers/alerting.ts @@ -94,7 +94,7 @@ const reducer = handleActions( initialDetectorsState ); -export const searchMonitors = (dataSourceId = ''): APIAction => { +export const searchMonitors = (dataSourceId: string): APIAction => { const baseUrl = `..${ALERTING_NODE_API._SEARCH}`; const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl; diff --git a/public/redux/reducers/anomalyResults.ts b/public/redux/reducers/anomalyResults.ts index 845e3bb4..5eda008e 100644 --- a/public/redux/reducers/anomalyResults.ts +++ b/public/redux/reducers/anomalyResults.ts @@ -94,7 +94,7 @@ const reducer = handleActions( export const getDetectorResults = ( id: string, - dataSourceId = '', + dataSourceId: string, queryParams: any, isHistorical: boolean, resultIndex: string, @@ -119,7 +119,7 @@ export const getDetectorResults = ( export const searchResults = ( requestBody: any, resultIndex: string, - dataSourceId = '', + dataSourceId: string, onlyQueryCustomResultIndex: boolean ): APIAction => { let baseUrl = `..${AD_NODE_API.DETECTOR}/results/_search`; diff --git a/public/redux/reducers/opensearch.ts b/public/redux/reducers/opensearch.ts index afd095ca..0c354c45 100644 --- a/public/redux/reducers/opensearch.ts +++ b/public/redux/reducers/opensearch.ts @@ -246,7 +246,7 @@ const reducer = handleActions( initialState ); -export const getIndices = (searchKey = '', dataSourceId = '') => { +export const getIndices = (searchKey = '', dataSourceId: string) => { const baseUrl = `..${AD_NODE_API._INDICES}`; const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl; @@ -259,7 +259,7 @@ export const getIndices = (searchKey = '', dataSourceId = '') => { export const getAliases = ( searchKey: string = '', - dataSourceId = '' + dataSourceId: string ): APIAction => { const baseUrl = `..${AD_NODE_API._ALIASES}`; const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl; @@ -287,7 +287,7 @@ export const searchOpenSearch = (requestData: any): APIAction => ({ }), }); -export const createIndex = (indexConfig: any, dataSourceId = ''): APIAction => { +export const createIndex = (indexConfig: any, dataSourceId: string): APIAction => { const url = dataSourceId ? `${AD_NODE_API.CREATE_INDEX}/${dataSourceId}` : AD_NODE_API.CREATE_INDEX; @@ -300,7 +300,7 @@ export const createIndex = (indexConfig: any, dataSourceId = ''): APIAction => { }; }; -export const bulk = (body: any, dataSourceId = ''): APIAction => { +export const bulk = (body: any, dataSourceId: string): APIAction => { const url = dataSourceId ? `${AD_NODE_API.BULK}/${dataSourceId}` : AD_NODE_API.BULK; @@ -318,7 +318,7 @@ export const deleteIndex = (index: string): APIAction => ({ }); export const getPrioritizedIndices = - (searchKey: string, dataSourceId = ''): ThunkAction => + (searchKey: string, dataSourceId: string): ThunkAction => async (dispatch, getState) => { //Fetch Indices and Aliases with text provided await dispatch(getIndices(searchKey, dataSourceId)); diff --git a/public/redux/reducers/sampleData.ts b/public/redux/reducers/sampleData.ts index a3e19ddd..b92ce773 100644 --- a/public/redux/reducers/sampleData.ts +++ b/public/redux/reducers/sampleData.ts @@ -56,7 +56,7 @@ const reducer = handleActions( export const createSampleData = ( sampleDataType: SAMPLE_TYPE, - dataSourceId = '' + dataSourceId: string ): APIAction => { const url = dataSourceId ? `..${AD_NODE_API.CREATE_SAMPLE_DATA}/${sampleDataType}/${dataSourceId}`