Skip to content

Commit c616873

Browse files
committed
addressing comments
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent 863e0d2 commit c616873

File tree

24 files changed

+68
-69
lines changed

24 files changed

+68
-69
lines changed

public/components/CreateDetectorButtons/CreateDetectorButtons.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import { constructHrefWithDataSourceId, getDataSourceFromURL } from '../../pages
1717

1818
export const CreateDetectorButtons = () => {
1919
const location = useLocation();
20-
const neoQueryParams = getDataSourceFromURL(location);
21-
const dataSourceId = neoQueryParams.dataSourceId;
20+
const MDSQueryParams = getDataSourceFromURL(location);
21+
const dataSourceId = MDSQueryParams.dataSourceId;
2222

2323
const createDetectorUrl = `${PLUGIN_NAME}#` + constructHrefWithDataSourceId(`${APP_PATH.CREATE_DETECTOR}`, dataSourceId, false);
2424

public/models/interfaces.ts

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DATA_TYPES } from '../utils/constants';
1414
import { DETECTOR_STATE } from '../../server/utils/constants';
1515
import { Duration } from 'moment';
1616
import moment from 'moment';
17+
import { MDSQueryParams } from '../../server/models/types';
1718

1819
export type FieldInfo = {
1920
label: string;
@@ -326,3 +327,8 @@ export interface ValidationSettingResponse {
326327
message: string;
327328
validationType: string;
328329
}
330+
331+
export interface MDSStates {
332+
queryParams: MDSQueryParams;
333+
selectedDataSourceId: string;
334+
}

public/pages/AnomalyCharts/containers/AnomalyDetailsChart.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ export const AnomalyDetailsChart = React.memo(
124124
(props: AnomalyDetailsChartProps) => {
125125
const dispatch = useDispatch();
126126
const location = useLocation();
127-
const neoQueryParams = getDataSourceFromURL(location);
128-
const dataSourceId = neoQueryParams.dataSourceId;
127+
const MDSQueryParams = getDataSourceFromURL(location);
128+
const dataSourceId = MDSQueryParams.dataSourceId;
129129
const [showAlertsFlyout, setShowAlertsFlyout] = useState<boolean>(false);
130130
const [alertAnnotations, setAlertAnnotations] = useState<any[]>([]);
131131
const [isLoadingAlerts, setIsLoadingAlerts] = useState<boolean>(false);

public/pages/ConfigureModel/containers/ConfigureModel.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ export function ConfigureModel(props: ConfigureModelProps) {
8888
const core = React.useContext(CoreServicesContext) as CoreStart;
8989
const dispatch = useDispatch();
9090
const location = useLocation();
91-
const neoQueryParams = getDataSourceFromURL(location);
91+
const MDSQueryParams = getDataSourceFromURL(location);
9292
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;
93-
const dataSourceId = neoQueryParams.dataSourceId;
93+
const dataSourceId = MDSQueryParams.dataSourceId;
9494

9595
useHideSideNavBar(true, false);
9696
const detectorId = get(props, 'match.params.detectorId', '');

public/pages/ConfigureModel/containers/SampleAnomalies.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export function SampleAnomalies(props: SampleAnomaliesProps) {
6565
const core = React.useContext(CoreServicesContext) as CoreStart;
6666
const dispatch = useDispatch();
6767
const location = useLocation();
68-
const neoQueryParams = getDataSourceFromURL(location);
69-
const dataSourceId = neoQueryParams.dataSourceId;
68+
const MDSQueryParams = getDataSourceFromURL(location);
69+
const dataSourceId = MDSQueryParams.dataSourceId;
7070
useHideSideNavBar(true, false);
7171

7272
const [isLoading, setIsLoading] = useState<boolean>(false);

public/pages/Dashboard/Components/AnomaliesDistribution.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export const AnomaliesDistributionChart = (
4444
) => {
4545
const dispatch = useDispatch();
4646
const location = useLocation();
47-
const neoQueryParams = getDataSourceFromURL(location);
48-
const dataSourceId = neoQueryParams.dataSourceId;
47+
const MDSQueryParams = getDataSourceFromURL(location);
48+
const dataSourceId = MDSQueryParams.dataSourceId;
4949

5050
const [anomalyDistribution, setAnomalyDistribution] = useState(
5151
[] as object[]

public/pages/Dashboard/Components/AnomaliesLiveChart.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ const MAX_LIVE_DETECTORS = 10;
7575
export const AnomaliesLiveChart = (props: AnomaliesLiveChartProps) => {
7676
const dispatch = useDispatch();
7777
const location = useLocation();
78-
const neoQueryParams = getDataSourceFromURL(location);
79-
const dataSourceId = neoQueryParams.dataSourceId;
78+
const MDSQueryParams = getDataSourceFromURL(location);
79+
const dataSourceId = MDSQueryParams.dataSourceId;
8080
const [liveTimeRange, setLiveTimeRange] = useState<LiveTimeRangeState>({
8181
startDateTime: moment().subtract(31, 'minutes'),
8282
endDateTime: moment(),

public/pages/Dashboard/Components/utils/DashboardHeader.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export interface DashboardHeaderProps {
2929

3030
export const DashboardHeader = (props: DashboardHeaderProps) => {
3131
const location = useLocation();
32-
const neoQueryParams = getDataSourceFromURL(location);
33-
const dataSourceId = neoQueryParams.dataSourceId;
32+
const MDSQueryParams = getDataSourceFromURL(location);
33+
const dataSourceId = MDSQueryParams.dataSourceId;
3434
const createDetectorUrl = `${PLUGIN_NAME}#` + constructHrefWithDataSourceId(APP_PATH.CREATE_DETECTOR, dataSourceId, false);
3535

3636
return (

public/pages/Dashboard/Container/DashboardOverview.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import queryString from 'querystring';
1717
import { useDispatch, useSelector } from 'react-redux';
1818
import { get, isEmpty, cloneDeep } from 'lodash';
1919

20-
import { DetectorListItem } from '../../../models/interfaces';
20+
import { DetectorListItem, MDSStates } from '../../../models/interfaces';
2121
import { getIndices, getAliases } from '../../../redux/reducers/opensearch';
2222
import { getDetectorList } from '../../../redux/reducers/ad';
2323
import {
@@ -38,7 +38,6 @@ import { AppState } from '../../../redux/reducers';
3838
import {
3939
CatIndex,
4040
IndexAlias,
41-
MDSQueryParams,
4241
} from '../../../../server/models/types';
4342
import {
4443
getAllDetectorsQueryParamsWithDataSourceId,
@@ -71,11 +70,6 @@ interface OverviewProps extends RouteComponentProps {
7170
setActionMenu: (menuMount: MountPoint | undefined) => void;
7271
}
7372

74-
interface MDSOverviewState {
75-
queryParams: MDSQueryParams;
76-
selectedDataSourceId: string;
77-
}
78-
7973
export function DashboardOverview(props: OverviewProps) {
8074
const core = React.useContext(CoreServicesContext) as CoreStart;
8175
const dispatch = useDispatch();
@@ -95,7 +89,7 @@ export function DashboardOverview(props: OverviewProps) {
9589
[] as string[]
9690
);
9791
const queryParams = getDataSourceFromURL(props.location);
98-
const [MDSOverviewState, setMDSOverviewState] = useState<MDSOverviewState>({
92+
const [MDSOverviewState, setMDSOverviewState] = useState<MDSStates>({
9993
queryParams,
10094
selectedDataSourceId: queryParams.dataSourceId
10195
? queryParams.dataSourceId

public/pages/DefineDetector/components/Datasource/DataSource.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ interface DataSourceProps {
5151
export function DataSource(props: DataSourceProps) {
5252
const dispatch = useDispatch();
5353
const location = useLocation();
54-
const neoQueryParams = getDataSourceFromURL(location);
55-
const dataSourceId = neoQueryParams.dataSourceId;
54+
const MDSQueryParams = getDataSourceFromURL(location);
55+
const dataSourceId = MDSQueryParams.dataSourceId;
5656
const [indexName, setIndexName] = useState<string>(
5757
props.formikProps.values.index[0]?.label
5858
);

public/pages/DefineDetector/components/Timestamp/Timestamp.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ interface TimestampProps {
3333
export function Timestamp(props: TimestampProps) {
3434
const dispatch = useDispatch();
3535
const location = useLocation();
36-
const neoQueryParams = getDataSourceFromURL(location);
37-
const dataSourceId = neoQueryParams.dataSourceId;
36+
const MDSQueryParams = getDataSourceFromURL(location);
37+
const dataSourceId = MDSQueryParams.dataSourceId;
3838
const opensearchState = useSelector((state: AppState) => state.opensearch);
3939
const selectedIndex = get(props, 'formikProps.values.index.0.label', '');
4040
const isRemoteIndex = selectedIndex.includes(':');

public/pages/DefineDetector/containers/DefineDetector.tsx

+5-11
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import {
5252
clearModelConfiguration,
5353
} from '../utils/helpers';
5454
import { DetectorDefinitionFormikValues } from '../models/interfaces';
55-
import { Detector, FILTER_TYPES } from '../../../models/interfaces';
55+
import { Detector, FILTER_TYPES, MDSStates } from '../../../models/interfaces';
5656
import { prettifyErrorMessage } from '../../../../server/utils/helpers';
5757
import { DETECTOR_STATE } from '../../../../server/utils/constants';
5858
import { ModelConfigurationFormikValues } from 'public/pages/ConfigureModel/models/interfaces';
@@ -63,7 +63,6 @@ import {
6363
getSavedObjectsClient,
6464
} from '../../../services';
6565
import { DataSourceSelectableConfig, DataSourceViewConfig } from '../../../../../../src/plugins/data_source_management/public';
66-
import { MDSQueryParams } from '../../../../server/models/types';
6766
import {
6867
constructHrefWithDataSourceId,
6968
getDataSourceFromURL,
@@ -74,11 +73,6 @@ interface DefineDetectorRouterProps {
7473
detectorId?: string;
7574
}
7675

77-
interface MDSCreateState {
78-
queryParams: MDSQueryParams;
79-
selectedDataSourceId: string;
80-
}
81-
8276
interface DefineDetectorProps
8377
extends RouteComponentProps<DefineDetectorRouterProps> {
8478
isEdit: boolean;
@@ -91,8 +85,8 @@ interface DefineDetectorProps
9185

9286
export const DefineDetector = (props: DefineDetectorProps) => {
9387
const location = useLocation();
94-
const neoQueryParams = getDataSourceFromURL(location);
95-
const dataSourceId = neoQueryParams.dataSourceId;
88+
const MDSQueryParams = getDataSourceFromURL(location);
89+
const dataSourceId = MDSQueryParams.dataSourceId;
9690
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;
9791

9892
const core = React.useContext(CoreServicesContext) as CoreStart;
@@ -102,8 +96,8 @@ export const DefineDetector = (props: DefineDetectorProps) => {
10296
const { detector, hasError } = useFetchDetectorInfo(detectorId, dataSourceId);
10397
const [newIndexSelected, setNewIndexSelected] = useState<boolean>(false);
10498

105-
const [MDSCreateState, setMDSCreateState] = useState<MDSCreateState>({
106-
queryParams: neoQueryParams,
99+
const [MDSCreateState, setMDSCreateState] = useState<MDSStates>({
100+
queryParams: MDSQueryParams,
107101
selectedDataSourceId: dataSourceId ? dataSourceId : '',
108102
});
109103

public/pages/DetectorConfig/containers/DetectorConfig.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ interface DetectorConfigProps extends RouteComponentProps {
3030
export function DetectorConfig(props: DetectorConfigProps) {
3131
const dispatch = useDispatch();
3232
const location = useLocation();
33-
const neoQueryParams = getDataSourceFromURL(location);
34-
const dataSourceId = neoQueryParams.dataSourceId;
33+
const MDSQueryParams = getDataSourceFromURL(location);
34+
const dataSourceId = MDSQueryParams.dataSourceId;
3535
const detector = useSelector(
3636
(state: AppState) => state.ad.detectors[props.detectorId]
3737
);

public/pages/DetectorDetail/containers/DetectorDetail.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
120120
const detectorId = get(props, 'match.params.detectorId', '') as string;
121121
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;
122122
const location = useLocation();
123-
const neoQueryParams = getDataSourceFromURL(location);
124-
const dataSourceId = neoQueryParams.dataSourceId;
123+
const MDSQueryParams = getDataSourceFromURL(location);
124+
const dataSourceId = MDSQueryParams.dataSourceId;
125125

126126
const { detector, hasError, isLoadingDetector, errorMessage } =
127127
useFetchDetectorInfo(detectorId, dataSourceId);

public/pages/DetectorJobs/containers/DetectorJobs.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ interface DetectorJobsProps extends RouteComponentProps {
5555
export function DetectorJobs(props: DetectorJobsProps) {
5656
const core = React.useContext(CoreServicesContext) as CoreStart;
5757
const location = useLocation();
58-
const neoQueryParams = getDataSourceFromURL(location);
58+
const MDSQueryParams = getDataSourceFromURL(location);
5959
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;
60-
const dataSourceId = neoQueryParams.dataSourceId;
60+
const dataSourceId = MDSQueryParams.dataSourceId;
6161
useHideSideNavBar(true, false);
6262

6363
const [realTime, setRealTime] = useState<boolean>(

public/pages/DetectorResults/containers/AnomalyHistory.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ export const AnomalyHistory = (props: AnomalyHistoryProps) => {
129129
? props.detector.detectionDateRange.endTime
130130
: moment().valueOf();
131131
const location = useLocation();
132-
const neoQueryParams = getDataSourceFromURL(location);
133-
const dataSourceId = neoQueryParams.dataSourceId;
132+
const MDSQueryParams = getDataSourceFromURL(location);
133+
const dataSourceId = MDSQueryParams.dataSourceId;
134134
const [dateRange, setDateRange] = useState<DateRange>({
135135
startDate: initialStartDate,
136136
endDate: initialEndDate,

public/pages/DetectorResults/containers/AnomalyResults.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export function AnomalyResults(props: AnomalyResultsProps) {
8686
(state: AppState) => state.ad.detectors[detectorId]
8787
);
8888
const location = useLocation();
89-
const neoQueryParams = getDataSourceFromURL(location);
90-
const dataSourceId = neoQueryParams.dataSourceId;
89+
const MDSQueryParams = getDataSourceFromURL(location);
90+
const dataSourceId = MDSQueryParams.dataSourceId;
9191

9292
useEffect(() => {
9393
core.chrome.setBreadcrumbs([

public/pages/DetectorResults/containers/AnomalyResultsLiveChart.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ export const AnomalyResultsLiveChart = (
6868
) => {
6969
const dispatch = useDispatch();
7070
const location = useLocation();
71-
const neoQueryParams = getDataSourceFromURL(location);
72-
const dataSourceId = neoQueryParams.dataSourceId;
71+
const MDSQueryParams = getDataSourceFromURL(location);
72+
const dataSourceId = MDSQueryParams.dataSourceId;
7373

7474
const [firstLoading, setFirstLoading] = useState<boolean>(true);
7575
const [isFullScreen, setIsFullScreen] = useState<boolean>(false);

public/pages/HistoricalDetectorResults/containers/HistoricalDetectorResults.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ export function HistoricalDetectorResults(
6464
const dispatch = useDispatch();
6565
const detectorId: string = get(props, 'match.params.detectorId', '');
6666
const location = useLocation();
67-
const neoQueryParams = getDataSourceFromURL(location);
68-
const dataSourceId = neoQueryParams.dataSourceId;
67+
const MDSQueryParams = getDataSourceFromURL(location);
68+
const dataSourceId = MDSQueryParams.dataSourceId;
6969

7070
const adState = useSelector((state: AppState) => state.ad);
7171
const allDetectors = adState.detectors;

public/pages/Overview/components/SampleDataBox/SampleDataBox.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ interface SampleDataBoxProps {
4040

4141
export const SampleDataBox = (props: SampleDataBoxProps) => {
4242
const location = useLocation();
43-
const neoQueryParams = getDataSourceFromURL(location);
44-
const dataSourceId = neoQueryParams.dataSourceId;
43+
const MDSQueryParams = getDataSourceFromURL(location);
44+
const dataSourceId = MDSQueryParams.dataSourceId;
4545

4646
return (
4747
<div style={{ height: 'auto' }}>

public/pages/Overview/containers/AnomalyDetectionOverview.tsx

+2-7
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,15 @@ import {
6262
getNotifications,
6363
getSavedObjectsClient,
6464
} from '../../../../public/services';
65-
import { MDSQueryParams } from 'server/models/types';
6665
import { RouteComponentProps } from 'react-router-dom';
6766
import queryString from 'querystring';
6867
import { getDataSourceFromURL, getSampleDetectorsQueryParamsWithDataSouceId } from '../../../../public/pages/utils/helpers';
68+
import { MDSStates } from '../../../models/interfaces';
6969

7070
interface AnomalyDetectionOverviewProps extends RouteComponentProps {
7171
setActionMenu: (menuMount: MountPoint | undefined) => void;
7272
}
7373

74-
interface MDSOverviewState {
75-
queryParams: MDSQueryParams;
76-
selectedDataSourceId: string;
77-
}
78-
7974
export function AnomalyDetectionOverview(props: AnomalyDetectionOverviewProps) {
8075
const core = React.useContext(CoreServicesContext) as CoreStart;
8176
const isLoadingSampleDetectors = useSelector(
@@ -105,7 +100,7 @@ export function AnomalyDetectionOverview(props: AnomalyDetectionOverviewProps) {
105100
useState<boolean>(false);
106101

107102
const queryParams = getDataSourceFromURL(props.location);
108-
const [MDSOverviewState, setMDSOverviewState] = useState<MDSOverviewState>({
103+
const [MDSOverviewState, setMDSOverviewState] = useState<MDSStates>({
109104
queryParams,
110105
selectedDataSourceId: queryParams.dataSourceId
111106
? queryParams.dataSourceId

public/pages/ReviewAndCreate/containers/ReviewAndCreate.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export function ReviewAndCreate(props: ReviewAndCreateProps) {
7575
const core = React.useContext(CoreServicesContext) as CoreStart;
7676
const dispatch = useDispatch();
7777
const location = useLocation();
78-
const neoQueryParams = getDataSourceFromURL(location);
79-
const dataSourceId = neoQueryParams.dataSourceId;
78+
const MDSQueryParams = getDataSourceFromURL(location);
79+
const dataSourceId = MDSQueryParams.dataSourceId;
8080
const dataSourceEnabled = getDataSourcePlugin()?.dataSourceEnabled || false;
8181
useHideSideNavBar(true, false);
8282

public/pages/utils/helpers.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from '../../../server/models/types';
1717
import sortBy from 'lodash/sortBy';
1818
import { DetectorListItem } from '../../models/interfaces';
19-
import { SORT_DIRECTION } from '../../../server/utils/constants';
19+
import { DETECTORS_QUERY_PARAMS, SORT_DIRECTION } from '../../../server/utils/constants';
2020
import { ALL_INDICES, ALL_DETECTOR_STATES, MAX_DETECTORS } from './constants';
2121
import { DETECTOR_STATE } from '../../../server/utils/constants';
2222
import { timeFormatter } from '@elastic/charts';
@@ -160,12 +160,12 @@ export const constructHrefWithDataSourceId = (
160160

161161
// Set up base parameters for '/detectors'
162162
if (basePath.startsWith('/detectors')) {
163-
url.set('from', '0');
164-
url.set('size', '20');
165-
url.set('search', '');
166-
url.set('indices', '');
167-
url.set('sortField', 'name');
168-
url.set('sortDirection', 'asc');
163+
url.set(DETECTORS_QUERY_PARAMS.FROM, '0');
164+
url.set(DETECTORS_QUERY_PARAMS.SIZE, '20');
165+
url.set(DETECTORS_QUERY_PARAMS.SEARCH, '');
166+
url.set(DETECTORS_QUERY_PARAMS.INDICES, '');
167+
url.set(DETECTORS_QUERY_PARAMS.SORT_FIELD, DETECTORS_QUERY_PARAMS.NAME);
168+
url.set(DETECTORS_QUERY_PARAMS.SORT_DIRECTION, SORT_DIRECTION.ASC);
169169
}
170170

171171
if (dataSourceEnabled && dataSourceId) {

server/utils/constants.ts

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ export enum SORT_DIRECTION {
4646
DESC = 'desc',
4747
}
4848

49+
export enum DETECTORS_QUERY_PARAMS {
50+
FROM = 'from',
51+
SIZE = 'size',
52+
SEARCH = 'search',
53+
INDICES = 'indices',
54+
SORT_FIELD = 'sortField',
55+
SORT_DIRECTION = 'sortDirection',
56+
NAME = 'name',
57+
}
58+
4959
export enum AD_DOC_FIELDS {
5060
DATA_START_TIME = 'data_start_time',
5161
DATA_END_TIME = 'data_end_time',

0 commit comments

Comments
 (0)