-
Notifications
You must be signed in to change notification settings - Fork 894
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 SearchOnLoad Preference for dataset #8513
Changes from all commits
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 |
---|---|---|
|
@@ -88,6 +88,7 @@ | |
const [savedSearch, setSavedSearch] = useState<SavedSearch | undefined>(undefined); | ||
const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover); | ||
const indexPattern = useIndexPattern(services); | ||
const skipInitialFetch = useRef(false); | ||
const { | ||
data, | ||
filterManager, | ||
|
@@ -111,6 +112,15 @@ | |
requests: new RequestAdapter(), | ||
}; | ||
|
||
const getDatasetAutoSearchOnPageLoadPreference = () => { | ||
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. I know it is a bit too much to ask. maybe we should add a test here given we have more and more logic in useSearch. 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. +1 we definitely need to add a test for this |
||
// Checks the searchOnpageLoadPreference for the current dataset if not specifed defaults to true | ||
const datasetType = data.query.queryString.getQuery().dataset?.type; | ||
|
||
const datasetService = data.query.queryString.getDatasetService(); | ||
|
||
return !datasetType || (datasetService?.getType(datasetType)?.meta?.searchOnLoad ?? true); | ||
}; | ||
|
||
const shouldSearchOnPageLoad = useCallback(() => { | ||
// A saved search is created on every page load, so we check the ID to see if we're loading a | ||
// previously saved search or if it is just transient | ||
|
@@ -125,10 +135,13 @@ | |
const data$ = useMemo( | ||
() => | ||
new BehaviorSubject<SearchData>({ | ||
status: shouldSearchOnPageLoad() ? ResultStatus.LOADING : ResultStatus.UNINITIALIZED, | ||
status: | ||
shouldSearchOnPageLoad() && !skipInitialFetch.current | ||
? ResultStatus.LOADING | ||
: ResultStatus.UNINITIALIZED, | ||
queryStatus: { startTime }, | ||
}), | ||
[shouldSearchOnPageLoad, startTime] | ||
[shouldSearchOnPageLoad, startTime, skipInitialFetch] | ||
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. should we check for 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. +1. |
||
); | ||
const refetch$ = useMemo(() => new Subject<SearchRefetch>(), []); | ||
|
||
|
@@ -289,6 +302,9 @@ | |
]); | ||
|
||
useEffect(() => { | ||
if (!getDatasetAutoSearchOnPageLoadPreference()) { | ||
skipInitialFetch.current = true; | ||
} | ||
const fetch$ = merge( | ||
refetch$, | ||
filterManager.getFetches$(), | ||
|
@@ -297,8 +313,11 @@ | |
timefilter.getAutoRefreshFetch$(), | ||
data.query.queryString.getUpdates$() | ||
).pipe(debounceTime(100)); | ||
|
||
const subscription = fetch$.subscribe(() => { | ||
if (skipInitialFetch.current) { | ||
skipInitialFetch.current = false; // Reset so future fetches will proceed normally | ||
return; // Skip the first fetch | ||
Check warning on line 319 in src/plugins/discover/public/application/view_components/utils/use_search.ts Codecov / codecov/patchsrc/plugins/discover/public/application/view_components/utils/use_search.ts#L318-L319
|
||
} | ||
(async () => { | ||
try { | ||
await fetch(); | ||
|
@@ -316,6 +335,8 @@ | |
return () => { | ||
subscription.unsubscribe(); | ||
}; | ||
// disabling the eslint since we are not adding getDatasetAutoSearchOnPageLoadPreference since this changes when dataset changes and these chnages are already part of data.query.queryString | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [ | ||
data$, | ||
data.query.queryString, | ||
|
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: So you set this one as an optional property. Seems searchOnLoad property is added to some dataset types but not all? Seems we have searchOnLoad on index pattern type, index type and s3 type. what else types need this searchOnLoad that allows this property to be missing? To make it consistent, maybe remove ? because this
return !datasetType || (datasetService?.getType(datasetType)?.meta?.searchOnLoad ?? true
already set the default value to true right? so?
is not necessary.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.
nice callout. I think we should have different types for the config we provide and the config we receive from the service. Not a blocker for the PR though