-
Notifications
You must be signed in to change notification settings - Fork 6
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
Configurable prop for UI kit components to refetch data #93
Closed
felipecadavid
wants to merge
5
commits into
main
from
felipe/pro-2152-configurable-prop-for-ui-kit-components-to-refetch-data
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bdf6c7c
feat: use React-Query for Counter, Leaderboard and TimeSeries
felipecadavid 8a1aae5
chore: rollback global react types
felipecadavid dfc9333
refactor: merge 'main' branch
felipecadavid c0c26aa
fix: remove react query retries
felipecadavid 718758e
refactor: merge 'main' branch
felipecadavid 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from 'react' | ||
import { QueryClient, QueryClientProvider as ReactQueryProvider } from '@tanstack/react-query' | ||
|
||
const queryClient = new QueryClient() | ||
|
||
export function QueryClientProvider({ children }: { children: React.ReactNode }) { | ||
return <ReactQueryProvider client={queryClient}>{children}</ReactQueryProvider> | ||
} |
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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
export * from './generated' | ||
|
||
export * from './useCounter' | ||
export * from './useTimeSeries' | ||
export * from './useLeaderboard' | ||
|
||
export * from './QueryClientProvider' | ||
|
||
// export const PROPEL_GRAPHQL_API_ENDPOINT = process.env.PROPEL_GRAPHQL_API_ENDPOINT as string | ||
export const PROPEL_GRAPHQL_API_ENDPOINT = 'https://api.us-east-2.propeldata.com/graphql' |
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,71 @@ | ||
import request from 'graphql-request' | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
import { | ||
CounterDocument, | ||
CounterQuery, | ||
CounterQueryVariables, | ||
FilterInput, | ||
Propeller, | ||
TimeRangeInput | ||
} from './generated' | ||
import { PROPEL_GRAPHQL_API_ENDPOINT } from '.' | ||
|
||
interface Query { | ||
/** Time range that the chart will respond to. Will be ignored when value is passed */ | ||
timeRange?: TimeRangeInput | ||
/** This should eventually be replaced to customer's app credentials. Will be ignored when value is passed */ | ||
accessToken?: string | ||
/** Metric unique name will be ignored when value is passed */ | ||
metric?: string | ||
/** Filters that the chart will respond to */ | ||
filters?: FilterInput[] | ||
/** Propeller that the chart will respond to */ | ||
propeller?: Propeller | ||
/** Interval in milliseconds for refetching the data */ | ||
refetchInterval?: number | ||
} | ||
|
||
interface Options { | ||
/** Whether the query is enabled or not */ | ||
enabled?: boolean | ||
} | ||
|
||
export function useCounter(query?: Query, options?: Options) { | ||
const fetcher = () => | ||
request<CounterQuery, CounterQueryVariables>( | ||
PROPEL_GRAPHQL_API_ENDPOINT, | ||
CounterDocument, | ||
{ | ||
counterInput: { | ||
metricName: query?.metric, | ||
timeRange: { | ||
relative: query?.timeRange?.relative ?? null, | ||
n: query?.timeRange?.n ?? null, | ||
start: query?.timeRange?.start ?? null, | ||
stop: query?.timeRange?.stop ?? null | ||
}, | ||
filters: query?.filters, | ||
propeller: query?.propeller | ||
} | ||
}, | ||
{ | ||
authorization: `Bearer ${query?.accessToken}` | ||
} | ||
) | ||
|
||
const queryOptions = { | ||
refetchInterval: query?.refetchInterval, | ||
enabled: options?.enabled && !!query, | ||
retry: false | ||
} | ||
|
||
const cacheKey = ['propel-counter', query] | ||
|
||
const { data, isLoading: isLoadingQuery, error } = useQuery(cacheKey, fetcher, queryOptions) | ||
|
||
const value = data?.counter?.value | ||
const isLoading = options?.enabled ? isLoadingQuery : false | ||
|
||
return { value, isLoading, error } | ||
} |
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.
Should this just be
refetchInterval ?? 1000
, and in all subsequent places, too?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.
Something else I am thinking about: there is a lot of manual work keeping the React examples in sync between 16, 17, and 18. If we diff the files, are they really so different? If not, I think we should consider
But this may make maintenance easier.
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.
I think right now there is no difference between the code of each version, I like this idea of having a canonical version of each.
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.
That wouldn't work, here we just want to switch from undefined => 1000 and from 1000 => undefined
refetchInterval ?? 1000
would setrefetchInterval
to 1000 when it's undefined but wouldn't set it to undefined when it's 1000