72 lines
1.7 KiB
JavaScript
Raw Normal View History

2019-07-09 16:56:40 +02:00
import React, { memo } from 'react';
2019-07-10 09:31:26 +02:00
import { withRouter } from 'react-router';
2019-07-09 16:56:40 +02:00
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';
2019-07-10 09:31:26 +02:00
function Row({ goTo, isBulkable, row, headers }) {
const { entriesToDelete, onChangeBulk, onClickDelete, slug } = useListView();
2019-07-10 08:43:40 +02:00
2019-07-09 16:56:40 +02:00
return (
<>
{isBulkable && (
2019-07-10 09:31:26 +02:00
<td 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={[
2019-07-10 09:31:26 +02:00
{
icoType: 'pencil',
onClick: () => {
goTo(row.id);
},
},
2019-07-09 16:56:40 +02:00
{
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 = {
2019-07-10 09:31:26 +02:00
goTo: PropTypes.func.isRequired,
2019-07-09 16:56:40 +02:00
headers: PropTypes.array.isRequired,
isBulkable: PropTypes.bool.isRequired,
row: PropTypes.object.isRequired,
};
2019-07-10 09:31:26 +02:00
export default withRouter(memo(Row));