-
Notifications
You must be signed in to change notification settings - Fork 502
feat: Feature Analytics label grouping (#6067) #7215
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
Open
talissoncosta
wants to merge
10
commits into
fix/storybook-dark-mode
Choose a base branch
from
feat/feature-analytics-6067
base: fix/storybook-dark-mode
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,012
−95
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ab7d3bc
feat: Add chart color tokens and getCSSVar utility
talissoncosta 42b6e48
feat: Add ColorSwatch component
talissoncosta 3650dc1
feat: Add reusable BarChart and ChartTooltip components
talissoncosta 9a98bdf
feat: Add label-based grouping to Feature Analytics charts
talissoncosta 1ed2108
feat: Add BarChart and MultiSelect Storybook stories
talissoncosta 5da399e
fix: Use natural sort order for token generation
talissoncosta bfee56a
fix: Remove hooks-in-loop violation, add unit tests
talissoncosta e6c3da8
refactor: Add useChartColors hook, remove direct getCSSVars calls
talissoncosta 9ccaf9d
fix: Use useChartColorMap hook in stories, replace inline styles
talissoncosta aaa56af
refactor: Inline getCSSVar into useChartColors, add explanatory comments
talissoncosta 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { useMemo } from 'react' | ||
| import { CHART_COLOURS } from 'common/theme/tokens' | ||
|
|
||
| /** | ||
| * Reads the computed value of CSS custom properties from the document root. | ||
| * | ||
| * Why not import values directly from tokens.ts? | ||
| * tokens.ts exports CSS var() references (e.g. 'var(--color-chart-1, #0aaddf)'), | ||
| * not raw hex strings. Recharts' `fill` prop needs actual colour values like | ||
| * '#0aaddf', not var() references. getComputedStyle resolves the var to its | ||
| * current value, which also means dark mode is respected automatically — | ||
| * the same token resolves to a different hex in light vs dark. | ||
| */ | ||
| function resolveColors(varNames: readonly string[]): string[] { | ||
| if (typeof document === 'undefined') return varNames.map(() => '') | ||
| const style = getComputedStyle(document.documentElement) | ||
| return varNames.map((name) => style.getPropertyValue(name).trim()) | ||
| } | ||
|
|
||
| /** | ||
| * Returns the resolved chart color palette for the current theme. | ||
| * | ||
| * @example | ||
| * const colors = useChartColors() | ||
| * colors[0] // '#0aaddf' in light, '#45bce0' in dark | ||
| */ | ||
| export function useChartColors(): string[] { | ||
| return useMemo(() => resolveColors(CHART_COLOURS), []) | ||
| } | ||
|
|
||
| /** | ||
| * Builds a color map from a list of series names to chart colors. | ||
| * Wraps around when there are more series than available colors. | ||
| * | ||
| * @example | ||
| * const colorMap = useChartColorMap(['js-sdk', 'python-sdk']) | ||
| * colorMap.get('js-sdk') // '#0aaddf' | ||
| */ | ||
| export function useChartColorMap(series: string[]): Map<string, string> { | ||
| const colors = useChartColors() | ||
| return useMemo(() => { | ||
| const map = new Map<string, string>() | ||
| series.forEach((name, index) => { | ||
| map.set(name, colors[index % colors.length]) | ||
| }) | ||
| return map | ||
| }, [series, colors]) | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -60,19 +60,27 @@ export const featureAnalyticsService = service | |
| preBuiltData.push(dayObj) | ||
| } | ||
|
|
||
| // Collect raw entries with labels intact for label-based grouping. | ||
| // chartData aggregates by environment (existing behaviour), | ||
|
Contributor
Author
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.
|
||
| // rawEntries preserves per-SDK labels for stacked charts (#6067). | ||
| const rawEntries: Res['environmentAnalytics'] = [] | ||
|
|
||
| responses.forEach((response, i) => { | ||
| const environment_id = query.environment_ids[i] | ||
|
|
||
| response.data?.forEach((entry) => { | ||
| rawEntries.push(entry) | ||
| const date = moment(entry.day).format('Do MMM') | ||
| const dayEntry = preBuiltData.find((d) => d.day === date) | ||
| if (dayEntry) { | ||
| dayEntry[environment_id] = entry.count // Set count for specific environment ID | ||
| dayEntry[environment_id] = entry.count | ||
| } | ||
| }) | ||
| }) | ||
| return { | ||
| data: error ? [] : preBuiltData, | ||
| data: error | ||
| ? { chartData: [], rawEntries: [] } | ||
| : { chartData: preBuiltData, rawEntries }, | ||
| error, | ||
| } | ||
| }, | ||
|
|
||
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.
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.
Recharts'
fillprop needs hex strings, not CSS var refs.getComputedStyleresolves to the current theme value automatically (dark mode respected).