Merge: + client: show date in query logs

Close #1202

* commit 'af7b9523b5732e708bf29d1dc8102887eece93b5':
  rewrite using isToday helper
  + client: add jsdocs with returning format of date format functions
  + client: show date in query logs
This commit is contained in:
Artem Baskal 2020-01-20 15:02:29 +03:00
commit 3166607540
2 changed files with 20 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import { HashLink as Link } from 'react-router-hash-link';
import { import {
formatTime, formatTime,
formatDateTime, formatDateTime,
isToday,
} from '../../helpers/helpers'; } from '../../helpers/helpers';
import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants'; import { SERVICES, FILTERED_STATUS, TABLE_DEFAULT_PAGE_SIZE } from '../../helpers/constants';
import { getTrackerData } from '../../helpers/trackers/trackers'; import { getTrackerData } from '../../helpers/trackers/trackers';
@ -116,9 +117,9 @@ class Logs extends Component {
getTimeCell = ({ value }) => ( getTimeCell = ({ value }) => (
<div className="logs__row"> <div className="logs__row">
<span className="logs__text" title={formatDateTime(value)}> <span className="logs__text" title={formatDateTime(value)}>
{formatTime(value)} {isToday(value) ? formatTime(value) : formatDateTime(value)}
</span> </span>
</div> </div>
); );
@ -257,7 +258,7 @@ class Logs extends Component {
{ {
Header: t('time_table_header'), Header: t('time_table_header'),
accessor: 'time', accessor: 'time',
maxWidth: 100, minWidth: 105,
Cell: this.getTimeCell, Cell: this.getTimeCell,
}, },
{ {

View File

@ -5,6 +5,7 @@ import subHours from 'date-fns/sub_hours';
import addHours from 'date-fns/add_hours'; import addHours from 'date-fns/add_hours';
import addDays from 'date-fns/add_days'; import addDays from 'date-fns/add_days';
import subDays from 'date-fns/sub_days'; import subDays from 'date-fns/sub_days';
import isSameDay from 'date-fns/is_same_day';
import round from 'lodash/round'; import round from 'lodash/round';
import axios from 'axios'; import axios from 'axios';
import i18n from 'i18next'; import i18n from 'i18next';
@ -19,11 +20,19 @@ import {
DNS_RECORD_TYPES, DNS_RECORD_TYPES,
} from './constants'; } from './constants';
/**
* @param string The time to format
* @returns string Returns the time in the format HH:mm:ss
*/
export const formatTime = (time) => { export const formatTime = (time) => {
const parsedTime = dateParse(time); const parsedTime = dateParse(time);
return dateFormat(parsedTime, 'HH:mm:ss'); return dateFormat(parsedTime, 'HH:mm:ss');
}; };
/**
* @param string The date to format
* @returns string Returns the date and time in the format DD/MM/YYYY, HH:mm
*/
export const formatDateTime = (dateTime) => { export const formatDateTime = (dateTime) => {
const currentLanguage = i18n.languages[0] || 'en'; const currentLanguage = i18n.languages[0] || 'en';
const parsedTime = dateParse(dateTime); const parsedTime = dateParse(dateTime);
@ -39,6 +48,12 @@ export const formatDateTime = (dateTime) => {
return parsedTime.toLocaleString(currentLanguage, options); return parsedTime.toLocaleString(currentLanguage, options);
}; };
/**
* @param string
* @returns boolean
*/
export const isToday = date => isSameDay(new Date(date), new Date());
export const normalizeLogs = logs => logs.map((log) => { export const normalizeLogs = logs => logs.map((log) => {
const { const {
time, time,