65 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-07-09 16:56:40 +02:00
import React, { memo } from 'react';
import PropTypes from 'prop-types';
2019-07-09 19:38:39 +02:00
import { toString } from 'lodash';
2019-07-09 16:56:40 +02:00
import { IcoContainer } from 'strapi-helper-plugin';
2019-07-09 19:38:39 +02:00
import { useListView } from '../../contexts/ListView';
2019-07-09 16:56:40 +02:00
import CustomInputCheckbox from '../CustomInputCheckbox';
import { ActionContainer, Truncate, Truncated } from './styledComponents';
function Row({ isBulkable, row, headers }) {
2019-07-10 09:12:48 +02:00
const { entriesToDelete, onChangeBulk, onClickDelete } = useListView();
2019-07-10 08:43:40 +02:00
2019-07-09 16:56:40 +02:00
return (
<>
{isBulkable && (
<td onClick={e => e.stopPropagation()} key="i">
2019-07-09 19:38:39 +02:00
<CustomInputCheckbox
name={row.id}
onChange={onChangeBulk}
value={
entriesToDelete.filter(id => toString(id) === toString(row.id))
.length > 0
}
/>
2019-07-09 16:56:40 +02:00
</td>
)}
{headers.map(header => {
//
return (
<td key={header.name}>
<Truncate>
<Truncated>{row[header.name]}</Truncated>
</Truncate>
</td>
);
})}
<ActionContainer>
<IcoContainer
icons={[
{ icoType: 'pencil', onClick: () => {} },
{
id: row.id,
icoType: 'trash',
2019-07-10 09:12:48 +02:00
onClick: () => {
onClickDelete(row.id);
},
2019-07-09 16:56:40 +02:00
},
]}
/>
</ActionContainer>
</>
);
}
Row.propTypes = {
headers: PropTypes.array.isRequired,
isBulkable: PropTypes.bool.isRequired,
row: PropTypes.object.isRequired,
};
export default memo(Row);