Skip to content
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

Fix: Details Visualization: render date/time values as strings and not epoch time #3951

Merged
merged 1 commit into from
Jul 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions client/app/visualizations/details/DetailsRenderer.jsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
import React, { useState } from 'react';
import map from 'lodash/map';
import { map, mapValues, keyBy } from 'lodash';
import moment from 'moment';
import { RendererPropTypes } from '@/visualizations';
import { clientConfig } from '@/services/auth';
import Pagination from 'antd/lib/pagination';

import './details.less';

function renderValue(value, type) {
const formats = {
date: clientConfig.dateFormat,
datetime: clientConfig.dateTimeFormat,
};

if (type === 'date' || type === 'datetime') {
if (moment.isMoment(value)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if (moment.isMoment(value)) { is enough, previous if is almost useless.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's relevant to make sure we have a known format type. But it's true that it will only be a moment if it's one of those (in normal situations).

return value.format(formats[type]);
}
}

return '' + value;
}

export default function DetailsRenderer({ data }) {
const [page, setPage] = useState(0);

if (!data || !data.rows || data.rows.length === 0) {
return null;
}

const types = mapValues(keyBy(data.columns, 'name'), 'type');

// We use columsn to maintain order of columns in the view.
const columns = data.columns.map(column => column.name);
const row = data.rows[page];
Expand All @@ -23,7 +42,7 @@ export default function DetailsRenderer({ data }) {
{map(columns, key => (
<tr key={key}>
<th>{key}</th>
<td>{'' + row[key]}</td>
<td>{renderValue(row[key], types[key])}</td>
</tr>
))}
</tbody>
Expand Down