-
Notifications
You must be signed in to change notification settings - Fork 98
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
Feature query regex #94
Changes from 4 commits
708d357
b98b80a
426b118
8833a6e
c33c600
576958a
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
export { getIndexPatternFromRawQuery } from './query_utils'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
export const getIndexPatternFromRawQuery = (query: string) : string => { | ||
const indexMatches = query.match('\=(.*)'); | ||
if (indexMatches) { | ||
return indexMatches[0]?.slice(1)?.split('|')[0]?.trim(); | ||
} | ||
return ''; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,17 +25,17 @@ import { | |
} from '@elastic/eui'; | ||
import classNames from 'classnames'; | ||
import { Search } from '../common/seach/search'; | ||
import { CountDistribution } from './visualizations/countDistribution'; | ||
import { DataGrid } from './dataGrid'; | ||
import { CountDistribution } from './visualizations/count_distribution'; | ||
import { DataGrid } from './data_grid'; | ||
import { Sidebar } from './sidebar'; | ||
import { NoResults } from './noResults'; | ||
import { NoResults } from './no_results'; | ||
import { HitsCounter } from './hits_counter/hits_counter'; | ||
import { TimechartHeader } from './timechart_header'; | ||
import { ExplorerVisualizations } from './visualizations'; | ||
import { | ||
IField, | ||
IQueryTab | ||
} from '../../common/types/explorer'; | ||
} from '../../../common/types/explorer'; | ||
import { | ||
TAB_CHART_TITLE, | ||
TAB_EVENT_TITLE, | ||
|
@@ -44,19 +44,20 @@ import { | |
RAW_QUERY, | ||
SELECTED_FIELDS, | ||
UNSELECTED_FIELDS | ||
} from '../../common/constants/explorer'; | ||
} from '../../../common/constants/explorer'; | ||
import { getIndexPatternFromRawQuery } from '../../../common/utils'; | ||
import { | ||
useFetchEvents, | ||
useFetchVisualizations | ||
} from './hooks'; | ||
import { | ||
changeQuery, | ||
selectQueries | ||
} from './slices/querySlice'; | ||
import { selectQueryResult } from './slices/queryResultSlice'; | ||
import { selectFields, updateFields } from './slices/fieldSlice'; | ||
import { selectCountDistribution } from './slices/countDistributionSlice'; | ||
import { selectExplorerVisualization } from './slices/visualizationSlice'; | ||
} from './slices/query_slice'; | ||
import { selectQueryResult } from './slices/query_result_slice'; | ||
import { selectFields, updateFields } from './slices/field_slice'; | ||
import { selectCountDistribution } from './slices/count_distribution_slice'; | ||
import { selectExplorerVisualization } from './slices/visualization_slice'; | ||
|
||
const TAB_EVENT_ID = _.uniqueId(TAB_EVENT_ID_TXT_PFX); | ||
const TAB_CHART_ID = _.uniqueId(TAB_CHART_ID_TXT_PFX); | ||
|
@@ -66,6 +67,8 @@ interface IExplorerProps { | |
tabId: string | ||
} | ||
|
||
const statsRegx = new RegExp(/stats/); | ||
|
||
export const Explorer = ({ | ||
pplService, | ||
tabId | ||
|
@@ -113,18 +116,21 @@ export const Explorer = ({ | |
[setFixedScrollEl] | ||
); | ||
|
||
const getIndexFromRawQuery = (rawQuery: string) => rawQuery.split('=')[1].split(' ')[0]; | ||
|
||
useEffect(() => { | ||
const fetchData = () => { | ||
if (!query) return; | ||
if (query.includes('stats')) { | ||
const index = getIndexFromRawQuery(query); | ||
if (statsRegx.test(query)) { | ||
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. similar here, this is the same as 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. yea, makes sense, I'm thinking and testing query.match(/|\s*stats/i) to match 'stats' 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. cool, i think the 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. yes, the one I used includes the escape, I noticed that when I left the comment it was missing that escape. I tried to modified it to add escape but it just not reflecting it. Wired. |
||
const index = getIndexPatternFromRawQuery(query); | ||
if (!index) return; | ||
getAvailableFields(`search source=${index}`); | ||
getVisualizations(); | ||
} else { | ||
getEvents(); | ||
getCountVisualizations('m'); | ||
getCountVisualizations('h'); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
fetchData(); | ||
}, []); | ||
|
||
const handleAddField = (field: IField) => toggleFields(field, UNSELECTED_FIELDS, SELECTED_FIELDS); | ||
|
@@ -415,18 +421,11 @@ export const Explorer = ({ | |
|
||
const handleContentTabClick = (selectedTab: IQueryTab) => setSelectedContentTab(selectedTab.id); | ||
|
||
const handleQuerySearch = (tabId: string) => { | ||
if (query.includes('stats')) { | ||
const index = getIndexFromRawQuery(query); // index | ||
getAvailableFields(`search source=${index}`); | ||
getVisualizations(); | ||
return; | ||
} | ||
getEvents(); | ||
getCountVisualizations('m'); | ||
const handleQuerySearch = () => { | ||
fetchData(); | ||
} | ||
|
||
const handleQueryChange = (query, tabId) => { | ||
const handleQueryChange = (query: string, tabId: string) => { | ||
dispatch(changeQuery({ | ||
tabId, | ||
query: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
* GitHub history for details. | ||
*/ | ||
|
||
export * from './countDistribution'; | ||
export * from './count_distribution'; |
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.
maybe use
/regex/
instead of'regex'
, also the\
and()
doesn't seem to make a difference?does this work with the example i gave before? I was thinking something like
.match(/source\s*=\s*([^|\s]+)/)[1]
instead of js string manipulationThere 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.
Sure, we can use /regex/. Yes, the \ and () can be removed in this case.
This works with the example you gave before and also other corner cases I can think of. But I agree it's better to use regex entirely in this case.
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.
Got it, then looks good. up to you on which implementation you want to use.
just a note i did not test the regex i wrote. if you use something similar maybe also add the
/i
flag to ignore case, and i thinkindex
can be used instead ofsource
so maybe(source|index)
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.
Exactly, I'm adding index and /i to it, thanks