mirror of
https://github.com/apache/superset.git
synced 2026-04-25 11:04:48 +00:00
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:
committed by
GitHub
parent
28e729b835
commit
830f2e71d3
@@ -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;
|
||||
}, {}),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user