-
Notifications
You must be signed in to change notification settings - Fork 272
feat(legacy-plugin-chart-pivot-table): add support for timestamp format #734
feat(legacy-plugin-chart-pivot-table): add support for timestamp format #734
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/superset/superset-ui/b1g9da0a0 |
Codecov Report
@@ Coverage Diff @@
## master #734 +/- ##
==========================================
+ Coverage 24.35% 24.38% +0.02%
==========================================
Files 340 340
Lines 7637 7662 +25
Branches 929 935 +6
==========================================
+ Hits 1860 1868 +8
- Misses 5704 5721 +17
Partials 73 73
Continue to review full report at Codecov.
|
@@ -44,25 +45,37 @@ const propTypes = { | |||
}; | |||
|
|||
function PivotTable(element, props) { | |||
const { data, height, columnFormats, numberFormat, numGroups, verboseMap } = props; | |||
const { data, height, columnFormats, dateFormat, numberFormat, numGroups, verboseMap } = props; | |||
|
|||
const { html, columns } = data; | |||
const container = element; | |||
const $container = $(element); |
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.
jQuery!? 😭
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.
Unfortunately pivot table still uses jQuery.dataTables
.
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.
Hey, if it works it works! 😄
|
||
const { html, columns } = data; | ||
const container = element; | ||
const $container = $(element); | ||
const dateFormatter = | ||
dateFormat === 'smart_date' ? smartDateFormatter : getTimeFormatter(dateFormat); |
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.
getTimeFormatter('smart_date')
should work just fine. But since we are here, can you update it to follow the same logic as the table chart?
superset-ui/plugins/plugin-chart-table/src/transformProps.ts
Lines 138 to 151 in d323ce8
// Use granularity for "Adaptive Formatting" (smart_date) | |
const timeFormat = format || tableTimestampFormat; | |
formatter = getTimeFormatter(timeFormat); | |
if (timeFormat === smartDateFormatter.id) { | |
if (isTimeColumn(key)) { | |
formatter = getTimeFormatterForGranularity(granularity); | |
} else if (format) { | |
formatter = getTimeFormatter(format); | |
} else { | |
// return the identity string when datasource level formatter is not set | |
// and table timestamp format is set to Adaptive Formatting | |
formatter = String; | |
} | |
} |
It has fallbacks to d3-format in pre-defined columns and uses Time Grain for smart_date
.
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.
If the code was hard to follow for you, I can also update this later and refactor these logics into some kind of common utilities.
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.
Thanks for this reference! I didn't have strong opinions here aka. I was just out to make this work. I'll digest the table chart logic and see if it makes sense for me to streamline here 👍
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.
@ktmud I implemented a slightly modified version of your formatter that felt most suitable for this slightly simpler case. Does it make sense to you?
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.
Looks good! Thanks for the update. Do you mind adding a datetime column to Storybook as well?
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.
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 @ktmud 's comment make sense. At minimum I would recommend updating this line.
const dateFormatter =
dateFormat === 'smart_date' ? smartDateFormatter : getTimeFormatter(dateFormat);
to
const dateFormatter = getTimeFormatter(dateFormat);
Thanks @kristw , I'll update accordingly 👍 |
I used superset-ui/plugins/plugin-chart-table/src/TableChart.tsx Lines 91 to 98 in d323ce8
In the future we should probably move the SVG icons from |
@ktmud I was unsure how to apply this snippet to this code, as it doesn't seem to be natively React. Perhaps it's best if we merge this as-is and leave this fix for later? |
Sounds good |
🏆 Enhancements
This adds support for formatted dates on
pivot-table
. This is done by prefixing date values with__timestamp:
, after which they can be identified and parsed into formattable date objects. In addition sorting is done based on the epoch value, meaning that the format won't affect the sorting order. Other changes:Query
pane)AFTER:
BEFORE: