-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(explore): Improve conversion to TimeSeries
#100532
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
gggritso
merged 10 commits into
master
from
georgegritsouk/dain-119-legend-name-formatter-incorrectly-treats-cache-keys-as
Oct 2, 2025
+174
−114
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e7a94ca
Improve chart rendering for "Other" series
gggritso 26a9d6e
Improve convertion to `TimeSeries`
gggritso 34264a1
Remove unused helper
gggritso ea8e062
Remove unused import
gggritso effbdf9
Merge branch 'master' into georgegritsouk/dain-119-legend-name-format…
gggritso 3cfd9cc
Add more robust order determination
gggritso 13b5c91
Fix comment typo
gggritso f70e6aa
Whoops
gggritso f66855d
Allow mismatched value and key counts
gggritso 5325425
Remove stray tests
gggritso 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import {parseGroupBy} from './parseGroupBy'; | ||
|
||
describe('parseGroupBy', () => { | ||
it('returns undefined for "Other" group name', () => { | ||
const result = parseGroupBy('Other', ['field1', 'field2']); | ||
expect(result).toBeUndefined(); | ||
}); | ||
|
||
it('parses single field and value correctly', () => { | ||
const result = parseGroupBy('value1', ['field1']); | ||
expect(result).toEqual([{key: 'field1', value: 'value1'}]); | ||
}); | ||
|
||
it('parses multiple fields and values correctly', () => { | ||
const result = parseGroupBy('value1,value2,value3', ['field1', 'field2', 'field3']); | ||
expect(result).toEqual([ | ||
{key: 'field1', value: 'value1'}, | ||
{key: 'field2', value: 'value2'}, | ||
{key: 'field3', value: 'value3'}, | ||
]); | ||
}); | ||
|
||
it('handles more values than fields by using empty strings for extra values', () => { | ||
const result = parseGroupBy('value1,value2', ['field1']); | ||
expect(result).toEqual([ | ||
{key: 'field1', value: 'value1'}, | ||
{key: '', value: 'value2'}, | ||
]); | ||
}); | ||
|
||
it('handles more fields than values by using empty strings for missing values', () => { | ||
const result = parseGroupBy('value1', ['field1', 'field2']); | ||
expect(result).toEqual([ | ||
{key: 'field1', value: 'value1'}, | ||
{key: 'field2', value: ''}, | ||
]); | ||
}); | ||
|
||
it('handles empty strings in values', () => { | ||
const result = parseGroupBy('value1,,value3', ['field1', 'field2', 'field3']); | ||
expect(result).toEqual([ | ||
{key: 'field1', value: 'value1'}, | ||
{key: 'field2', value: ''}, | ||
{key: 'field3', value: 'value3'}, | ||
]); | ||
}); | ||
|
||
it('handles empty fields array', () => { | ||
const result = parseGroupBy('', []); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
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,26 @@ | ||
import zipWith from 'lodash/zipWith'; | ||
|
||
import type {TimeSeriesGroupBy} from 'sentry/views/dashboards/widgets/common/types'; | ||
|
||
export function parseGroupBy( | ||
groupName: string, | ||
fields: string[] | ||
): TimeSeriesGroupBy[] | undefined { | ||
if (groupName === 'Other') { | ||
return undefined; | ||
} | ||
|
||
const groupKeys = fields; | ||
const groupValues = groupName.split(','); | ||
|
||
const groupBys = zipWith(groupKeys, groupValues, (key, value) => { | ||
return { | ||
key: key ?? '', | ||
value: value ?? '', | ||
}; | ||
}).filter(groupBy => { | ||
return groupBy.key || groupBy.value; | ||
}); | ||
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. |
||
|
||
return groupBys.length > 0 ? groupBys : undefined; | ||
} |
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.
This makes the assumption that each group value won't have any commas.
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.
🤔 it does make that assumption, yes. I don't think there's actually any way for me to figure out which commas are the delimiters, even knowing how many fields there were originally ... but this problem will go away when we use
/events-timeseries/
which separates each field completelyThere 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 ended up making this more permissive, and creating empty keys/values when necessary. The values end up getting concatenated with commas later anyway and the keys are not readily visible to anyone, so we should be good. Good catch, thanks!