import React, { memo, useCallback } from 'react'; import { withRouter } from 'react-router'; import PropTypes from 'prop-types'; import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash'; import moment from 'moment'; import { IcoContainer, useGlobalContext } from 'strapi-helper-plugin'; import useListView from '../../hooks/useListView'; import CustomInputCheckbox from '../CustomInputCheckbox'; import MediaPreviewList from '../MediaPreviewList'; import { ActionContainer, Truncate, Truncated } from './styledComponents'; import DATE_FORMATS from './DATE_FORMATS'; const dateToUtcTime = date => moment.parseZone(date).utc(); const getDisplayedValue = (type, value, name) => { switch (toLower(type)) { case 'string': case 'text': case 'email': case 'enumeration': return (value && !isEmpty(toString(value))) || name === 'id' ? toString(value) : '-'; case 'float': case 'integer': case 'biginteger': case 'decimal': return !isNull(value) ? toString(value) : '-'; case 'boolean': return value !== null ? toString(value) : '-'; case 'date': case 'datetime': case 'timestamp': { if (value == null) { return '-'; } const date = value && isObject(value) && value._isAMomentObject === true ? JSON.stringify(value) : value; return dateToUtcTime(date).format(DATE_FORMATS[type]); } case 'password': return '••••••••'; case 'media': case 'file': case 'files': return value; case 'time': { const [hour, minute, second] = value.split(':'); const timeObj = { hour, minute, second, }; const date = moment().set(timeObj); return dateToUtcTime(date).format(DATE_FORMATS.time); } default: return '-'; } }; function Row({ goTo, isBulkable, row, headers }) { const { entriesToDelete, onChangeBulk, onClickDelete, schema, } = useListView(); const memoizedDisplayedValue = useCallback( name => { const type = get(schema, ['attributes', name, 'type'], 'string'); return getDisplayedValue(type, row[name], name); }, [row, schema] ); const { emitEvent } = useGlobalContext(); return ( <> {isBulkable && (