Skip to content

Commit

Permalink
fix(plugin-chart-table): better rendering for temporal columns (#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud authored and zhaoyongjie committed Nov 26, 2021
1 parent d3d343d commit 79f67fe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ export default function buildQuery(formData: TableChartFormData) {
const { percent_metrics: percentMetrics, order_desc: orderDesc = false } = formData;
const queryMode = getQueryMode(formData);
const sortByMetric = ensureIsArray(formData.timeseries_limit_metric)[0];
return buildQueryContext(formData, baseQueryObject => {
let formDataCopy = formData;

// never include time in raw records mode
if (queryMode === QueryMode.raw) {
formDataCopy = {
...formData,
include_time: false,
};
}

return buildQueryContext(formDataCopy, baseQueryObject => {
let { metrics, orderby } = baseQueryObject;
let postProcessing: PostProcessingRule[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
smartDateFormatter,
getTimeFormatterForGranularity,
TimeFormatter,
TimeFormats,
GenericDataType,
getMetricLabel,
} from '@superset-ui/core';
Expand All @@ -34,6 +35,7 @@ import DateWithFormatter from './utils/DateWithFormatter';
import { TableChartProps, TableChartTransformedProps, DataColumnMeta } from './types';

const { PERCENT_3_POINT } = NumberFormats;
const { DATABASE_DATETIME } = TimeFormats;
const TIME_COLUMN = '__timestamp';

function isTimeColumn(key: string) {
Expand Down Expand Up @@ -114,9 +116,12 @@ const processColumns = memoizeOne(function processColumns(props: TableChartProps
} else if (format) {
// other columns respect the column-specific format
formatter = getTimeFormatter(format);
} else if (isNumeric(key, records)) {
// if column is numeric values, it is considered a timestamp64
formatter = getTimeFormatter(DATABASE_DATETIME);
} else {
// if no column-specific format, use smart_date
formatter = smartDateFormatter;
// if no column-specific format, print cell as is
formatter = String;
}
} else if (timeFormat) {
formatter = getTimeFormatter(timeFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface TableChartData {
export type TableChartFormData = QueryFormData & {
align_pn?: boolean;
color_pn?: boolean;
include_time?: boolean;
include_search?: boolean;
query_mode?: QueryMode;
page_length?: string | number | null; // null means auto-paginate
Expand Down

0 comments on commit 79f67fe

Please sign in to comment.