2022-04-26 05:14:48 +00:00
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
|
2022-05-23 07:57:22 +00:00
|
|
|
import { useSettings } from '@/portainer/settings/queries';
|
2022-04-26 05:14:48 +00:00
|
|
|
import { r2a } from '@/react-tools/react2angular';
|
|
|
|
|
2022-06-17 16:18:42 +00:00
|
|
|
import { FormControl } from '@@/form-components/FormControl';
|
|
|
|
import { Select } from '@@/form-components/Input';
|
|
|
|
|
2022-04-26 05:14:48 +00:00
|
|
|
interface Props {
|
|
|
|
value: number;
|
|
|
|
onChange(value: number): void;
|
|
|
|
isDefaultHidden?: boolean;
|
|
|
|
label?: string;
|
|
|
|
tooltip?: string;
|
2022-06-01 04:28:31 +00:00
|
|
|
readonly?: boolean;
|
2022-04-26 05:14:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const checkinIntervalOptions = [
|
|
|
|
{ label: 'Use default interval', value: 0 },
|
|
|
|
{
|
|
|
|
label: '5 seconds',
|
|
|
|
value: 5,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '10 seconds',
|
|
|
|
value: 10,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: '30 seconds',
|
|
|
|
value: 30,
|
|
|
|
},
|
|
|
|
{ label: '5 minutes', value: 300 },
|
|
|
|
{ label: '1 hour', value: 3600 },
|
|
|
|
{ label: '1 day', value: 86400 },
|
|
|
|
];
|
|
|
|
|
|
|
|
export function EdgeCheckinIntervalField({
|
|
|
|
value,
|
2022-06-01 04:28:31 +00:00
|
|
|
readonly,
|
2022-04-26 05:14:48 +00:00
|
|
|
onChange,
|
|
|
|
isDefaultHidden = false,
|
|
|
|
label = 'Poll frequency',
|
|
|
|
tooltip = 'Interval used by this Edge agent to check in with the Portainer instance. Affects Edge environment management and Edge compute features.',
|
|
|
|
}: Props) {
|
|
|
|
const options = useOptions(isDefaultHidden);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<FormControl inputId="edge_checkin" label={label} tooltip={tooltip}>
|
|
|
|
<Select
|
|
|
|
value={value}
|
|
|
|
onChange={(e) => {
|
|
|
|
onChange(parseInt(e.currentTarget.value, 10));
|
|
|
|
}}
|
|
|
|
options={options}
|
2022-06-01 04:28:31 +00:00
|
|
|
disabled={readonly}
|
2022-04-26 05:14:48 +00:00
|
|
|
/>
|
|
|
|
</FormControl>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export const EdgeCheckinIntervalFieldAngular = r2a(EdgeCheckinIntervalField, [
|
|
|
|
'value',
|
|
|
|
'onChange',
|
2022-05-24 05:35:20 +00:00
|
|
|
'isDefaultHidden',
|
|
|
|
'tooltip',
|
|
|
|
'label',
|
2022-06-01 04:28:31 +00:00
|
|
|
'readonly',
|
2022-04-26 05:14:48 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
function useOptions(isDefaultHidden: boolean) {
|
|
|
|
const [options, setOptions] = useState(checkinIntervalOptions);
|
|
|
|
|
|
|
|
const settingsQuery = useSettings(
|
|
|
|
(settings) => settings.EdgeAgentCheckinInterval
|
|
|
|
);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isDefaultHidden) {
|
|
|
|
setOptions(checkinIntervalOptions.filter((option) => option.value !== 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDefaultHidden && typeof settingsQuery.data !== 'undefined') {
|
|
|
|
setOptions((options) => {
|
|
|
|
let label = `${settingsQuery.data} seconds`;
|
|
|
|
const option = options.find((o) => o.value === settingsQuery.data);
|
|
|
|
if (option) {
|
|
|
|
label = option.label;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
value: 0,
|
|
|
|
label: `Use default interval (${label})`,
|
|
|
|
},
|
|
|
|
...options.slice(1),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [settingsQuery.data, setOptions, isDefaultHidden]);
|
|
|
|
|
|
|
|
return options;
|
|
|
|
}
|