Skip to content

Commit

Permalink
chore(PieChart): add timeZone to top level props
Browse files Browse the repository at this point in the history
  • Loading branch information
sashathor committed Feb 23, 2024
1 parent a7a8439 commit 0bf76ed
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .changeset/brave-moons-destroy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@propeldata/ui-kit': patch
---

[Counter, Leaderboard, PieChart, TimeSeries]: prioritize `query.timeZone` over the deprecated `timeZone` prop
[Counter, Leaderboard, PieChart, TimeSeries]: pass `query.timeZone` when provided
5 changes: 1 addition & 4 deletions packages/ui-kit/src/components/Counter/Counter.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ export interface CounterProps extends DataComponentProps<'span'> {
/** When true, formats value to locale string */
localize?: boolean

/**
* @deprecated ~~Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC").
* Defaults to the client's local time zone.~~
* This type is deprecated, pass it via `query` instead */
/** Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC"). Defaults to the client's local time zone */
timeZone?: string

/** Counter query props */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export interface LeaderboardProps extends DataComponentProps<'div'> {
/** When true, shows a skeleton loader */
loading?: boolean

/**
* @deprecated Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC").
* Defaults to the client's local time zone.
* This type is deprecated, pass it via `query` instead. */
/** Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC"). Defaults to the client's local time zone */
timeZone?: string

/** Leaderboard query props */
Expand Down
8 changes: 6 additions & 2 deletions packages/ui-kit/src/components/PieChart/PieChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from 'react'
import {
customCanvasBackgroundColor,
getCustomChartLabelsPlugin,
getTimeZone,
useCombinedRefsCallback,
withThemeWrapper
} from '../../helpers'
Expand Down Expand Up @@ -32,6 +33,7 @@ export const PieChartComponent = React.forwardRef<HTMLDivElement, PieChartProps>
errorFallbackProps: errorFallbackPropsInitial,
errorFallback,
renderEmpty,
timeZone: timeZoneInitial,
card = false,
className,
style,
Expand Down Expand Up @@ -79,14 +81,16 @@ export const PieChartComponent = React.forwardRef<HTMLDivElement, PieChartProps>
*/
const isStatic = !query

const timeZone = getTimeZone(query?.timeZone ?? timeZoneInitial)

/**
* Fetches the leaderboard data from the API
*/
const {
data: leaderboardData,
isLoading: leaderboardIsLoading,
error: leaderboardHasError
} = useLeaderboard({ ...query, dimensions: [query?.dimension ?? { columnName: '' }], enabled: !isStatic })
} = useLeaderboard({ ...query, timeZone, dimensions: [query?.dimension ?? { columnName: '' }], enabled: !isStatic })

/**
* Fetches the counter data from the API
Expand All @@ -95,7 +99,7 @@ export const PieChartComponent = React.forwardRef<HTMLDivElement, PieChartProps>
data: counterData,
isLoading: counterIsLoading,
error: counterHasError
} = useCounter({ ...query, enabled: !isStatic })
} = useCounter({ ...query, timeZone, enabled: !isStatic })

const isLoading = leaderboardIsLoading || counterIsLoading

Expand Down
3 changes: 3 additions & 0 deletions packages/ui-kit/src/components/PieChart/PieChart.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ export interface PieChartProps extends DataComponentProps<'div'> {
/** When true, shows a skeleton loader */
loading?: boolean

/** Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC"). Defaults to the client's local time zone */
timeZone?: string

/** If passed along with `rows` the component will ignore the built-in GraphQL operations. */
headers?: string[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ export interface TimeSeriesBaseProps extends DataComponentProps<'div'> {
/** Canvas role prop, if not passed we handle it */
role?: string

/**
* @deprecated Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC").
* Defaults to the client's local time zone.
* This type is deprecated, pass it via `query` instead */
/** Time zone to use (for example, "America/Los_Angeles", "Europe/Berlin", or "UTC"). Defaults to the client's local time zone */
timeZone?: string

/** TimeSeries query props */
Expand Down

0 comments on commit 0bf76ed

Please sign in to comment.