|
|
@ -9,7 +9,7 @@ import { |
|
|
|
|
|
|
|
|
|
|
|
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; |
|
|
|
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; |
|
|
|
|
|
|
|
|
|
|
|
import AddUpsInputGroup, { INPUT_ID_UPS_TYPE_ID } from './AddUpsInputGroup'; |
|
|
|
import AddUpsInputGroup, { INPUT_ID_UPS_TYPE } from './AddUpsInputGroup'; |
|
|
|
import api from '../../lib/api'; |
|
|
|
import api from '../../lib/api'; |
|
|
|
import { INPUT_ID_UPS_IP, INPUT_ID_UPS_NAME } from './CommonUpsInputGroup'; |
|
|
|
import { INPUT_ID_UPS_IP, INPUT_ID_UPS_NAME } from './CommonUpsInputGroup'; |
|
|
|
import ConfirmDialog from '../ConfirmDialog'; |
|
|
|
import ConfirmDialog from '../ConfirmDialog'; |
|
|
@ -18,11 +18,13 @@ import FlexBox from '../FlexBox'; |
|
|
|
import FormDialog from '../FormDialog'; |
|
|
|
import FormDialog from '../FormDialog'; |
|
|
|
import handleAPIError from '../../lib/handleAPIError'; |
|
|
|
import handleAPIError from '../../lib/handleAPIError'; |
|
|
|
import List from '../List'; |
|
|
|
import List from '../List'; |
|
|
|
|
|
|
|
import MessageGroup, { MessageGroupForwardedRefContent } from '../MessageGroup'; |
|
|
|
import { Panel, PanelHeader } from '../Panels'; |
|
|
|
import { Panel, PanelHeader } from '../Panels'; |
|
|
|
import periodicFetch from '../../lib/fetchers/periodicFetch'; |
|
|
|
import periodicFetch from '../../lib/fetchers/periodicFetch'; |
|
|
|
import Spinner from '../Spinner'; |
|
|
|
import Spinner from '../Spinner'; |
|
|
|
import { BodyText, HeaderText, InlineMonoText, MonoText } from '../Text'; |
|
|
|
import { BodyText, HeaderText, InlineMonoText, MonoText } from '../Text'; |
|
|
|
import useConfirmDialogProps from '../../hooks/useConfirmDialogProps'; |
|
|
|
import useConfirmDialogProps from '../../hooks/useConfirmDialogProps'; |
|
|
|
|
|
|
|
import useFormUtils from '../../hooks/useFormUtils'; |
|
|
|
import useIsFirstRender from '../../hooks/useIsFirstRender'; |
|
|
|
import useIsFirstRender from '../../hooks/useIsFirstRender'; |
|
|
|
import useProtectedState from '../../hooks/useProtectedState'; |
|
|
|
import useProtectedState from '../../hooks/useProtectedState'; |
|
|
|
|
|
|
|
|
|
|
@ -48,7 +50,7 @@ const getUpsFormData = ( |
|
|
|
INPUT_ID_UPS_IP, |
|
|
|
INPUT_ID_UPS_IP, |
|
|
|
) as HTMLInputElement; |
|
|
|
) as HTMLInputElement; |
|
|
|
|
|
|
|
|
|
|
|
const inputUpsTypeId = elements.namedItem(INPUT_ID_UPS_TYPE_ID); |
|
|
|
const inputUpsTypeId = elements.namedItem(INPUT_ID_UPS_TYPE); |
|
|
|
|
|
|
|
|
|
|
|
let upsAgent = ''; |
|
|
|
let upsAgent = ''; |
|
|
|
let upsBrand = ''; |
|
|
|
let upsBrand = ''; |
|
|
@ -101,6 +103,7 @@ const ManageUpsPanel: FC = () => { |
|
|
|
|
|
|
|
|
|
|
|
const confirmDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
const confirmDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
const formDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
const formDialogRef = useRef<ConfirmDialogForwardedRefContent>({}); |
|
|
|
|
|
|
|
const messageGroupRef = useRef<MessageGroupForwardedRefContent>({}); |
|
|
|
|
|
|
|
|
|
|
|
const [confirmDialogProps, setConfirmDialogProps] = useConfirmDialogProps(); |
|
|
|
const [confirmDialogProps, setConfirmDialogProps] = useConfirmDialogProps(); |
|
|
|
const [formDialogProps, setFormDialogProps] = useConfirmDialogProps(); |
|
|
|
const [formDialogProps, setFormDialogProps] = useConfirmDialogProps(); |
|
|
@ -116,6 +119,12 @@ const ManageUpsPanel: FC = () => { |
|
|
|
refreshInterval: 60000, |
|
|
|
refreshInterval: 60000, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formUtils = useFormUtils( |
|
|
|
|
|
|
|
[INPUT_ID_UPS_IP, INPUT_ID_UPS_NAME, INPUT_ID_UPS_TYPE], |
|
|
|
|
|
|
|
messageGroupRef, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
const { isFormInvalid } = formUtils; |
|
|
|
|
|
|
|
|
|
|
|
const buildEditUpsFormDialogProps = useCallback< |
|
|
|
const buildEditUpsFormDialogProps = useCallback< |
|
|
|
(args: APIUpsOverview[string]) => ConfirmDialogProps |
|
|
|
(args: APIUpsOverview[string]) => ConfirmDialogProps |
|
|
|
>( |
|
|
|
>( |
|
|
@ -131,6 +140,7 @@ const ManageUpsPanel: FC = () => { |
|
|
|
actionProceedText: 'Update', |
|
|
|
actionProceedText: 'Update', |
|
|
|
content: ( |
|
|
|
content: ( |
|
|
|
<EditUpsInputGroup |
|
|
|
<EditUpsInputGroup |
|
|
|
|
|
|
|
formUtils={formUtils} |
|
|
|
previous={{ |
|
|
|
previous={{ |
|
|
|
upsIPAddress, |
|
|
|
upsIPAddress, |
|
|
|
upsName, |
|
|
|
upsName, |
|
|
@ -170,13 +180,15 @@ const ManageUpsPanel: FC = () => { |
|
|
|
), |
|
|
|
), |
|
|
|
}; |
|
|
|
}; |
|
|
|
}, |
|
|
|
}, |
|
|
|
[setConfirmDialogProps, upsTemplate], |
|
|
|
[formUtils, setConfirmDialogProps, upsTemplate], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const addUpsFormDialogProps = useMemo<ConfirmDialogProps>( |
|
|
|
const addUpsFormDialogProps = useMemo<ConfirmDialogProps>( |
|
|
|
() => ({ |
|
|
|
() => ({ |
|
|
|
actionProceedText: 'Add', |
|
|
|
actionProceedText: 'Add', |
|
|
|
content: <AddUpsInputGroup upsTemplate={upsTemplate} />, |
|
|
|
content: ( |
|
|
|
|
|
|
|
<AddUpsInputGroup formUtils={formUtils} upsTemplate={upsTemplate} /> |
|
|
|
|
|
|
|
), |
|
|
|
onSubmitAppend: (event) => { |
|
|
|
onSubmitAppend: (event) => { |
|
|
|
if (!upsTemplate) { |
|
|
|
if (!upsTemplate) { |
|
|
|
return; |
|
|
|
return; |
|
|
@ -201,7 +213,7 @@ const ManageUpsPanel: FC = () => { |
|
|
|
}, |
|
|
|
}, |
|
|
|
titleText: 'Add a UPS', |
|
|
|
titleText: 'Add a UPS', |
|
|
|
}), |
|
|
|
}), |
|
|
|
[setConfirmDialogProps, upsTemplate], |
|
|
|
[formUtils, setConfirmDialogProps, upsTemplate], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const listElement = useMemo( |
|
|
|
const listElement = useMemo( |
|
|
@ -269,7 +281,18 @@ const ManageUpsPanel: FC = () => { |
|
|
|
</PanelHeader> |
|
|
|
</PanelHeader> |
|
|
|
{panelContent} |
|
|
|
{panelContent} |
|
|
|
</Panel> |
|
|
|
</Panel> |
|
|
|
<FormDialog {...formDialogProps} ref={formDialogRef} /> |
|
|
|
<FormDialog |
|
|
|
|
|
|
|
{...formDialogProps} |
|
|
|
|
|
|
|
ref={formDialogRef} |
|
|
|
|
|
|
|
preActionArea={ |
|
|
|
|
|
|
|
<MessageGroup |
|
|
|
|
|
|
|
count={1} |
|
|
|
|
|
|
|
defaultMessageType="warning" |
|
|
|
|
|
|
|
ref={messageGroupRef} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
proceedButtonProps={{ disabled: isFormInvalid }} |
|
|
|
|
|
|
|
/> |
|
|
|
<ConfirmDialog {...confirmDialogProps} ref={confirmDialogRef} /> |
|
|
|
<ConfirmDialog {...confirmDialogProps} ref={confirmDialogRef} /> |
|
|
|
</> |
|
|
|
</> |
|
|
|
); |
|
|
|
); |
|
|
|