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

[Discover-next] query editor and UI settings toggle #7001

Merged
merged 2 commits into from
Jun 14, 2024

Conversation

kavilla
Copy link
Member

@kavilla kavilla commented Jun 11, 2024

Description

Adds new query editor in replacement of query string input.

Utilizing:

data.enhancements.enabled: false

And enabling the Advanced Setting: query:enhancements:enabled

Also, cleans up the toggling since it is now two different components.

More information:

For 2.14, the query enhancements were nested within query string input bar.
For 2.15, query enhancements included the Monaco query editor.

This made the conditional logic for the query enhancements easier since we do not render even majority of the work if query enhancements are disabled.

  • First it will check the config file data.enhancements.enabled if it the feature is enabled (by default it is not).
  • If that is TRUE, then while rendering the Search Bar, it will check the Advanced Setting query:enhancements:enabled if it is enabled (by default it is not).
  • If data.enhancements.enabled && query:enhancements:enabled:
    • renders query editor
  • If data.enhancements.enabled && NOT query:enhancements:enabled:
    • renders query string input
  • If NOT data.enhancements.enabled && query:enhancements:enabled:
    • renders query string input
  • If NOT data.enhancements.enabled && NOT query:enhancements:enabled:
    • renders query string input

If user toggles on the setting in Advanced Settings, and queries a non-Native (DQL or Lucene) filter language from the language selector it will be treated as native query language. Existing features like local storage typeahead, userQueryString, and userQueryLanguage will support the new languages. However, when the users toggles off the setting in Advanced Setting, we will reset the these to be kuery and empty query string to reset the state. However, there exists an Advanced Setting for query language so we should consider best next steps here to improve this experience because we force this default state regardless if the user even used these extra langauges.

Issues Related:

#6067

Screenshot

Screenshot 2024-06-10 at 5 31 49 PM

Testing the changes

Changelog

  • feat: Query editor and UI settings toggle

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 55.86207% with 64 lines in your changes missing coverage. Please review.

Project coverage is 67.46%. Comparing base (e74ed2c) to head (af675c9).
Report is 376 commits behind head on main.

Files with missing lines Patch % Lines
src/plugins/data/public/ui/settings/settings.ts 33.33% 16 Missing and 2 partials ⚠️
...c/plugins/data/public/ui/search_bar/search_bar.tsx 47.61% 6 Missing and 5 partials ⚠️
.../data_explorer/public/components/sidebar/index.tsx 52.38% 8 Missing and 2 partials ⚠️
.../data/public/ui/query_editor/language_selector.tsx 59.09% 8 Missing and 1 partial ⚠️
src/plugins/data/public/ui/ui_service.ts 0.00% 4 Missing ⚠️
...public/ui/query_string_input/language_switcher.tsx 78.57% 3 Missing ⚠️
...ns/data/public/ui/search_bar/create_search_bar.tsx 0.00% 3 Missing ⚠️
src/plugins/data/public/ui/query_editor/index.tsx 71.42% 2 Missing ⚠️
src/plugins/data/public/plugin.ts 0.00% 1 Missing ⚠️
src/plugins/data/public/ui/mocks.ts 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7001      +/-   ##
==========================================
+ Coverage   67.45%   67.46%   +0.01%     
==========================================
  Files        3442     3444       +2     
  Lines       67816    67865      +49     
  Branches    11027    11027              
==========================================
+ Hits        45742    45786      +44     
- Misses      19408    19416       +8     
+ Partials     2666     2663       -3     
Flag Coverage Δ
Linux_1 33.07% <25.00%> (-0.01%) ⬇️
Linux_2 55.11% <ø> (ø)
Linux_3 45.24% <55.55%> (+0.03%) ⬆️
Linux_4 34.86% <27.02%> (-0.01%) ⬇️
Windows_1 33.12% <25.00%> (+0.02%) ⬆️
Windows_2 55.06% <ø> (ø)
Windows_3 45.24% <55.55%> (+0.02%) ⬆️
Windows_4 34.86% <27.02%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

kavilla pushed a commit to kavilla/OpenSearch-Dashboards-1 that referenced this pull request Jun 11, 2024
@ashwin-pc ashwin-pc added the discover for discover reinvent label Jun 11, 2024
@ashwin-pc
Copy link
Member

I think i understand how this keeps the new experience isolated from the existing one, but might be worth it to call it out in the PR how you test the change and how it safeguards against regressions.

bandinib-amzn pushed a commit to kavilla/OpenSearch-Dashboards-1 that referenced this pull request Jun 11, 2024
@kavilla kavilla force-pushed the kavilla/editor_toggle branch 2 times, most recently from d269095 to cee212d Compare June 12, 2024 10:15
Adds new query editor in replacement of query string input.

Utilizing:
```
data.enhancements.enabled: true
```

And enabling the Advanced Setting: `query:enhancements:enabled`

Also, cleans up the toggling since it is now two different components.

Related issue:
opensearch-project#6067

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note: this is actually restoring the language switcher to it's state before 2.14. Because the conditional logic renders different components then removed the query enhancements stuff and just having the switcher how it was before. This can be considered safe.

This changes can be considered safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note: this is actually restoring the language switcher to it's state before 2.14. Because the conditional logic renders different components then removed the query enhancements stuff and just having the switcher how it was before. This can be considered safe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note: this isn't actually deleting the logic. this file was new for 2.14 to house the pre-2.14 code. this file is unneeded. since i'm restoring the language switcher in the original file (to retain the git history).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please note: this isn't actually deleting the logic. this file was new for 2.14 to house the pre-2.14 code. this file is unneeded. since i'm restoring the language switcher in the original file (to retain the git history).

import { monaco } from '@osd/monaco';

import darkTheme from '@elastic/eui/dist/eui_theme_dark.json';
import lightTheme from '@elastic/eui/dist/eui_theme_light.json';

// NOTE: For talk around where this theme information will ultimately live,
// please see this discuss issue: https://github.com/elastic/kibana/issues/43814
const standardizeColor = (color: string) => new Color(color).hex().toLowerCase();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

required, Monaco doesn't support shorthand hex code and will crash.

Comment on lines +14 to 26
.globalQueryEditor {
padding: 0 $euiSizeXS $euiSizeXS $euiSizeXS;
}

.globalQueryEditor:first-child {
padding-top: $euiSizeXS;
}

.globalQueryEditor:not(:empty) {
padding-bottom: $euiSizeXS;
}

.globalFilterGroup__filterBar {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right file? I guess kept here because other query bar styles are here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. this isn't the right file and should be in it's own file along with the query bar style. i opted to going this route for 2.15 so that we can be more holistic in the clean up. along with even more refactoring related to search bar.

i've added a line item: #6957

* SPDX-License-Identifier: Apache-2.0
*/

.osdQueryEditor__wrap {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, what's the difference between the osd query editor and the global query editor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ported over from query bar but i agree this location and names of these are not accurate for their uses.

added here:
#6957

.osdQueryEditorHeader {
max-height: 400px;

// TODO fix styling: with "overflow: auto" the scroll bar appears although the content is below max-height
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a mechanism to track todos to avoid long lived dead code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch: ive added an item here to do start the ball rolling: #6957

}
}

// IE specific fix for the datepicker to not collapse
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we support IE or is this for Edge in IE mode?

Copy link
Member Author

@kavilla kavilla Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Edge: https://opensearch.org/docs/1.2/dashboards/browser-compatibility/

But I can't find new doc about browser compatibility so I should check . Added an issue here to clean up this stuff and verify: #6957

src/plugins/data/public/ui/query_editor/query_editor.tsx Outdated Show resolved Hide resolved
index: number | null;
suggestions: QuerySuggestion[];
indexPatterns: IIndexPattern[];
queryEditorRect: DOMRect | undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason for undefined over null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this work might be unneeded based on what we do with suggestions and the query assist but reason between undefined over null is based on what the suggestions is expecting.

will make sure to track it here:
#6957

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

queryEditorRect can be undefined? so it is not required? should we use queryEditorRect?: DOMRect to show it is optional?

}

public componentWillUnmount() {
if (this.abortController) this.abortController.abort();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is code style not to use braces on single line ifs? personally think they should be required (e.g. apple's tls bug)

Copy link
Member Author

@kavilla kavilla Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part was pretty much ported over.

i agree. one of things that we forked was the ability for plugins that have unrestricted control.

our repo has linters defined here https://github.com/opensearch-project/OpenSearch-Dashboards/tree/main/packages/opensearch-eslint-config-opensearch-dashboards

which we can add this rule (and more rules) but in the past worried about updating this. any plugin that uses our rules then will also have to update their code. And we tried our best to avoid breaking them by opening an issue in each repo and letting them know ahead of time.

i've added a line item for code clean up in both components:
#6957

}

this.initPersistedLog();
// this.fetchIndexPatterns().then(this.updateSuggestions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't want to delete this code since this where we will get suggestions once query assist is added. Right now the suggestions is not wired up into the query editor but will be used once assistant work is added.

thanks for catching. added to this issue for tracking:
#6957

onChange={this.onQueryBarChange}
isDirty={this.isDirty()}
customSubmitButton={
this.props.customSubmitButton ? this.props.customSubmitButton : undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this.props.customSubmitButton || undefined

Copy link
Member Author

@kavilla kavilla Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1,

added here when we do clean up of both components:
#6957

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
}
this.isEnabled = enabled;
this.enabledQueryEnhancementsUpdated$.next(this.isEnabled);
return true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. it feels to me that these return true statement are redundant as we are not having other conditional statement / async CURD operations to return false, and the set operation will always be true.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true i did this to mimic the other settings files within the repo. i think it's a little bit redundant as well. we should consider doing an audit

export function createSettings({ storage, queryEnhancements }: Deps) {
return new Settings(storage, queryEnhancements);
export function createSettings({ config, search, storage, queryEnhancements }: Deps) {
return new Settings(config, search, storage, queryEnhancements);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to also passing params as an object to make it more scalable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. added to tracker issue. hopefully we don't have to add any more params here but if we do ive tracked an action item for us to convert to an object.

Copy link
Member

@ananzh ananzh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just did a local try out. approve as 2nd reviewer to unblock.


const LazyQueryEditorTopRow = React.lazy(() => import('./query_editor_top_row'));
export const QueryEditorTopRow = (props: QueryEditorTopRowProps) => (
<React.Suspense fallback={<Fallback />}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: instead of an empty

ad fallback, do we want something meaningful like spinner or a loading message. Should we also consider adding an error boundary to catch any errors that occur during the dynamic import or component rendering in case of crashing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair i feel like a fallback globally could be more helpful. added to the tracker issue

onChange={handleLanguageChange}
singleSelection={{ asPlainText: true }}
isClearable={false}
async
Copy link
Member

@ananzh ananzh Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't know there is an async for EuiComboBox.. good learning for me

}
}, [noDataPopoverDismissed, showNoDataPopover]);

return (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we are repeating query_string_input 's context in query_editor. I know that there are there are three cases that we use query string input and only one with both settings enabled to use query editor, so if that is the case can't we just simply reuse these repeat component from query_string_input? why duplicate these component?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good catch. part of this issue: #6957.

the goal here was to release to this for 2.15, it would keep the query string input completely intact (even restored some of the files to their pre-2.14 state). to ensure the code paths are completely separate in case users toggle it on and off.

then targeting 2.16, with more automated testing start cleaning up these components.

settings={settings}
containerRef={containerRef}
Copy link
Member

@ananzh ananzh Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the containerRef is added to access a DOM element within a QueryEditorUI?. or is there use cases that will cause DOM to lose?

@kavilla kavilla merged commit a4aa682 into opensearch-project:main Jun 14, 2024
66 of 67 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 14, 2024
* [Discover-next] query editor and UI settings toggle

Adds new query editor in replacement of query string input.

Utilizing:
```
data.enhancements.enabled: true
```

And enabling the Advanced Setting: `query:enhancements:enabled`

Also, cleans up the toggling since it is now two different components.

Related issue:
#6067

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>

* Remove commented out code

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>

---------

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
(cherry picked from commit a4aa682)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
name: i18n.translate('data.advancedSettings.query.enhancements.enableTitle', {
defaultMessage: 'Enable query enhancements',
}),
value: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this still needs user to set data.enhancements.enabled in osd config yml, would it be confusing if user only sets it to true here and see enhancements are still disabled because yml is not set?

kavilla pushed a commit that referenced this pull request Jun 20, 2024
* [Discover-next] query editor and UI settings toggle

Adds new query editor in replacement of query string input.

Utilizing:
```
data.enhancements.enabled: true
```

And enabling the Advanced Setting: `query:enhancements:enabled`

Also, cleans up the toggling since it is now two different components.

Related issue:
#6067



* Remove commented out code



---------


(cherry picked from commit a4aa682)

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants