feat(explore): Allow using time formatter on temporal columns in data table (#18569)

* feat(explore): Allow using time formatter on temporal columns in data table

* Fix data table loading

* Return colnames and coltypes from results request

* Fix types

* Fix tests

* Fix copy button

* Fix df is none

* Fix test

* Address comments

* Move useTimeFormattedColumns out of useTableColumns

* Make reducer more readable
This commit is contained in:
Kamil Gabryjelski
2022-02-09 10:29:11 +01:00
committed by GitHub
parent 28e729b835
commit 830f2e71d3
14 changed files with 475 additions and 88 deletions

View File

@@ -20,6 +20,7 @@ import {
SupersetClient,
getTimeFormatter,
TimeFormats,
ensureIsArray,
} from '@superset-ui/core';
// ATTENTION: If you change any constants, make sure to also change constants.py
@@ -107,18 +108,24 @@ export function prepareCopyToClipboardTabularData(data, columns) {
return result;
}
export function applyFormattingToTabularData(data) {
if (!data || data.length === 0 || !('__timestamp' in data[0])) {
export function applyFormattingToTabularData(data, timeFormattedColumns) {
if (
!data ||
data.length === 0 ||
ensureIsArray(timeFormattedColumns).length === 0
) {
return data;
}
return data.map(row => ({
...row,
/* eslint-disable no-underscore-dangle */
__timestamp:
row.__timestamp === 0 || row.__timestamp
? DATETIME_FORMATTER(new Date(row.__timestamp))
: row.__timestamp,
/* eslint-enable no-underscore-dangle */
...timeFormattedColumns.reduce((acc, colName) => {
if (row[colName] !== null && row[colName] !== undefined) {
acc[colName] = DATETIME_FORMATTER(row[colName]);
}
return acc;
}, {}),
}));
}