-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add search result statistics on the main search screen #16130
Merged
linuspahl
merged 17 commits into
master
from
fix/Total-result-count-missing-from-query-page/issue-7386
Feb 9, 2024
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
38d4eff
Add execution info components
maxiadlovskii 355cbde
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii b14a678
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii a42a309
refactoring. add total value to sidebar execution info
maxiadlovskii dd9ac1f
add change log
maxiadlovskii 7db6bc8
fix type issues
maxiadlovskii 643e5bd
update changelog
maxiadlovskii d1fbfbd
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii dc1aa93
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii f7d53c5
fix tests
maxiadlovskii e112dd5
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii 971f6ea
fix eslint
maxiadlovskii 72c48b9
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii 9d95ee4
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii bf35e8c
refactoring
maxiadlovskii be0ffc1
Merge branch 'master' into fix/Total-result-count-missing-from-query-…
maxiadlovskii 56d9865
refactoring
maxiadlovskii File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type = "a" | ||
message = "Add search result statistics on the main search screen and execution info popover to each dashboard widget" | ||
|
||
pulls = ["16130"] | ||
issues=["7386"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
graylog2-web-interface/src/views/components/views/ExecutionInfo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import React from 'react'; | ||
import numeral from 'numeral'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
|
||
import useAppSelector from 'stores/useAppSelector'; | ||
import { selectCurrentQueryResults } from 'views/logic/slices/viewSelectors'; | ||
import { Timestamp } from 'components/common'; | ||
|
||
const ExecutionInfo = () => { | ||
const result = useAppSelector(selectCurrentQueryResults); | ||
const total = result?.searchTypes && Object.values(result?.searchTypes)?.[0]?.total; | ||
|
||
if (isEmpty(result)) { | ||
return <i>No query executed yet.</i>; | ||
} | ||
|
||
return ( | ||
<i> | ||
Query executed in{' '} | ||
{numeral(result?.duration).format('0,0')}ms at <Timestamp dateTime={result?.timestamp} /> | ||
{' '}Total results: {numeral(total).format('0,0')} | ||
</i> | ||
); | ||
}; | ||
|
||
export default ExecutionInfo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
graylog2-web-interface/src/views/components/widgets/SearchQueryExecutionInfoHelper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
import * as React from 'react'; | ||
import styled from 'styled-components'; | ||
import type { PropsWithChildren } from 'react'; | ||
import { useCallback, useMemo, useState } from 'react'; | ||
import numeral from 'numeral'; | ||
import isEmpty from 'lodash/isEmpty'; | ||
|
||
import { Timestamp } from 'components/common'; | ||
import { Table } from 'components/bootstrap'; | ||
import useAppSelector from 'stores/useAppSelector'; | ||
import { selectCurrentQueryResults } from 'views/logic/slices/viewSelectors'; | ||
import type { MessageResult, SearchTypeResult, SearchTypeResultTypes } from 'views/types'; | ||
import type { SearchTypeIds } from 'views/logic/views/types'; | ||
import Popover from 'components/common/Popover'; | ||
|
||
type Props = PropsWithChildren & { | ||
currentWidgetMapping: SearchTypeIds, | ||
}; | ||
|
||
const TargetContainer = styled.div` | ||
cursor: pointer; | ||
`; | ||
|
||
const StyledTable = styled(Table)` | ||
margin-bottom: 0 | ||
`; | ||
|
||
type WidgetExecutionData = { | ||
total: number, | ||
duration: number, | ||
timestamp: string, | ||
effectiveTimerange: SearchTypeResult['effective_timerange'] | MessageResult['effectiveTimerange'] | ||
} | ||
|
||
const HelpPopover = ({ widgetExecutionData }: { widgetExecutionData: WidgetExecutionData}) => ( | ||
<StyledTable condensed> | ||
<tbody> | ||
<tr> | ||
<td><i>Executed at:</i></td> | ||
<td aria-label="Executed at"><Timestamp dateTime={widgetExecutionData?.timestamp} /></td> | ||
</tr> | ||
<tr> | ||
<td><i>Executed in:</i> </td> | ||
<td>{numeral(widgetExecutionData?.duration).format('0,0')}ms</td> | ||
</tr> | ||
<tr> | ||
<td colSpan={2}><i>Effective time range:</i></td> | ||
</tr> | ||
<tr> | ||
<td>From</td> | ||
<td aria-label="Effective time range from"><Timestamp dateTime={widgetExecutionData?.effectiveTimerange?.from} format="complete" /></td> | ||
</tr> | ||
<tr> | ||
<td>To</td> | ||
<td aria-label="Effective time range to"><Timestamp dateTime={widgetExecutionData?.effectiveTimerange?.to} format="complete" /></td> | ||
</tr> | ||
<tr> | ||
<td><i>Total results:</i></td> | ||
<td>{numeral(widgetExecutionData?.total).format('0,0')}</td> | ||
</tr> | ||
</tbody> | ||
</StyledTable> | ||
); | ||
|
||
const SearchQueryExecutionInfoHelper = ({ currentWidgetMapping, children }: Props) => { | ||
const [open, setOpen] = useState(false); | ||
const result = useAppSelector(selectCurrentQueryResults); | ||
const currentWidgetSearchType = useMemo<SearchTypeResultTypes[keyof SearchTypeResultTypes]>(() => { | ||
const searchTypeId = currentWidgetMapping?.toJS()?.[0]; | ||
|
||
return result?.searchTypes?.[searchTypeId]; | ||
}, [currentWidgetMapping, result?.searchTypes]); | ||
|
||
const widgetExecutionData = useMemo<WidgetExecutionData>(() => ({ | ||
effectiveTimerange: (currentWidgetSearchType as MessageResult)?.effectiveTimerange || (currentWidgetSearchType as SearchTypeResult)?.effective_timerange, | ||
total: currentWidgetSearchType?.total, | ||
duration: result?.duration, | ||
timestamp: result?.timestamp, | ||
|
||
}), [currentWidgetSearchType, result?.duration, result?.timestamp]); | ||
|
||
const onClose = useCallback(() => { | ||
setOpen(false); | ||
}, []); | ||
|
||
const onToggle = useCallback(() => { | ||
setOpen((cur) => !cur); | ||
}, []); | ||
|
||
return ( | ||
<Popover position="bottom" opened={open} onClose={onClose} closeOnClickOutside> | ||
<Popover.Target> | ||
<TargetContainer role="presentation" onClick={onToggle}>{children}</TargetContainer> | ||
</Popover.Target> | ||
<Popover.Dropdown title="Execution Info"> | ||
{isEmpty(result) ? <i>No query executed yet.</i> : <HelpPopover widgetExecutionData={widgetExecutionData} />} | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default SearchQueryExecutionInfoHelper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Currently we show "Query executed in 0ms" + "Total results: 0" when executing search for the first time.
Maybe let's unify it with the sidebar, where we show
<i>No query executed yet.</i>
in this case?