diff --git a/src/plugins/point_in_time_management/public/components/pit_table/empty_state/empty_state.tsx b/src/plugins/point_in_time_management/public/components/pit_table/empty_state/empty_state.tsx index 3d8679cd1351..22a4a77d8b7f 100644 --- a/src/plugins/point_in_time_management/public/components/pit_table/empty_state/empty_state.tsx +++ b/src/plugins/point_in_time_management/public/components/pit_table/empty_state/empty_state.tsx @@ -6,27 +6,33 @@ import { EuiButton, EuiEmptyPrompt } from '@elastic/eui'; import { FormattedMessage } from '@osd/i18n/react'; import React from 'react'; +import { History } from 'history'; +import { CreateButton } from '../../create_button'; -export const EmptyState = () => ( - - -

- } - actions={ - - - - } - /> -); +interface Props { + history: History; +} + +export const EmptyState = ({ history }: Props) => { + console.log('history in empty state', history); + const createButton = ( + + ); + + return ( + + +

+ } + actions={createButton} + /> + ); +}; export const NoDataSourceState = () => ( { http, } = useOpenSearchDashboards().services; - const history = props.history; + const history: History = props.history; const dataSourceProp = props.location && props.location.state; useMount(() => { @@ -99,13 +105,15 @@ const PITTable = (props: RouteComponentProps) => { const [loading, setLoading] = useState(false); const [pits, setPits] = useState([]); const [pitsToDelete, setPitsToDelete] = useState([]); + const [pitToAddTime, setPitToAddTime] = useState([]); const [selectedPits, setSelectedPits] = useState([]); // const [dashboardPits, setDashboardPits] = useState([]); - const [message, setMessage] = useState(); + const [message, setMessage] = useState(); const [dataSources, setDataSources] = useState([defaultDataSource]); const [dataSource, setDataSource] = useState(''); const [isModalVisible, setIsModalVisible] = useState(false); + const [isAddTimeModalVisible, setIsAddTimeModalVisible] = useState(false); useEffectOnce(() => { fetchDataSources(); @@ -421,18 +429,129 @@ const PITTable = (props: RouteComponentProps) => { return
{modal}
; }; + const AddTimeModal = ({}) => { + const closeModal = () => { + setIsAddTimeModalVisible(false); + }; + + const [addTimeHr, setAddTimeHr] = useState(0); + const [addTimeMin, setAddTimeMin] = useState(0); + const [addTime, setAddTime] = useState(0); + + const onChangeTimeHr = (e) => { + setAddTimeHr(parseInt(e.target.value)); + setAddTime(60 * parseInt(e.target.value) + addTimeMin); + }; + + const onChangeTimeMin = (e) => { + setAddTimeMin(parseInt(e.target.value)); + setAddTime(60 * addTimeHr + parseInt(e.target.value)); + }; + + const addTimeToPit = (pit) => { + console.log(addTime); + console.log('add time pit', pit); + const new_keep_alive_proposal = addTime.toString() + 'm'; + const ds = + pit.dataSource == '' + ? undefined + : dataSources.filter((x) => x.title === pit.dataSource)[0].id; + services + .addPitTime(pit.pit_id, new_keep_alive_proposal, ds) + .then(() => getPits(pit.dataSource)) + .catch(() => { + toasts.addDanger( + i18n.translate('pitManagement.pitTable.addTimeError', { + defaultMessage: 'Error while updating PIT object.', + }) + ); + }); + }; + + let modal; + + if (isAddTimeModalVisible) { + const maxTime = moment(pitToAddTime[0].expiry).diff( + moment(pitToAddTime[0].creation_time), + 'hours' + ); + console.log('maxTime', maxTime); + const maxTimeExceeded = maxTime >= 24; + if (maxTimeExceeded) { + modal = ( + + + Maximum time reached + + + + A PIT can be kept for a maximum of 24 hours. You cannot add more time to this PIT. + To extend the time, configure point_in_time.max_keep_alive or contact your + administrator. + + + + + + Cancel + + + + ); + } else { + modal = ( + { + closeModal(); + addTimeToPit(pitToAddTime[0]); + setPitToAddTime([]); + }} + confirmButtonText="Add time to PIT" + cancelButtonText="Cancel" + > + + Add an amount of time to a PIT. This amount must be greater than the keep_alive time + (x) and cannot exceed the max_keep_alive time (y). You can configure keep_alive on the + PIT object details page. + + + + + + + + + + + + + + ); + } + } + + return
{modal}
; + }; + const displayDelete = (pit) => { setPitsToDelete([pit]); setIsModalVisible(true); }; + const displayAddTime = (pit) => { + setPitToAddTime([pit]); + setIsAddTimeModalVisible(true); + }; + const actions = [ { name: 'Add Time', description: 'Add Time', icon: 'clock', type: 'icon', - onClick: fetchDataSources, + onClick: displayAddTime, }, { name: 'Configure PIT', @@ -733,6 +852,7 @@ const PITTable = (props: RouteComponentProps) => { selection={selection} /> + {/* Create PIT