-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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
TablePanel: Add support for Count calculation per column or per entire dataset #58134
Changes from 3 commits
fc371ae
af6d441
aca5c2b
a3951f8
f8eb71e
480930f
d5cce99
bf6329f
ba8802f
1c6a30b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,13 @@ export const plugin = new PanelPlugin<PanelOptions, TableFieldOptions>(TablePane | |
defaultValue: [ReducerID.sum], | ||
showIf: (cfg) => cfg.footer?.show, | ||
}) | ||
.addBooleanSwitch({ | ||
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. Looks good! I'm thinking we should add a description here and maybe change the name of this option as well to make it more clear. 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. And I'd say we might to reverse the language, like "Count Per Field" with a description along the lines of "Count the non-empty results of each field separately" 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. From this I understand we also reverse the functionality. E.g: We show a count for all fields in one column and when the "Count Per Field" switch is active we show a count for each field. This would change all existing table panels for the users. Is this something we'd want? |
||
path: 'footer.countAll', | ||
category: [footerCategory], | ||
name: 'Count all data', | ||
defaultValue: defaultPanelOptions.footer?.countAll, | ||
showIf: (cfg) => cfg.footer?.reducer?.length === 1 && cfg.footer?.reducer[0] === ReducerID.count, | ||
}) | ||
.addMultiSelect({ | ||
path: 'footer.fields', | ||
category: [footerCategory], | ||
|
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.
Can we properly narrow the type down, rather than just hoping for the best that the value is a string?
We want to avoid adding more exceptions to .betterer.results that we only have to go in and clean up 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.
Alternatively, rename this file to
.js
and remove all typescript and be prepared to justify the decision 😅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.
Is the
footerValues
property really potentially an array of arrays (of an objects)? Or is the wrong type being used here?At the moment it looks like if this function is called incorrectly it can lead to a runtime crash as react tries to render an object. I see maybe two approaches to fix this directly here:
Throw an exception directly if the input doesn't match our expectations. This is the current behaviour of the code, but it's being honest about it's potential to crash
Or, all
.toString()
on the value if it's not a string. This can still (silently) give you something undesirable like[object Object]
being printed, but at least grafana doesn't crash.