-
Notifications
You must be signed in to change notification settings - Fork 933
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
Fix object empty check and minor perf issue in query editor extensions #7077
Changes from 2 commits
bac6cc4
f02e725
fc5369e
5b3e358
2cb217e
3c8d096
6391986
397b402
1de91d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import classNames from 'classnames'; | |
import { isEqual } from 'lodash'; | ||
import React, { Component, createRef, RefObject } from 'react'; | ||
import { Settings } from '..'; | ||
import { IDataPluginServices, IIndexPattern, Query, TimeRange } from '../..'; | ||
import { DataSource, IDataPluginServices, IIndexPattern, Query, TimeRange } from '../..'; | ||
import { | ||
CodeEditor, | ||
OpenSearchDashboardsReactContextValue, | ||
|
@@ -19,9 +19,11 @@ import { SuggestionsListSize } from '../typeahead/suggestions_component'; | |
import { DataSettings, QueryEnhancement } from '../types'; | ||
import { fetchIndexPatterns } from './fetch_index_patterns'; | ||
import { QueryLanguageSelector } from './language_selector'; | ||
import { QueryEditorExtensions } from './query_editor_extensions'; | ||
|
||
export interface QueryEditorProps { | ||
indexPatterns: Array<IIndexPattern | string>; | ||
dataSource?: DataSource; | ||
query: Query; | ||
containerRef?: React.RefCallback<HTMLDivElement>; | ||
settings: Settings; | ||
|
@@ -41,10 +43,9 @@ export interface QueryEditorProps { | |
size?: SuggestionsListSize; | ||
className?: string; | ||
isInvalid?: boolean; | ||
queryEditorHeaderRef: React.RefObject<HTMLDivElement>; | ||
queryEditorHeaderClassName?: string; | ||
queryEditorBannerRef: React.RefObject<HTMLDivElement>; | ||
queryEditorBannerClassName?: string; | ||
queryLanguage?: string; | ||
headerClassName?: string; | ||
bannerClassName?: string; | ||
} | ||
|
||
interface Props extends QueryEditorProps { | ||
|
@@ -92,6 +93,9 @@ export default class QueryEditorUI extends Component<Props, State> { | |
private services = this.props.opensearchDashboards.services; | ||
private componentIsUnmounting = false; | ||
private queryEditorDivRefInstance: RefObject<HTMLDivElement> = createRef(); | ||
private headerRef: RefObject<HTMLDivElement> = createRef(); | ||
private bannerRef: RefObject<HTMLDivElement> = createRef(); | ||
private extensionMap = this.props.settings?.getQueryEditorExtensionMap(); | ||
|
||
private getQueryString = () => { | ||
if (!this.props.query.query) { | ||
|
@@ -120,6 +124,30 @@ export default class QueryEditorUI extends Component<Props, State> { | |
}); | ||
}; | ||
|
||
private renderQueryEditorExtensions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! nice clean up! |
||
if ( | ||
!( | ||
this.headerRef.current && | ||
this.bannerRef.current && | ||
this.props.queryLanguage && | ||
this.extensionMap && | ||
Object.keys(this.extensionMap).length > 0 | ||
) | ||
) { | ||
return null; | ||
} | ||
return ( | ||
<QueryEditorExtensions | ||
language={this.props.queryLanguage} | ||
configMap={this.extensionMap} | ||
componentContainer={this.headerRef.current} | ||
bannerContainer={this.bannerRef.current} | ||
indexPatterns={this.props.indexPatterns} | ||
dataSource={this.props.dataSource} | ||
/> | ||
); | ||
} | ||
|
||
private onSubmit = (query: Query, dateRange?: TimeRange) => { | ||
if (this.props.onSubmit) { | ||
if (this.persistedLog) { | ||
|
@@ -249,20 +277,12 @@ export default class QueryEditorUI extends Component<Props, State> { | |
|
||
public render() { | ||
const className = classNames(this.props.className); | ||
|
||
const queryEditorHeaderClassName = classNames( | ||
'osdQueryEditorHeader', | ||
this.props.queryEditorHeaderClassName | ||
); | ||
|
||
const queryEditorBannerClassName = classNames( | ||
'osdQueryEditorBanner', | ||
this.props.queryEditorBannerClassName | ||
); | ||
const headerClassName = classNames('osdQueryEditorHeader', this.props.headerClassName); | ||
const bannerClassName = classNames('osdQueryEditorBanner', this.props.bannerClassName); | ||
|
||
return ( | ||
<div className={className}> | ||
<div ref={this.props.queryEditorBannerRef} className={queryEditorBannerClassName} /> | ||
<div ref={this.bannerRef} className={bannerClassName} /> | ||
<EuiFlexGroup gutterSize="xs" direction="column"> | ||
<EuiFlexItem grow={false}> | ||
<EuiFlexGroup gutterSize="xs"> | ||
|
@@ -285,7 +305,7 @@ export default class QueryEditorUI extends Component<Props, State> { | |
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiFlexItem onClick={this.onClickInput} grow={true}> | ||
<div ref={this.props.queryEditorHeaderRef} className={queryEditorHeaderClassName} /> | ||
<div ref={this.headerRef} className={headerClassName} /> | ||
<CodeEditor | ||
height={70} | ||
languageId="opensearchql" | ||
|
@@ -306,6 +326,7 @@ export default class QueryEditorUI extends Component<Props, State> { | |
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
{this.renderQueryEditorExtensions()} | ||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,6 @@ import { | |
} from '../../../../opensearch_dashboards_react/public'; | ||
import { UI_SETTINGS } from '../../../common'; | ||
import { fromUser, getQueryLog, PersistedLog } from '../../query'; | ||
import { QueryEditorExtensions } from './query_editor_extensions'; | ||
import { Settings } from '../types'; | ||
import { NoDataPopover } from './no_data_popover'; | ||
import QueryEditorUI from './query_editor'; | ||
|
@@ -71,8 +70,6 @@ export interface QueryEditorTopRowProps { | |
export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { | ||
const [isDateRangeInvalid, setIsDateRangeInvalid] = useState(false); | ||
const [isQueryEditorFocused, setIsQueryEditorFocused] = useState(false); | ||
const queryEditorHeaderRef = useRef<HTMLDivElement | null>(null); | ||
const queryEditorBannerRef = useRef<HTMLDivElement | null>(null); | ||
|
||
const opensearchDashboards = useOpenSearchDashboards<IDataPluginServices>(); | ||
const { uiSettings, storage, appName } = opensearchDashboards.services; | ||
|
@@ -85,7 +82,6 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { | |
props.settings && | ||
props.settings.getQueryEnhancements(queryLanguage)?.searchBar) || | ||
null; | ||
const queryEditorExtensionMap = props.settings?.getQueryEditorExtensionMap(); | ||
const parsedQuery = | ||
!queryUiEnhancement || isValidQuery(props.query) | ||
? props.query! | ||
|
@@ -235,6 +231,7 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { | |
<QueryEditor | ||
disableAutoFocus={props.disableAutoFocus} | ||
indexPatterns={props.indexPatterns!} | ||
dataSource={props.dataSource} | ||
prepend={props.prepend} | ||
query={parsedQuery} | ||
containerRef={props.containerRef} | ||
|
@@ -246,33 +243,12 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { | |
getQueryStringInitialValue={getQueryStringInitialValue} | ||
persistedLog={persistedLog} | ||
dataTestSubj={props.dataTestSubj} | ||
queryEditorHeaderRef={queryEditorHeaderRef} | ||
queryEditorBannerRef={queryEditorBannerRef} | ||
queryLanguage={queryLanguage} | ||
/> | ||
</EuiFlexItem> | ||
); | ||
} | ||
|
||
function renderQueryEditorExtensions() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a good clean up. that i need to do after restructuring. I have a clean up task in #6957 but some of the render functions i added are in the wrong location and that's cause i tried to not touch query string input. so thanks for starting the clean up! |
||
if ( | ||
!shouldRenderQueryEditorExtensions() || | ||
!queryEditorHeaderRef.current || | ||
!queryEditorBannerRef.current || | ||
!queryLanguage | ||
) | ||
return; | ||
return ( | ||
<QueryEditorExtensions | ||
language={queryLanguage} | ||
configMap={queryEditorExtensionMap} | ||
componentContainer={queryEditorHeaderRef.current} | ||
bannerContainer={queryEditorBannerRef.current} | ||
indexPatterns={props.indexPatterns} | ||
dataSource={props.dataSource} | ||
/> | ||
); | ||
} | ||
|
||
function renderSharingMetaFields() { | ||
const { from, to } = getDateRange(); | ||
const dateRangePretty = prettyDuration( | ||
|
@@ -304,10 +280,6 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { | |
); | ||
} | ||
|
||
function shouldRenderQueryEditorExtensions(): boolean { | ||
return Boolean(queryEditorExtensionMap && Object.keys(queryEditorExtensionMap).length); | ||
} | ||
|
||
function renderUpdateButton() { | ||
const button = props.customSubmitButton ? ( | ||
React.cloneElement(props.customSubmitButton, { onClick: onClickSubmitButton }) | ||
|
@@ -400,7 +372,6 @@ export default function QueryEditorTopRow(props: QueryEditorTopRowProps) { | |
direction="column" | ||
justifyContent="flexEnd" | ||
> | ||
{renderQueryEditorExtensions()} | ||
{renderQueryEditor()} | ||
<EuiFlexItem> | ||
<EuiFlexGroup responsive={false} gutterSize="none"> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: tbh I think I carried this over from the query string input component and it was used for attaching suggestions. I wonder then if we should just delete this then since i think the header ref more or less solves it.
but not a blocker for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the handleListUpdate related stuff in 5b3e358