-
Notifications
You must be signed in to change notification settings - Fork 557
dbeaver/pro#8746 add useQuery hook #4241
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
06778bc
dbeaver/pro#8746 add useQuery hook
devnaumov 1c16350
dbeaver/pro#8746 add language tokens
devnaumov f2c2efe
dbeaver/pro#8746 set loading to false in case of abort
devnaumov 7fbc099
dbeaver/pro#8746 use more advanced useQuery
devnaumov e876811
Merge branch 'devel' into dbeaver/pro#8746-oauth
devnaumov 8c17856
dbeaver/pro#8746 fix code style
devnaumov 765c7fc
dbeaver/pro#8746 remove useQuery hook
devnaumov 32d9c39
Merge branch 'devel' into dbeaver/pro#8746-oauth
devnaumov ded54cb
Merge branch 'devel' into dbeaver/pro#8746-oauth
dariamarutkina 7fd0323
Merge branch 'devel' into dbeaver/pro#8746-oauth
dariamarutkina efa83d4
Merge branch 'devel' into dbeaver/pro#8746-oauth
dariamarutkina f439469
Merge branch 'devel' into dbeaver/pro#8746-oauth
dariamarutkina 1f229f0
Merge branch 'devel' into dbeaver/pro#8746-oauth
dariamarutkina 26f83f6
Merge branch 'devel' into dbeaver/pro#8746-oauth
serge-rider 2dc3081
Merge branch 'devel' into dbeaver/pro#8746-oauth
serge-rider 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 hidden or 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 hidden or 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,52 @@ | ||
| /* | ||
| * CloudBeaver - Cloud Database Manager | ||
| * Copyright (C) 2020-2026 DBeaver Corp and others | ||
| * | ||
| * Licensed under the Apache License, Version 2.0. | ||
| * you may not use this file except in compliance with the License. | ||
| */ | ||
|
|
||
| import { useState, useEffect, useRef, useLayoutEffect } from 'react'; | ||
|
|
||
| interface QueryState<T> { | ||
| data: T | null; | ||
| loading: boolean; | ||
| error: Error | null; | ||
| } | ||
|
|
||
| /** We can use this if we don’t have ILoadableState and we fetch data that is not supposed to be kept in the resource */ | ||
| export function useQuery<T>(queryFn: () => Promise<T>, deps: any[] = []): QueryState<T> { | ||
| const [state, setState] = useState<QueryState<T>>({ | ||
| data: null, | ||
| loading: true, | ||
| error: null, | ||
| }); | ||
|
|
||
| const abortRef = useRef<AbortController | null>(null); | ||
| const queryFnRef = useRef(queryFn); | ||
|
|
||
| useLayoutEffect(() => { | ||
| queryFnRef.current = queryFn; | ||
| }, [queryFn]); | ||
|
|
||
| useEffect(() => { | ||
| abortRef.current?.abort(); | ||
| abortRef.current = new AbortController(); | ||
|
Wroud marked this conversation as resolved.
Outdated
|
||
|
|
||
| queryFnRef | ||
| .current() | ||
| .then(data => setState({ data, loading: false, error: null })) | ||
| .catch(error => { | ||
| if (error.name === 'AbortError') { | ||
|
devnaumov marked this conversation as resolved.
Outdated
|
||
| setState(prev => ({ ...prev, loading: false })); | ||
| return; | ||
| } | ||
|
|
||
| setState({ data: null, loading: false, error }); | ||
| }); | ||
|
|
||
| return () => abortRef.current?.abort(); | ||
| }, deps); | ||
|
Check warning on line 49 in webapp/packages/core-blocks/src/useQuery.ts
|
||
|
|
||
| return state; | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.