import React from 'react'
import PropTypes from 'prop-types'
import Table from '../../../../common/Table/Table'
import LinkCell from '../../../../common/Table/LinkCell'
import CheckboxCell from '../../../../common/Table/CheckboxCell'
import SortableTh from '../../../../common/Table/SortableTh'
import DeletePopup from './DeletePopup'
import Toggler from '../../../../common/Table/Toggler'
import { addOrdinalSuffix, padLeft } from '../../../../../common/StringUtils'
import DeleteButton from '../../../../common/Table/DeleteButton'
import Restrictions from '../../../../common/Restrictions/Restrictions'
export class GenericTable extends React.Component {
static propTypes = {
t: PropTypes.func.isRequired,
type: PropTypes.string.isRequired,
tableState: PropTypes.object.isRequired,
actions: PropTypes.object.isRequired,
tableActions: PropTypes.object.isRequired,
deleteSingleText: PropTypes.string.isRequired,
deleteMultipleText: PropTypes.string.isRequired
};
onDeleteButtonClick = () => {
const { tableState, tableActions } = this.props
tableActions.confirmDelete(tableState.selectedIds)
};
fetchData = (page, pageSize, sorted) => {
const { tableActions } = this.props
const params = {
page: page + 1,
limit: pageSize
}
if (sorted.length) {
const sortedField = sorted[0]
params['sortField'] = sortedField.id
params['sortDirection'] = sortedField.desc ? 'desc' : 'asc'
}
tableActions.loadTable(params)
};
selectAllAction = () => {
const { tableActions } = this.props
tableActions.selectTableAllRows()
};
selectRowAction = (itemId) => {
const { tableActions } = this.props
tableActions.selectTableRow(itemId)
};
deleteRowAction = (itemId) => {
const { tableActions } = this.props
tableActions.confirmDelete([itemId])
};
nameClickAction = (item) => {
//implement in subclasses
};
onActivateButtonClick = () => {
const { tableState, tableActions } = this.props
tableActions.toggleActive(tableState.selectedIds, true)
};
onPauseButtonClick = () => {
const { tableState, tableActions } = this.props
tableActions.toggleActive(tableState.selectedIds, false)
};
scheduleFormat (schedules) {
const { t } = this.props
if (!schedules) {
return ''
} else if (schedules.length === 0) {
return 'n/a'
} else if (schedules.length === 1) {
const schedule = schedules[0]
if (schedule.type === 'daily') {
const time = t(`notificationsTab.form.time.${schedule.time}`)
const days = t(`notificationsTab.form.days.${schedule.days}`)
return `${days}, ${time}`
} else if (schedule.type === 'weekly') {
const period = t(`notificationsTab.form.period.${schedule.period}`)
const day = t(`notificationsTab.form.day.${schedule.day}`)
const hour = padLeft(schedule.hour.toString(), 2)
const minute = padLeft(schedule.minute.toString(), 2)
return `${period} ${day}, ${hour}:${minute}`
} else if (schedule.type === 'monthly') {
const monthDay = addOrdinalSuffix(schedule.day)
const hour = padLeft(schedule.hour.toString(), 2)
const minute = padLeft(schedule.minute.toString(), 2)
return `${monthDay} of the month, ${hour}:${minute}`
}
return ''
} else {
return (
schedules.length + ' ' + this.props.t('notificationsTab.scheduledTimes')
)
}
}
getRestrictions (restrictions) {
if (!restrictions) return null
return (