Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test ci #2

Open
wants to merge 6 commits into
base: improve-lint
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/constants/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,4 @@ export const DIRECT_DUMMY_QUERY = 'select 1';

export const DEFAULT_START_TIME = 'now-15m';
export const QUERY_ASSIST_START_TIME = 'now-40y';
export const QUERY_ASSIST_END_TIME = 'now';
export const QUERY_ASSIST_END_TIME = 'now';
4 changes: 2 additions & 2 deletions public/components/common/search/__tests__/search.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { configure, mount, shallow } from 'enzyme';
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { applyMiddleware, createStore } from '@reduxjs/toolkit';
Expand All @@ -13,7 +13,7 @@ import { Search } from '../search';
import thunk from 'redux-thunk';
import { initialTabId } from '../../../../framework/redux/store/shared_state';

describe.only('Explorer Search component', () => {
describe('Explorer Search component', () => {
configure({ adapter: new Adapter() });
const store = createStore(rootReducer, applyMiddleware(thunk));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
EuiSpacer,
EuiText,
} from '@elastic/eui';
import chatLogo from '../../datasources/icons/query-assistant-logo.svg';
import React from 'react';
import chatLogo from '../../datasources/icons/query-assistant-logo.svg';

export function QueryAssistSummarization({
queryAssistantSummarization,
setNlqInput,
showFlyout,
}: any) {

Check warning on line 26 in public/components/common/search/query_assist_summarization.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return (
<EuiPanel>
<EuiAccordion
Expand Down
35 changes: 4 additions & 31 deletions public/components/common/search/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
EuiButtonEmpty,
EuiComboBox,
EuiComboBoxOptionOption,
EuiContextMenuItem,
EuiContextMenuPanel,
EuiFlexGroup,
EuiFlexItem,
Expand Down Expand Up @@ -71,7 +70,7 @@
tempQuery: string;
handleQueryChange: (query: string) => void;
handleQuerySearch: () => void;
dslService: any;

Check warning on line 73 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface IDatePickerProps {
Expand All @@ -81,17 +80,16 @@
setEndTime: (end: string) => void;
setTimeRange: () => void;
setIsOutputStale: () => void;
handleTimePickerChange: (timeRange: string[]) => any;

Check warning on line 83 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
handleTimeRangePickerRefresh: () => any;

Check warning on line 84 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
isAppAnalytics: boolean;
}

export const Search = (props: any) => {

Check warning on line 88 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const {
query,
tempQuery,
handleQueryChange,
handleQuerySearch,
handleTimePickerChange,
dslService,
startTime,
Expand Down Expand Up @@ -134,7 +132,7 @@
const dispatch = useDispatch();
const appLogEvents = tabId.match(APP_ANALYTICS_TAB_ID_REGEX);
const [isSavePanelOpen, setIsSavePanelOpen] = useState(false);
const [isLanguagePopoverOpen, setLanguagePopoverOpen] = useState(false);
const [_isLanguagePopoverOpen, setLanguagePopoverOpen] = useState(false);
const [isFlyoutVisible, setIsFlyoutVisible] = useState(false);
const [queryLang, setQueryLang] = useState(QUERY_LANGUAGE.PPL);
const [timeRange, setTimeRange] = useState([
Expand All @@ -151,11 +149,11 @@

const {
data: pollingResult,
loading: pollingLoading,
loading: _pollingLoading,
error: pollingError,
startPolling,
startPolling: _startPolling,
stopPolling,
} = usePolling<any, any>((params) => {

Check warning on line 156 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type

Check warning on line 156 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return sqlService.fetchWithJobId(params);
}, 5000);

Expand Down Expand Up @@ -222,10 +220,6 @@
closeLanguagePopover();
};

const onLanguagePopoverClick = () => {
setLanguagePopoverOpen(!isLanguagePopoverOpen);
};

const closeLanguagePopover = () => {
setLanguagePopoverOpen(false);
};
Expand All @@ -235,28 +229,7 @@
{ value: QUERY_LANGUAGE.DQL, inputDisplay: <EuiText>DQL</EuiText> },
];

const languagePopOverItems = [
<EuiContextMenuItem
key={QUERY_LANGUAGE.PPL}
onClick={() => handleQueryLanguageChange(QUERY_LANGUAGE.PPL)}
>
PPL
</EuiContextMenuItem>,
<EuiContextMenuItem
key={QUERY_LANGUAGE.DQL}
onClick={() => handleQueryLanguageChange(QUERY_LANGUAGE.DQL)}
>
DQL
</EuiContextMenuItem>,
];

const languagePopOverButton = (
<EuiButton iconType="arrowDown" iconSide="right" onClick={onLanguagePopoverClick} color="text">
{queryLang}
</EuiButton>
);

const onQuerySearch = (lang) => {
const onQuerySearch = () => {
handleTimeRangePickerRefresh();
};

Expand All @@ -268,7 +241,7 @@
stopPolling();
setIsQueryRunning(false);
}
}, [pollingResult, pollingError]);

Check warning on line 244 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'dispatchOnGettingHis', 'setIsQueryRunning', and 'stopPolling'. Either include them or remove the dependency array

useEffect(() => {
// set index and olly query assistant question if changed elsewhere
Expand All @@ -294,7 +267,7 @@
})
);
}
}, [queryRedux.index, queryRedux.ollyQueryAssistant]);

Check warning on line 270 in public/components/common/search/search.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'dispatch', 'getAvailableFields', 'handleQueryChange', and 'props.tabId'. Either include them or remove the dependency array

const runChanges = () => {
batch(() => {
Expand Down
4 changes: 2 additions & 2 deletions public/components/common/search/sql_search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
tempQuery: string;
handleQueryChange: (query: string) => void;
handleQuerySearch: () => void;
dslService: any;

Check warning on line 48 in public/components/common/search/sql_search.tsx

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

export interface IDatePickerProps {
Expand Down Expand Up @@ -97,7 +97,7 @@

const {
data: pollingResult,
loading: pollingLoading,
loading: _pollingLoading,
error: pollingError,
startPolling,
stopPolling,
Expand Down Expand Up @@ -139,7 +139,7 @@
</EuiButton>
);

const handleQueryLanguageChange = (lang: string) => {
const handleQueryLanguageChange = (lang: QUERY_LANGUAGE) => {
if (lang === 'DQL') {
application!.navigateToUrl('../app/data-explorer/discover');
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,30 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React, { useMemo, useState, useRef, Fragment, useCallback, useEffect } from 'react';
import {
EuiDataGrid,
EuiDataGridColumn,
EuiDataGridSorting,
EuiDescriptionList,
EuiDescriptionListDescription,
EuiDescriptionListTitle,
EuiDataGridColumn,
EuiDataGridSorting,
EuiPanel,
EuiDataGridProps,
} from '@elastic/eui';
import moment from 'moment';
import { MutableRefObject } from 'react';
import { IExplorerFields, IField } from '../../../../../common/types/explorer';
import React, { Fragment, MutableRefObject, useEffect, useRef, useState } from 'react';
import { HttpSetup } from '../../../../../../../src/core/public';
import {
DATE_DISPLAY_FORMAT,
DEFAULT_EMPTY_EXPLORER_FIELDS,
DEFAULT_SOURCE_COLUMN,
DEFAULT_TIMESTAMP_COLUMN,
} from '../../../../../common/constants/explorer';
import { HttpSetup } from '../../../../../../../src/core/public';
import { IExplorerFields, IField } from '../../../../../common/types/explorer';
import PPLService from '../../../../services/requests/ppl';
import { FlyoutButton } from './docViewRow';
import { useFetchEvents } from '../../hooks';
import { redoQuery } from '../../utils/utils';
import { FlyoutButton } from './docViewRow';

export interface DataGridProps {
http: HttpSetup;
Expand Down
20 changes: 11 additions & 9 deletions public/components/event_analytics/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import {
getSavingCommonParams,
uiSettingsService,
} from '../../../../common/utils';
import { coreRefs } from '../../../framework/core_refs';
import { initialTabId } from '../../../framework/redux/store/shared_state';
import { PPLDataFetcher } from '../../../services/data_fetchers/ppl/ppl_data_fetcher';
import { getSavedObjectsClient } from '../../../services/saved_objects/saved_object_client/client_factory';
Expand Down Expand Up @@ -115,7 +116,7 @@ import {
change as updateVizConfig,
} from '../redux/slices/viualization_config_slice';
import { getDefaultVisConfig } from '../utils';
import { getContentTabTitle, getDateRange } from '../utils/utils';
import { formatError, getContentTabTitle, getDateRange } from '../utils/utils';
import { DataSourceSelection } from './datasources/datasources_selection';
import { DirectQueryRunning } from './direct_query_running';
import { DataGrid } from './events_views/data_grid';
Expand Down Expand Up @@ -161,7 +162,7 @@ export const Explorer = ({
requestParams,
});
const {
isEventsLoading: isPatternLoading,
isEventsLoading: _isPatternLoading,
getPatterns,
setDefaultPatternsField,
} = useFetchPatterns({
Expand All @@ -181,7 +182,7 @@ export const Explorer = ({
const [selectedCustomPanelOptions, setSelectedCustomPanelOptions] = useState([]);
const [selectedPanelName, setSelectedPanelName] = useState('');
const [curVisId, setCurVisId] = useState('bar');
const [isPanelTextFieldInvalid, setIsPanelTextFieldInvalid] = useState(false);
const [isPanelTextFieldInvalid, _setIsPanelTextFieldInvalid] = useState(false);
const [timeIntervalOptions, setTimeIntervalOptions] = useState(TIME_INTERVAL_OPTIONS);
const [isOverridingTimestamp, setIsOverridingTimestamp] = useState(false);
const [tempQuery, setTempQuery] = useState(query[RAW_QUERY]);
Expand Down Expand Up @@ -214,8 +215,8 @@ export const Explorer = ({
value: string;
}>();
const [subType, setSubType] = useState('visualization');
const [metricMeasure, setMetricMeasure] = useState('');
const [metricChecked, setMetricChecked] = useState(false);
const [_metricMeasure, setMetricMeasure] = useState('');
const [_metricChecked, setMetricChecked] = useState(false);
const queryRef = useRef();
const appBasedRef = useRef('');
appBasedRef.current = appBaseQuery;
Expand Down Expand Up @@ -273,10 +274,11 @@ export const Explorer = ({

const getErrorHandler = (title: string) => {
return (error: any) => {
// const formattedError = formatError(error.name, error.message, error.body.message);
// notifications.toasts.addError(formattedError, {
// title,
// });
if (coreRefs.summarizeEnabled) return;
const formattedError = formatError(error.name, error.message, error.body.message);
notifications.toasts.addError(formattedError, {
title,
});
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
EuiText,
EuiEmptyPrompt,
} from '@elastic/eui';
import { coreRefs } from '../../../framework/core_refs';
import { useSelector } from 'react-redux';
import { coreRefs } from '../../../framework/core_refs';
import { selectQueries } from '../redux/slices/query_slice';

export const NoResults = ({ tabId }: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,23 @@ describe('<QueryAssistInput /> spec', () => {
);
});

it('should not call summarize if disabled', async () => {
coreRefs.summarizeEnabled = false;
httpMock.post.mockRejectedValueOnce({ body: { statusCode: 429 } });

const { component } = renderQueryAssistInput();
await waitFor(() => {
fireEvent.click(component.getByTestId('query-assist-generate-and-run-button'));
});

expect(httpMock.post).toBeCalledWith(QUERY_ASSIST_API.GENERATE_PPL, {
body: '{"question":"test-input","index":"selected-test-index"}',
});
expect(httpMock.post).not.toBeCalledWith(QUERY_ASSIST_API.SUMMARIZE, expect.anything());
});

it('should call summarize for generate and run errors', async () => {
coreRefs.summarizeEnabled = true;
httpMock.post.mockRejectedValueOnce({ body: { statusCode: 429 } }).mockResolvedValueOnce({
summary: 'too many requests',
suggestedQuestions: ['1', '2'],
Expand Down
43 changes: 25 additions & 18 deletions public/components/event_analytics/explorer/query_assist/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ResponseError } from '@opensearch-project/opensearch/lib/errors';
import React, { useEffect, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RAW_QUERY } from '../../../../../common/constants/explorer';
import { QUERY_ASSIST_API } from '../../../../../common/constants/query_assist';
import { getOSDHttp } from '../../../../../common/utils';
import { coreRefs } from '../../../../framework/core_refs';
import chatLogo from '../../../datasources/icons/query-assistant-logo.svg';
Expand All @@ -34,7 +35,6 @@ import {
} from '../../redux/slices/query_assistant_summarization_slice';
import { reset, selectQueryResult } from '../../redux/slices/query_result_slice';
import { changeQuery, selectQueries } from '../../redux/slices/query_slice';
import { QUERY_ASSIST_API } from '../../../../../common/constants/query_assist';

interface SummarizationContext {
question: string;
Expand Down Expand Up @@ -87,21 +87,23 @@ export const QueryAssistInput: React.FC<Props> = (props) => {

useEffect(() => {
if (
summaryData.responseForSummaryStatus === 'success' ||
summaryData.responseForSummaryStatus === 'failure'
) {
void (async () => {
await dispatch(
changeSummary({
tabId: props.tabId,
data: {
summaryLoading: false,
},
})
);
if (explorerData.total > 0) generateSummary();
})();
}
props.nlqInput.trim().length === 0 ||
(summaryData.responseForSummaryStatus !== 'success' &&
summaryData.responseForSummaryStatus !== 'failure')
)
return;
void (async () => {
await dispatch(
changeSummary({
tabId: props.tabId,
data: {
summaryLoading: false,
},
})
);
if (explorerData.total > 0 || summaryData.responseForSummaryStatus === 'failure')
generateSummary();
})();
}, [summaryData.responseForSummaryStatus]);

const [barSelected, setBarSelected] = useState(false);
Expand Down Expand Up @@ -173,6 +175,7 @@ export const QueryAssistInput: React.FC<Props> = (props) => {
}
};
const generateSummary = async (context?: Partial<SummarizationContext>) => {
if (!coreRefs.summarizeEnabled) return;
try {
const isError = summaryData.responseForSummaryStatus === 'failure';
const summarizationContext: SummarizationContext = {
Expand Down Expand Up @@ -333,7 +336,9 @@ export const QueryAssistInput: React.FC<Props> = (props) => {
<EuiButton
isLoading={generating}
onClick={generatePPL}
isDisabled={generating || generatingOrRunning}
isDisabled={
generating || generatingOrRunning || props.nlqInput.trim().length === 0
}
iconSide="right"
fill={false}
data-test-subj="query-assist-generate-button"
Expand All @@ -346,7 +351,9 @@ export const QueryAssistInput: React.FC<Props> = (props) => {
<EuiButton
isLoading={generatingOrRunning}
onClick={runAndSummarize}
isDisabled={generating || generatingOrRunning}
isDisabled={
generating || generatingOrRunning || props.nlqInput.trim().length === 0
}
iconType="returnKey"
iconSide="right"
type="submit"
Expand Down
Loading
Loading