/* eslint-disable camelcase */
/* eslint-disable react/prop-types */
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import {
Dropdown,
DropdownItem,
KebabToggle,
FlexItem,
Flex,
Tooltip,
} from '@patternfly/react-core';
import {
ExclamationCircleIcon,
SyncAltIcon,
CheckCircleIcon,
BanIcon,
TagIcon,
} from '@patternfly/react-icons';
import { openConfirmModal } from 'foremanReact/components/ConfirmModal';
import { APIActions } from 'foremanReact/redux/API';
import { translate as __ } from 'foremanReact/common/I18n';
import { reportToShowFormatter } from '../../Router/HostReports/IndexPage/Components/HostReportsTable/Components/Formatters';
const FailedIcon = ({ label, withMargin = false }) => (
{label}
);
const ChangedIcon = ({ label, withMargin = false }) => (
{label}
);
const NochangeIcon = ({ label }) => (
<>
{label}
>
);
export const statusSummaryFormatter = ({ change, nochange, failure }) => {
const summary = [];
if (failure)
summary.push();
if (change)
summary.push();
if (nochange) summary.push();
return summary.length ? summary : '--';
};
export const globalStatusFormatter = ({ status }) => {
switch (status) {
case 'failure':
return ;
case 'change':
return ;
case 'nochange':
return ;
default:
return (
<>
{__('Empty')}
>
);
}
};
export const keywordsFormatter = ({ keywords = [] }) => (
<>
{keywords.join(',\n')}}>
{' '}
{keywords.length}
>
);
export const ActionFormatter = ({ id, can_delete }, fetchReports) => {
const [isOpen, setOpen] = useState(false);
const dispatch = useDispatch();
const dispatchConfirm = () => {
dispatch(
openConfirmModal({
isWarning: true,
title: __('Delete report?'),
confirmButtonText: __('Delete report'),
onConfirm: () =>
dispatch(
APIActions.delete({
url: `/api/v2/host_reports/${id}`,
key: `report-${id}-DELETE`,
successToast: success => __('Report was successfully deleted'),
errorToast: error =>
__(`There was some issue deleting the report: ${error}`),
handleSuccess: fetchReports,
})
),
message: __(
'Are you sure you want to delete this report? This action is irreversible.'
),
})
);
};
const dropdownItems = [
{__('Delete')}
,
];
return (
setOpen(!v)}
toggle={}
isOpen={isOpen}
isPlain
dropdownItems={dropdownItems}
/>
);
};
export const getColumns = fetchReports => [
{
title: __('Reported at'),
formatter: ({ reported_at, can_view, id }) =>
reportToShowFormatter()(reported_at, {
rowData: { canEdit: can_view, id },
}),
width: 25,
},
{
title: __('Status'),
formatter: globalStatusFormatter,
width: 25,
},
{
title: __('Summary'),
formatter: statusSummaryFormatter,
width: 25,
},
{ title: __('Keywords'), formatter: keywordsFormatter, width: 15 },
{
title: null,
formatter: data => ActionFormatter(data, fetchReports),
width: 10,
},
];