Skip to content

Commit

Permalink
querymanager types added, renamed to qm
Browse files Browse the repository at this point in the history
Signed-off-by: Ramneet Chopra <ramneet_chopra@persistent.com>
  • Loading branch information
ramneet-persistent committed Sep 20, 2022
1 parent d0603e7 commit 248e73d
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 40 deletions.
38 changes: 34 additions & 4 deletions dashboards-observability/common/types/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { History } from 'history';
import Plotly from 'plotly.js-dist';
import { QueryManager } from 'common/query_manager';
import {
RAW_QUERY,
SELECTED_FIELDS,
Expand All @@ -16,12 +17,18 @@ import {
SELECTED_TIMESTAMP,
SELECTED_DATE_RANGE,
} from '../constants/explorer';
import { CoreStart, HttpSetup, HttpStart, NotificationsStart } from '../../../../src/core/public';
import {
CoreStart,
CoreSetup,
HttpSetup,
HttpStart,
NotificationsStart,
} from '../../../../src/core/public';
import SavedObjects from '../../public/services/saved_objects/event_analytics/saved_objects';
import TimestampUtils from '../../public/services/timestamp/timestamp';
import PPLService from '../../public/services/requests/ppl';
import DSLService from '../../public/services/requests/dsl';

import { SavedObjectsStart } from '../../../../src/core/public/saved_objects';
export interface IQueryTab {
id: string;
name: React.ReactNode | string;
Expand Down Expand Up @@ -90,7 +97,7 @@ export interface ILogExplorerProps {
) => void;
savedObjectId: string;
getExistingEmptyTab: (params: EmptyTabParams) => string;
queryManager: any;
qm: QueryManager;
}

export interface IExplorerProps {
Expand Down Expand Up @@ -121,7 +128,7 @@ export interface IExplorerProps {
appBaseQuery?: string;
callback?: any;
callbackInApp?: any;
queryManager: any;
qm: QueryManager;
}

export interface SavedQuery {
Expand Down Expand Up @@ -292,3 +299,26 @@ export interface ConfigList {
breakdowns?: ConfigListEntry[] | HistogramConfigList[];
span?: DimensionSpan;
}

export interface Breadcrumbs {
text: string;
href: string;
}

export interface EventAnalyticsProps {
chrome: CoreSetup;
parentBreadcrumbs: Breadcrumbs[];
pplService: any;
dslService: any;
savedObjects: SavedObjectsStart;
timestampUtils: TimestampUtils;
http: HttpStart;
notifications: NotificationsStart;
qm: QueryManager;
}

export interface DataConfigPanelProps {
fieldOptionList: IField[];
visualizations: IVisualizationContainerProps;
qm?: QueryManager;
}
7 changes: 4 additions & 3 deletions dashboards-observability/public/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { I18nProvider } from '@osd/i18n/react';
import React from 'react';
import { Provider } from 'react-redux';
import { HashRouter, Route, Switch } from 'react-router-dom';
import { QueryManager } from 'common/query_manager';
import { CoreStart } from '../../../../src/core/public';
import { observabilityID, observabilityTitle } from '../../common/constants/shared';
import store from '../framework/redux/store';
Expand All @@ -24,7 +25,7 @@ interface ObservabilityAppDeps {
dslService: any;
savedObjects: any;
timestampUtils: any;
queryManagerInstance: any;
qm: QueryManager;
}

// for cypress to test redux store
Expand All @@ -39,7 +40,7 @@ export const App = ({
dslService,
savedObjects,
timestampUtils,
queryManagerInstance,
qm,
}: ObservabilityAppDeps) => {
const { chrome, http, notifications } = CoreStartProp;
const parentBreadcrumb = {
Expand Down Expand Up @@ -132,7 +133,7 @@ export const App = ({
timestampUtils={timestampUtils}
http={http}
notifications={notifications}
queryManager={queryManagerInstance}
qm={qm}
{...props}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export const Explorer = ({
setEndTime,
callback,
callbackInApp,
queryManager,
qm,
}: IExplorerProps) => {
const dispatch = useDispatch();
const requestParams = { tabId };
Expand Down Expand Up @@ -764,7 +764,7 @@ export const Explorer = ({
handleOverrideTimestamp={handleOverrideTimestamp}
callback={callbackForConfig}
changeIsValidConfigOptionState={changeIsValidConfigOptionState}
queryManager={queryManager}
qm={qm}
/>
);
};
Expand Down Expand Up @@ -842,7 +842,7 @@ export const Explorer = ({

if (selectedContentTabId === TAB_CHART_ID) {
// parse stats section on every search
const statsTokens = queryManager.queryParser().parse(tempQuery).getStats();
const statsTokens = qm.queryParser().parse(tempQuery).getStats();
const timeUnitValue = TIME_INTERVAL_OPTIONS.find(
(time_unit) => time_unit.value === statsTokens.groupby?.span.span_expression.time_unit
)?.text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const LogExplorer = ({
history,
notifications,
http,
queryManager,
qm,
}: ILogExplorerProps) => {
const dispatch = useDispatch();
const tabIds = useSelector(selectQueryTabs).queryTabIds.filter(
Expand Down Expand Up @@ -185,7 +185,7 @@ export const LogExplorer = ({
curSelectedTabId={curSelectedTabIdRef}
http={http}
searchBarConfigs={searchBarConfigs}
queryManager={queryManager}
qm={qm}
/>
</>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../../../../../../../../common/constants/explorer';
import { ButtonGroupItem } from './config_button_group';
import { visChartTypes } from '../../../../../../../../common/constants/shared';
import { ConfigList } from '../../../../../../../../common/types/explorer';
import { ConfigList, DataConfigPanelProps } from '../../../../../../../../common/types/explorer';
import { TabContext } from '../../../../../hooks';
import { composeAggregations } from '../../../../../../../../common/query_manager/utils';

Expand All @@ -46,7 +46,11 @@ const initialMetricEntry = {
aggregation: 'count',
};

export const DataConfigPanelItem = ({ fieldOptionList, visualizations, queryManager }: any) => {
export const DataConfigPanelItem = ({
fieldOptionList,
visualizations,
qm,
}: DataConfigPanelProps) => {
const dispatch = useDispatch();
const { tabId, handleQuerySearch, handleQueryChange, setTempQuery, fetchData } = useContext<any>(
TabContext
Expand Down Expand Up @@ -119,8 +123,8 @@ export const DataConfigPanelItem = ({ fieldOptionList, visualizations, queryMana
};

const updateChart = (updatedConfigList = configList) => {
const statsTokens = queryManager.queryParser().parse(data.query.rawQuery).getStats();
const newQuery = queryManager
const statsTokens = qm.queryParser().parse(data.query.rawQuery).getStats();
const newQuery = qm
.queryBuilder()
.build(data.query.rawQuery, composeAggregations(updatedConfigList, statsTokens));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,27 @@ import {
EuiText,
} from '@elastic/eui';
import { batch, useDispatch, useSelector } from 'react-redux';
import { cloneDeep } from 'lodash';
import {
AVAILABLE_FIELDS,
SELECTED_FIELDS,
} from '../../../../../../../../common/constants/explorer';
import { ConfigList, ConfigListEntry } from '../../../../../../../../common/types/explorer';
import {
ConfigList,
ConfigListEntry,
DataConfigPanelProps,
} from '../../../../../../../../common/types/explorer';
import { TabContext } from '../../../../../hooks';
import {
selectFields,
sortFields,
updateFields,
} from '../../../../../../event_analytics/redux/slices/field_slice';
import { cloneDeep } from 'lodash';

export const LogsViewConfigPanelItem = ({ fieldOptionList, visualizations }: any) => {
export const LogsViewConfigPanelItem = ({
fieldOptionList,
visualizations,
}: DataConfigPanelProps) => {
const dispatch = useDispatch();
const { tabId, curVisId, changeVisualizationConfig } = useContext<any>(TabContext);
const explorerFields = useSelector(selectFields)[tabId];
Expand Down Expand Up @@ -159,7 +166,7 @@ export const LogsViewConfigPanelItem = ({ fieldOptionList, visualizations }: any
};

const getLogsViewUI = () => {
let list = configList.dimensions ? configList.dimensions : [];
const list = configList.dimensions ? configList.dimensions : [];
const listUI = list.map((field, index) => (
<EuiFormRow
label="Field"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import { ConfigTreemapParentFields } from './config_treemap_parents';
import { numericalTypes, RAW_QUERY } from '../../../../../../../../common/constants/explorer';
import { TabContext } from '../../../../../hooks';
import { composeAggregations } from '../../../../../../../../common/query_manager/utils';
import { DataConfigPanelProps } from '../../../../../../../../common/types/explorer';

export const TreemapConfigPanelItem = ({
fieldOptionList,
visualizations,
tabID,
queryManager,
}: any) => {
qm,
}: DataConfigPanelProps) => {
const dispatch = useDispatch();
const { tabId, curVisId, changeVisualizationConfig, fetchData, handleQueryChange } = useContext<
any
Expand Down Expand Up @@ -72,8 +72,8 @@ export const TreemapConfigPanelItem = ({
};

const updateChart = (updatedConfigList = configList) => {
const statsTokens = queryManager.queryParser().parse(data.query.rawQuery).getStats();
const newQuery = queryManager
const statsTokens = qm.queryParser().parse(data.query.rawQuery).getStats();
const newQuery = qm
.queryBuilder()
.build(data.query.rawQuery, composeAggregations(updatedConfigList, statsTokens));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isEmpty } from 'lodash';

import React, { useContext } from 'react';
import { EuiPanel, EuiResizableContainer, EuiSpacer } from '@elastic/eui';
import { QueryManager } from 'common/query_manager';
import { RAW_QUERY, SELECTED_TIMESTAMP } from '../../../../../common/constants/explorer';
import {
IField,
Expand All @@ -24,6 +25,7 @@ import { TabContext } from '../../hooks';
import { PPL_STATS_REGEX, visChartTypes } from '../../../../../common/constants/shared';
import { TreemapConfigPanelItem } from './config_panel/config_panes/config_controls/treemap_config_panel_item';
import { LogsViewConfigPanelItem } from './config_panel/config_panes/config_controls/logs_view_config_panel_item';

interface IExplorerVisualizationsProps {
query: IQuery;
curVisId: string;
Expand All @@ -37,7 +39,7 @@ interface IExplorerVisualizationsProps {
handleOverrideTimestamp: (field: IField) => void;
callback?: any;
changeIsValidConfigOptionState: (isValidConfigOptionSelected: boolean) => void;
queryManager: any;
qm: QueryManager;
}

export const ExplorerVisualizations = ({
Expand All @@ -53,7 +55,7 @@ export const ExplorerVisualizations = ({
handleOverrideTimestamp,
callback,
changeIsValidConfigOptionState,
queryManager,
qm,
}: IExplorerVisualizationsProps) => {
const { tabId } = useContext<any>(TabContext);
const { data, vis } = visualizations;
Expand All @@ -70,25 +72,22 @@ export const ExplorerVisualizations = ({
<TreemapConfigPanelItem
fieldOptionList={fieldOptionList}
visualizations={visualizations}
tabID={tabId}
queryManager={queryManager}
qm={qm}
/>
);
case visChartTypes.LogsView:
return (
<LogsViewConfigPanelItem
fieldOptionList={fieldOptionList}
visualizations={visualizations}
tabID={tabId}
/>
);
default:
return (
<DataConfigPanelItem
fieldOptionList={fieldOptionList}
visualizations={visualizations}
tabID={tabId}
queryManager={queryManager}
qm={qm}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { EuiGlobalToastList } from '@elastic/eui';
import { Toast } from '@elastic/eui/src/components/toast/global_toast_list';
import { EmptyTabParams } from 'common/types/explorer';
import { EmptyTabParams, EventAnalyticsProps } from 'common/types/explorer';
import { isEmpty } from 'lodash';
import React, { ReactChild, useState } from 'react';
import { HashRouter, Route, Switch, useHistory } from 'react-router-dom';
Expand All @@ -23,9 +23,9 @@ export const EventAnalytics = ({
timestampUtils,
http,
notifications,
queryManager,
qm,
...props
}: any) => {
}: EventAnalyticsProps) => {
const history = useHistory();
const [toasts, setToasts] = useState<Toast[]>([]);

Expand Down Expand Up @@ -85,7 +85,7 @@ export const EventAnalytics = ({
getExistingEmptyTab={getExistingEmptyTab}
history={history}
notifications={notifications}
queryManager={queryManager}
qm={qm}
/>
);
}}
Expand Down
5 changes: 3 additions & 2 deletions dashboards-observability/public/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { QueryManager } from 'common/query_manager';
import { AppMountParameters, CoreStart } from '../../../../src/core/public';
import { AppPluginStartDependencies } from '../types';
import { App } from './app';
Expand All @@ -17,7 +18,7 @@ export const Observability = (
dslService: any,
savedObjects: any,
timestampUtils: any,
queryManagerInstance: any
qm: QueryManager
) => {
ReactDOM.render(
<App
Expand All @@ -27,7 +28,7 @@ export const Observability = (
dslService={dslService}
savedObjects={savedObjects}
timestampUtils={timestampUtils}
queryManagerInstance={queryManagerInstance}
qm={qm}
/>,
AppMountParametersProp.element
);
Expand Down
4 changes: 2 additions & 2 deletions dashboards-observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class ObservabilityPlugin implements Plugin<ObservabilitySetup, Observabi
const dslService = new DSLService(coreStart.http);
const savedObjects = new SavedObjects(coreStart.http);
const timestampUtils = new TimestampUtils(dslService);
const queryManagerInstance = new QueryManager();
const qm = new QueryManager();
return Observability(
coreStart,
depsStart as AppPluginStartDependencies,
Expand All @@ -57,7 +57,7 @@ export class ObservabilityPlugin implements Plugin<ObservabilitySetup, Observabi
dslService,
savedObjects,
timestampUtils,
queryManagerInstance
qm
);
},
});
Expand Down

0 comments on commit 248e73d

Please sign in to comment.