Skip to content

Commit

Permalink
update actionOption attribution for all data soure components (opense…
Browse files Browse the repository at this point in the history
…arch-project#732)

Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Apr 29, 2024
1 parent 2643c14 commit 348a29c
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion public/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,5 @@ export interface ValidationSettingResponse {

export interface MDSStates {
queryParams: MDSQueryParams;
selectedDataSourceId: string;
selectedDataSourceId: string | undefined;
}
6 changes: 4 additions & 2 deletions public/pages/Dashboard/Container/DashboardOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function DashboardOverview(props: OverviewProps) {
queryParams,
selectedDataSourceId: queryParams.dataSourceId
? queryParams.dataSourceId
: '',
: undefined,
});

const getDetectorOptions = (detectorsIdMap: {
Expand Down Expand Up @@ -267,7 +267,9 @@ export function DashboardOverview(props: OverviewProps) {
componentType={'DataSourceSelectable'}
componentConfig={{
fullWidth: false,
activeOption: [{ id: MDSOverviewState.selectedDataSourceId }],
activeOption: MDSOverviewState.selectedDataSourceId !== undefined
? [{ id: MDSOverviewState.selectedDataSourceId }]
: undefined,
savedObjects: getSavedObjectsClient(),
notifications: getNotifications(),
onSelectedDataSources: (dataSources) =>
Expand Down
6 changes: 4 additions & 2 deletions public/pages/DefineDetector/containers/DefineDetector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const DefineDetector = (props: DefineDetectorProps) => {

const [MDSCreateState, setMDSCreateState] = useState<MDSStates>({
queryParams: MDSQueryParams,
selectedDataSourceId: dataSourceId ? dataSourceId : '',
selectedDataSourceId: dataSourceId ? dataSourceId : undefined,
});

// To handle backward compatibility, we need to pass some fields via
Expand Down Expand Up @@ -297,7 +297,9 @@ export const DefineDetector = (props: DefineDetectorProps) => {
componentType={'DataSourceSelectable'}
componentConfig={{
fullWidth: false,
activeOption: [{ id: MDSCreateState.selectedDataSourceId }],
activeOption: MDSCreateState.selectedDataSourceId !== undefined
? [{ id: MDSCreateState.selectedDataSourceId }]
: undefined,
savedObjects: getSavedObjectsClient(),
notifications: getNotifications(),
onSelectedDataSources: (dataSources) =>
Expand Down
8 changes: 5 additions & 3 deletions public/pages/DetectorsList/containers/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ interface ListState {
queryParams: GetDetectorsQueryParams;
selectedDetectorStates: DETECTOR_STATE[];
selectedIndices: string[];
selectedDataSourceId: string;
selectedDataSourceId: string | undefined;
}
interface ConfirmModalState {
isOpen: boolean;
Expand Down Expand Up @@ -208,7 +208,7 @@ export const DetectorList = (props: ListProps) => {
: ALL_INDICES,
selectedDataSourceId: queryParams.dataSourceId
? queryParams.dataSourceId
: '',
: undefined,
});

// Set breadcrumbs on page initialization
Expand Down Expand Up @@ -681,7 +681,9 @@ export const DetectorList = (props: ListProps) => {
componentType={'DataSourceSelectable'}
componentConfig={{
fullWidth: false,
activeOption: [{ id: state.selectedDataSourceId }],
activeOption: state.selectedDataSourceId !== undefined
? [{ id: state.selectedDataSourceId }]
: undefined,
savedObjects: getSavedObjectsClient(),
notifications: getNotifications(),
onSelectedDataSources: (dataSources) =>
Expand Down
6 changes: 4 additions & 2 deletions public/pages/Overview/containers/AnomalyDetectionOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function AnomalyDetectionOverview(props: AnomalyDetectionOverviewProps) {
queryParams,
selectedDataSourceId: queryParams.dataSourceId
? queryParams.dataSourceId
: '',
: undefined,
});

// Set breadcrumbs on page initialization
Expand Down Expand Up @@ -242,7 +242,9 @@ export function AnomalyDetectionOverview(props: AnomalyDetectionOverviewProps) {
componentType={'DataSourceSelectable'}
componentConfig={{
fullWidth: false,
activeOption: [{ id: MDSOverviewState.selectedDataSourceId }],
activeOption: MDSOverviewState.selectedDataSourceId !== undefined
? [{ id: MDSOverviewState.selectedDataSourceId }]
: undefined,
savedObjects: getSavedObjectsClient(),
notifications: getNotifications(),
onSelectedDataSources: (dataSources) =>
Expand Down
6 changes: 3 additions & 3 deletions public/pages/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const formatNumber = (data: any) => {
};

export const getAllDetectorsQueryParamsWithDataSourceId = (
dataSourceId: string
dataSourceId: string = ''
) => ({
from: 0,
search: '',
Expand All @@ -131,7 +131,7 @@ export const getAllDetectorsQueryParamsWithDataSourceId = (
});

export const getSampleDetectorsQueryParamsWithDataSouceId = (
dataSourceId: string
dataSourceId: string = ''
) => ({
from: 0,
search: 'sample',
Expand All @@ -152,7 +152,7 @@ export const getDataSourceFromURL = (location: {

export const constructHrefWithDataSourceId = (
basePath: string,
dataSourceId: string,
dataSourceId: string = '',
withHash: Boolean
): string => {
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;
Expand Down
29 changes: 16 additions & 13 deletions public/redux/reducers/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ const reducer = handleActions<Detectors>(

export const createDetector = (
requestBody: Detector,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const url = dataSourceId
? `..${AD_NODE_API.DETECTOR}/${dataSourceId}`
Expand All @@ -389,7 +389,7 @@ export const createDetector = (
export const validateDetector = (
requestBody: Detector,
validationType: string,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/_validate/${validationType}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -405,7 +405,7 @@ export const validateDetector = (

export const getDetector = (
detectorId: string,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -420,9 +420,11 @@ export const getDetector = (
export const getDetectorList = (
queryParams: GetDetectorsQueryParams
): APIAction => {
const dataSourceId = queryParams.dataSourceId || '';

const baseUrl = `..${AD_NODE_API.DETECTOR}/_list`;
const url = queryParams.dataSourceId
? `${baseUrl}/${queryParams.dataSourceId}`
const url = dataSourceId
? `${baseUrl}/${dataSourceId}`
: baseUrl;

return {
Expand All @@ -442,7 +444,7 @@ export const searchDetector = (requestBody: any): APIAction => ({
export const updateDetector = (
detectorId: string,
requestBody: Detector,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -459,7 +461,7 @@ export const updateDetector = (

export const deleteDetector = (
detectorId: string,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -473,7 +475,7 @@ export const deleteDetector = (

export const startDetector = (
detectorId: string,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/start`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -487,7 +489,7 @@ export const startDetector = (

export const startHistoricalDetector = (
detectorId: string,
dataSourceId: string,
dataSourceId: string = '',
startTime: number,
endTime: number
): APIAction => {
Expand All @@ -513,7 +515,7 @@ export const startHistoricalDetector = (

export const stopDetector = (
detectorId: string,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/stop/${false}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -527,7 +529,7 @@ export const stopDetector = (

export const stopHistoricalDetector = (
detectorId: string,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorId}/stop/${true}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -548,7 +550,8 @@ export const getDetectorProfile = (detectorId: string): APIAction => ({

export const matchDetector = (
detectorName: string,
dataSourceId: string): APIAction => {
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API.DETECTOR}/${detectorName}/_match`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;

Expand All @@ -558,7 +561,7 @@ export const matchDetector = (
};
};

export const getDetectorCount = (dataSourceId: string): APIAction => {
export const getDetectorCount = (dataSourceId: string = ''): APIAction => {
const url = dataSourceId ?
`..${AD_NODE_API.DETECTOR}/_count/${dataSourceId}` :
`..${AD_NODE_API.DETECTOR}/_count`;
Expand Down
4 changes: 2 additions & 2 deletions public/redux/reducers/alerting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const reducer = handleActions<Monitors>(
initialDetectorsState
);

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

Expand All @@ -108,7 +108,7 @@ export const searchAlerts = (
monitorId: string,
startTime: number,
endTime: number,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${ALERTING_NODE_API.ALERTS}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand Down
4 changes: 2 additions & 2 deletions public/redux/reducers/anomalyResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const reducer = handleActions<Anomalies>(

export const getDetectorResults = (
id: string,
dataSourceId: string,
dataSourceId: string = '',
queryParams: any,
isHistorical: boolean,
resultIndex: string,
Expand All @@ -119,7 +119,7 @@ export const getDetectorResults = (
export const searchResults = (
requestBody: any,
resultIndex: string,
dataSourceId: string,
dataSourceId: string = '',
onlyQueryCustomResultIndex: boolean
): APIAction => {
let baseUrl = `..${AD_NODE_API.DETECTOR}/results/_search`;
Expand Down
13 changes: 7 additions & 6 deletions public/redux/reducers/opensearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { getPathsPerDataType } from './mapper';
import { CatIndex, IndexAlias } from '../../../server/models/types';
import { AD_NODE_API } from '../../../utils/constants';
import { get } from 'lodash';
import { data } from 'jquery';

const GET_INDICES = 'opensearch/GET_INDICES';
const GET_ALIASES = 'opensearch/GET_ALIASES';
Expand Down Expand Up @@ -246,7 +247,7 @@ const reducer = handleActions<OpenSearchState>(
initialState
);

export const getIndices = (searchKey = '', dataSourceId: string) => {
export const getIndices = (searchKey = '', dataSourceId: string = '') => {
const baseUrl = `..${AD_NODE_API._INDICES}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;

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

export const getAliases = (
searchKey: string = '',
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const baseUrl = `..${AD_NODE_API._ALIASES}`;
const url = dataSourceId ? `${baseUrl}/${dataSourceId}` : baseUrl;
Expand All @@ -271,7 +272,7 @@ export const getAliases = (
};
};

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

return {
Expand All @@ -291,7 +292,7 @@ export const searchOpenSearch = (requestData: any): APIAction => ({
}),
});

export const createIndex = (indexConfig: any, dataSourceId: string): APIAction => {
export const createIndex = (indexConfig: any, dataSourceId: string = ''): APIAction => {
const url = dataSourceId
? `${AD_NODE_API.CREATE_INDEX}/${dataSourceId}`
: AD_NODE_API.CREATE_INDEX;
Expand All @@ -304,7 +305,7 @@ export const createIndex = (indexConfig: any, dataSourceId: string): APIAction =
};
};

export const bulk = (body: any, dataSourceId: string): APIAction => {
export const bulk = (body: any, dataSourceId: string = ''): APIAction => {
const url = dataSourceId
? `${AD_NODE_API.BULK}/${dataSourceId}`
: AD_NODE_API.BULK;
Expand All @@ -322,7 +323,7 @@ export const deleteIndex = (index: string): APIAction => ({
});

export const getPrioritizedIndices =
(searchKey: string, dataSourceId: string): ThunkAction =>
(searchKey: string, dataSourceId: string = ''): ThunkAction =>
async (dispatch, getState) => {
//Fetch Indices and Aliases with text provided
await dispatch(getIndices(searchKey, dataSourceId));
Expand Down
2 changes: 1 addition & 1 deletion public/redux/reducers/previewAnomalies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const reducer = handleActions<PreviewAnomalies>(
initialDetectorsState
);

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

Expand Down
2 changes: 1 addition & 1 deletion public/redux/reducers/sampleData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const reducer = handleActions<SampleDataState>(

export const createSampleData = (
sampleDataType: SAMPLE_TYPE,
dataSourceId: string
dataSourceId: string = ''
): APIAction => {
const url = dataSourceId
? `..${AD_NODE_API.CREATE_SAMPLE_DATA}/${sampleDataType}/${dataSourceId}`
Expand Down

0 comments on commit 348a29c

Please sign in to comment.