Skip to content

Commit 225b386

Browse files
update actionOption attribution for all data soure components (#732)
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent a0a2608 commit 225b386

File tree

12 files changed

+50
-38
lines changed

12 files changed

+50
-38
lines changed

public/models/interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,5 +330,5 @@ export interface ValidationSettingResponse {
330330

331331
export interface MDSStates {
332332
queryParams: MDSQueryParams;
333-
selectedDataSourceId: string;
333+
selectedDataSourceId: string | undefined;
334334
}

public/pages/Dashboard/Container/DashboardOverview.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function DashboardOverview(props: OverviewProps) {
9393
queryParams,
9494
selectedDataSourceId: queryParams.dataSourceId
9595
? queryParams.dataSourceId
96-
: '',
96+
: undefined,
9797
});
9898

9999
const getDetectorOptions = (detectorsIdMap: {
@@ -267,7 +267,9 @@ export function DashboardOverview(props: OverviewProps) {
267267
componentType={'DataSourceSelectable'}
268268
componentConfig={{
269269
fullWidth: false,
270-
activeOption: [{ id: MDSOverviewState.selectedDataSourceId }],
270+
activeOption: MDSOverviewState.selectedDataSourceId !== undefined
271+
? [{ id: MDSOverviewState.selectedDataSourceId }]
272+
: undefined,
271273
savedObjects: getSavedObjectsClient(),
272274
notifications: getNotifications(),
273275
onSelectedDataSources: (dataSources) =>

public/pages/DefineDetector/containers/DefineDetector.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const DefineDetector = (props: DefineDetectorProps) => {
9898

9999
const [MDSCreateState, setMDSCreateState] = useState<MDSStates>({
100100
queryParams: MDSQueryParams,
101-
selectedDataSourceId: dataSourceId ? dataSourceId : '',
101+
selectedDataSourceId: dataSourceId ? dataSourceId : undefined,
102102
});
103103

104104
// To handle backward compatibility, we need to pass some fields via
@@ -297,7 +297,9 @@ export const DefineDetector = (props: DefineDetectorProps) => {
297297
componentType={'DataSourceSelectable'}
298298
componentConfig={{
299299
fullWidth: false,
300-
activeOption: [{ id: MDSCreateState.selectedDataSourceId }],
300+
activeOption: MDSCreateState.selectedDataSourceId !== undefined
301+
? [{ id: MDSCreateState.selectedDataSourceId }]
302+
: undefined,
301303
savedObjects: getSavedObjectsClient(),
302304
notifications: getNotifications(),
303305
onSelectedDataSources: (dataSources) =>

public/pages/DetectorsList/containers/List/List.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ interface ListState {
109109
queryParams: GetDetectorsQueryParams;
110110
selectedDetectorStates: DETECTOR_STATE[];
111111
selectedIndices: string[];
112-
selectedDataSourceId: string;
112+
selectedDataSourceId: string | undefined;
113113
}
114114
interface ConfirmModalState {
115115
isOpen: boolean;
@@ -208,7 +208,7 @@ export const DetectorList = (props: ListProps) => {
208208
: ALL_INDICES,
209209
selectedDataSourceId: queryParams.dataSourceId
210210
? queryParams.dataSourceId
211-
: '',
211+
: undefined,
212212
});
213213

214214
// Set breadcrumbs on page initialization
@@ -681,7 +681,9 @@ export const DetectorList = (props: ListProps) => {
681681
componentType={'DataSourceSelectable'}
682682
componentConfig={{
683683
fullWidth: false,
684-
activeOption: [{ id: state.selectedDataSourceId }],
684+
activeOption: state.selectedDataSourceId !== undefined
685+
? [{ id: state.selectedDataSourceId }]
686+
: undefined,
685687
savedObjects: getSavedObjectsClient(),
686688
notifications: getNotifications(),
687689
onSelectedDataSources: (dataSources) =>

public/pages/Overview/containers/AnomalyDetectionOverview.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function AnomalyDetectionOverview(props: AnomalyDetectionOverviewProps) {
104104
queryParams,
105105
selectedDataSourceId: queryParams.dataSourceId
106106
? queryParams.dataSourceId
107-
: '',
107+
: undefined,
108108
});
109109

110110
// Set breadcrumbs on page initialization
@@ -242,7 +242,9 @@ export function AnomalyDetectionOverview(props: AnomalyDetectionOverviewProps) {
242242
componentType={'DataSourceSelectable'}
243243
componentConfig={{
244244
fullWidth: false,
245-
activeOption: [{ id: MDSOverviewState.selectedDataSourceId }],
245+
activeOption: MDSOverviewState.selectedDataSourceId !== undefined
246+
? [{ id: MDSOverviewState.selectedDataSourceId }]
247+
: undefined,
246248
savedObjects: getSavedObjectsClient(),
247249
notifications: getNotifications(),
248250
onSelectedDataSources: (dataSources) =>

public/pages/utils/helpers.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const formatNumber = (data: any) => {
119119
};
120120

121121
export const getAllDetectorsQueryParamsWithDataSourceId = (
122-
dataSourceId: string
122+
dataSourceId: string = ''
123123
) => ({
124124
from: 0,
125125
search: '',
@@ -131,7 +131,7 @@ export const getAllDetectorsQueryParamsWithDataSourceId = (
131131
});
132132

133133
export const getSampleDetectorsQueryParamsWithDataSouceId = (
134-
dataSourceId: string
134+
dataSourceId: string = ''
135135
) => ({
136136
from: 0,
137137
search: 'sample',
@@ -152,7 +152,7 @@ export const getDataSourceFromURL = (location: {
152152

153153
export const constructHrefWithDataSourceId = (
154154
basePath: string,
155-
dataSourceId: string,
155+
dataSourceId: string = '',
156156
withHash: Boolean
157157
): string => {
158158
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;

public/redux/reducers/ad.ts

+16-13
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ const reducer = handleActions<Detectors>(
371371

372372
export const createDetector = (
373373
requestBody: Detector,
374-
dataSourceId: string
374+
dataSourceId: string = ''
375375
): APIAction => {
376376
const url = dataSourceId
377377
? `..${AD_NODE_API.DETECTOR}/${dataSourceId}`
@@ -389,7 +389,7 @@ export const createDetector = (
389389
export const validateDetector = (
390390
requestBody: Detector,
391391
validationType: string,
392-
dataSourceId: string
392+
dataSourceId: string = ''
393393
): APIAction => {
394394
const baseUrl = `..${AD_NODE_API.DETECTOR}/_validate/${validationType}`;
395395
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -405,7 +405,7 @@ export const validateDetector = (
405405

406406
export const getDetector = (
407407
detectorId: string,
408-
dataSourceId: string
408+
dataSourceId: string = ''
409409
): APIAction => {
410410
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`;
411411
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -420,9 +420,11 @@ export const getDetector = (
420420
export const getDetectorList = (
421421
queryParams: GetDetectorsQueryParams
422422
): APIAction => {
423+
const dataSourceId = queryParams.dataSourceId || '';
424+
423425
const baseUrl = `..${AD_NODE_API.DETECTOR}/_list`;
424-
const url = queryParams.dataSourceId
425-
? `${baseUrl}/${queryParams.dataSourceId}`
426+
const url = dataSourceId
427+
? `${baseUrl}/${dataSourceId}`
426428
: baseUrl;
427429

428430
return {
@@ -442,7 +444,7 @@ export const searchDetector = (requestBody: any): APIAction => ({
442444
export const updateDetector = (
443445
detectorId: string,
444446
requestBody: Detector,
445-
dataSourceId: string
447+
dataSourceId: string = ''
446448
): APIAction => {
447449
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`;
448450
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -459,7 +461,7 @@ export const updateDetector = (
459461

460462
export const deleteDetector = (
461463
detectorId: string,
462-
dataSourceId: string
464+
dataSourceId: string = ''
463465
): APIAction => {
464466
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`;
465467
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -473,7 +475,7 @@ export const deleteDetector = (
473475

474476
export const startDetector = (
475477
detectorId: string,
476-
dataSourceId: string
478+
dataSourceId: string = ''
477479
): APIAction => {
478480
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/start`;
479481
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -487,7 +489,7 @@ export const startDetector = (
487489

488490
export const startHistoricalDetector = (
489491
detectorId: string,
490-
dataSourceId: string,
492+
dataSourceId: string = '',
491493
startTime: number,
492494
endTime: number
493495
): APIAction => {
@@ -513,7 +515,7 @@ export const startHistoricalDetector = (
513515

514516
export const stopDetector = (
515517
detectorId: string,
516-
dataSourceId: string
518+
dataSourceId: string = ''
517519
): APIAction => {
518520
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/stop/${false}`;
519521
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -527,7 +529,7 @@ export const stopDetector = (
527529

528530
export const stopHistoricalDetector = (
529531
detectorId: string,
530-
dataSourceId: string
532+
dataSourceId: string = ''
531533
): APIAction => {
532534
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/stop/${true}`;
533535
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -548,7 +550,8 @@ export const getDetectorProfile = (detectorId: string): APIAction => ({
548550

549551
export const matchDetector = (
550552
detectorName: string,
551-
dataSourceId: string): APIAction => {
553+
dataSourceId: string = ''
554+
): APIAction => {
552555
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorName}/_match`;
553556
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
554557

@@ -558,7 +561,7 @@ export const matchDetector = (
558561
};
559562
};
560563

561-
export const getDetectorCount = (dataSourceId: string): APIAction => {
564+
export const getDetectorCount = (dataSourceId: string = ''): APIAction => {
562565
const url = dataSourceId ?
563566
`..${AD_NODE_API.DETECTOR}/_count/${dataSourceId}` :
564567
`..${AD_NODE_API.DETECTOR}/_count`;

public/redux/reducers/alerting.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const reducer = handleActions<Monitors>(
9494
initialDetectorsState
9595
);
9696

97-
export const searchMonitors = (dataSourceId: string): APIAction => {
97+
export const searchMonitors = (dataSourceId: string = ''): APIAction => {
9898
const baseUrl = `..${ALERTING_NODE_API._SEARCH}`;
9999
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
100100

@@ -108,7 +108,7 @@ export const searchAlerts = (
108108
monitorId: string,
109109
startTime: number,
110110
endTime: number,
111-
dataSourceId: string
111+
dataSourceId: string = ''
112112
): APIAction => {
113113
const baseUrl = `..${ALERTING_NODE_API.ALERTS}`;
114114
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;

public/redux/reducers/anomalyResults.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const reducer = handleActions<Anomalies>(
9494

9595
export const getDetectorResults = (
9696
id: string,
97-
dataSourceId: string,
97+
dataSourceId: string = '',
9898
queryParams: any,
9999
isHistorical: boolean,
100100
resultIndex: string,
@@ -119,7 +119,7 @@ export const getDetectorResults = (
119119
export const searchResults = (
120120
requestBody: any,
121121
resultIndex: string,
122-
dataSourceId: string,
122+
dataSourceId: string = '',
123123
onlyQueryCustomResultIndex: boolean
124124
): APIAction => {
125125
let baseUrl = `..${AD_NODE_API.DETECTOR}/results/_search`;

public/redux/reducers/opensearch.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { getPathsPerDataType } from './mapper';
2121
import { CatIndex, IndexAlias } from '../../../server/models/types';
2222
import { AD_NODE_API } from '../../../utils/constants';
2323
import { get } from 'lodash';
24+
import { data } from 'jquery';
2425

2526
const GET_INDICES = 'opensearch/GET_INDICES';
2627
const GET_ALIASES = 'opensearch/GET_ALIASES';
@@ -246,7 +247,7 @@ const reducer = handleActions<OpenSearchState>(
246247
initialState
247248
);
248249

249-
export const getIndices = (searchKey = '', dataSourceId: string) => {
250+
export const getIndices = (searchKey = '', dataSourceId: string = '') => {
250251
const baseUrl = `..${AD_NODE_API._INDICES}`;
251252
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
252253

@@ -259,7 +260,7 @@ export const getIndices = (searchKey = '', dataSourceId: string) => {
259260

260261
export const getAliases = (
261262
searchKey: string = '',
262-
dataSourceId: string
263+
dataSourceId: string = ''
263264
): APIAction => {
264265
const baseUrl = `..${AD_NODE_API._ALIASES}`;
265266
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
@@ -271,7 +272,7 @@ export const getAliases = (
271272
};
272273
};
273274

274-
export const getMappings = (searchKey: string = '', dataSourceId: string): APIAction => {
275+
export const getMappings = (searchKey: string = '', dataSourceId: string = ''): APIAction => {
275276
const url = dataSourceId ? `${AD_NODE_API._MAPPINGS}/${dataSourceId}` : AD_NODE_API._MAPPINGS;
276277

277278
return {
@@ -291,7 +292,7 @@ export const searchOpenSearch = (requestData: any): APIAction => ({
291292
}),
292293
});
293294

294-
export const createIndex = (indexConfig: any, dataSourceId: string): APIAction => {
295+
export const createIndex = (indexConfig: any, dataSourceId: string = ''): APIAction => {
295296
const url = dataSourceId
296297
? `${AD_NODE_API.CREATE_INDEX}/${dataSourceId}`
297298
: AD_NODE_API.CREATE_INDEX;
@@ -304,7 +305,7 @@ export const createIndex = (indexConfig: any, dataSourceId: string): APIAction =
304305
};
305306
};
306307

307-
export const bulk = (body: any, dataSourceId: string): APIAction => {
308+
export const bulk = (body: any, dataSourceId: string = ''): APIAction => {
308309
const url = dataSourceId
309310
? `${AD_NODE_API.BULK}/${dataSourceId}`
310311
: AD_NODE_API.BULK;
@@ -322,7 +323,7 @@ export const deleteIndex = (index: string): APIAction => ({
322323
});
323324

324325
export const getPrioritizedIndices =
325-
(searchKey: string, dataSourceId: string): ThunkAction =>
326+
(searchKey: string, dataSourceId: string = ''): ThunkAction =>
326327
async (dispatch, getState) => {
327328
//Fetch Indices and Aliases with text provided
328329
await dispatch(getIndices(searchKey, dataSourceId));

public/redux/reducers/previewAnomalies.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const reducer = handleActions<PreviewAnomalies>(
5959
initialDetectorsState
6060
);
6161

62-
export const previewDetector = (requestBody: any, dataSourceId: string): APIAction => {
62+
export const previewDetector = (requestBody: any, dataSourceId: string = ''): APIAction => {
6363
const baseUrl = `..${AD_NODE_API.DETECTOR}/preview`;
6464
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
6565

public/redux/reducers/sampleData.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const reducer = handleActions<SampleDataState>(
5656

5757
export const createSampleData = (
5858
sampleDataType: SAMPLE_TYPE,
59-
dataSourceId: string
59+
dataSourceId: string = ''
6060
): APIAction => {
6161
const url = dataSourceId
6262
? `..${AD_NODE_API.CREATE_SAMPLE_DATA}/${sampleDataType}/${dataSourceId}`

0 commit comments

Comments
 (0)