mirror of
https://git.vectorsigma.ru/public/AdGuardHome.git
synced 2026-08-03 21:39:38 +00:00
Merge in DNS/adguard-home from ADG-10293 to ADG-10291 Squashed commit of the following: commit d488e3d3ce9c1b154dae63af0514e776430cb355 Author: Ildar Kamalov <ik@adguard.com> Date: Wed Aug 13 19:40:42 2025 +0300 fix language change commit 2c22687bae448c8de3910b90376656a5e68b3a56 Author: Ildar Kamalov <ik@adguard.com> Date: Wed Aug 13 19:38:09 2025 +0300 fix mobile links commit 372eddc1e7fe3688b59a5c8285c65ef08a852374 Author: Ildar Kamalov <ik@adguard.com> Date: Wed Aug 13 11:53:58 2025 +0300 fix lock commit3f6d759b7fAuthor: Ildar Kamalov <ik@adguard.com> Date: Tue Aug 12 16:40:31 2025 +0300 fix placeholder commit507631ab71Author: Ildar Kamalov <ik@adguard.com> Date: Tue Aug 12 16:15:57 2025 +0300 use batch commite495a5585cAuthor: Ildar Kamalov <ik@adguard.com> Date: Tue Aug 12 16:13:13 2025 +0300 review fix commit2ba671b408Author: Ildar Kamalov <ik@adguard.com> Date: Tue Aug 12 10:45:00 2025 +0300 fix commit6f696238a0Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 18:38:28 2025 +0300 fix language change commit8206f3f885Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 14:54:58 2025 +0300 fix custom radio commit0920a51c4aAuthor: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 14:30:26 2025 +0300 fix commitc7ca1e8eafAuthor: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 14:25:16 2025 +0300 fix ids commit7ecd6426d9Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 13:56:29 2025 +0300 fix constant import commit246f1277b8Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 13:46:11 2025 +0300 fix version commit0224f567e6Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 13:34:29 2025 +0300 fix version commit75c9caffbdAuthor: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 13:14:01 2025 +0300 lint fix commitd0cf6ad5abAuthor: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 12:40:49 2025 +0300 lint fix commit87eb68e519Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 12:06:35 2025 +0300 use npm commit7df7d60ec9Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 11:23:00 2025 +0300 rm unused commitc285ea978aAuthor: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 10:42:39 2025 +0300 fix commitd00f1e12b3Author: Ildar Kamalov <ik@adguard.com> Date: Mon Aug 11 09:43:35 2025 +0300 fix ... and 2 more commits
156 lines
5.5 KiB
TypeScript
156 lines
5.5 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import { Controller, useForm } from 'react-hook-form';
|
|
|
|
import intl from 'panel/common/intl';
|
|
import { Button } from 'panel/common/ui/Button';
|
|
import theme from 'panel/lib/theme';
|
|
import { QUERY_LOG_INTERVALS_DAYS, RETENTION_CUSTOM } from 'panel/helpers/constants';
|
|
|
|
import { RadioGroup } from '../SettingsGroup/RadioGroup';
|
|
import { SwitchGroup } from '../SettingsGroup';
|
|
import { IgnoredDomains } from '../IgnoredDomains';
|
|
import { getIntervalTitle, getDefaultInterval } from '../helpers';
|
|
import { RetentionCustomInput } from '../RetentionCustomInput';
|
|
|
|
export type FormValues = {
|
|
enabled: boolean;
|
|
anonymize_client_ip: boolean;
|
|
interval: number;
|
|
customInterval?: number | null;
|
|
ignored: string;
|
|
ignore_enabled: boolean;
|
|
};
|
|
|
|
type Props = {
|
|
initialValues: Partial<FormValues>;
|
|
processing: boolean;
|
|
processingReset: boolean;
|
|
onSubmit: (values: FormValues) => void;
|
|
onReset: () => void;
|
|
};
|
|
|
|
export const Form = ({ initialValues, processing, processingReset, onSubmit, onReset }: Props) => {
|
|
const {
|
|
handleSubmit,
|
|
watch,
|
|
setValue,
|
|
control,
|
|
formState: { isSubmitting },
|
|
} = useForm<FormValues>({
|
|
mode: 'onBlur',
|
|
defaultValues: {
|
|
enabled: initialValues.enabled || false,
|
|
anonymize_client_ip: initialValues.anonymize_client_ip || false,
|
|
interval: getDefaultInterval(initialValues.customInterval, initialValues.interval),
|
|
customInterval: initialValues.customInterval ?? undefined,
|
|
ignored: initialValues.ignored || '',
|
|
ignore_enabled: initialValues.ignore_enabled || true,
|
|
},
|
|
});
|
|
|
|
const intervalValue = watch('interval');
|
|
const customIntervalValue = watch('customInterval');
|
|
const ignoreEnabled = watch('ignore_enabled');
|
|
|
|
useEffect(() => {
|
|
if (QUERY_LOG_INTERVALS_DAYS.includes(intervalValue)) {
|
|
setValue('customInterval', undefined);
|
|
}
|
|
}, [intervalValue]);
|
|
|
|
const onSubmitForm = (data: FormValues) => {
|
|
onSubmit(data);
|
|
};
|
|
|
|
const disableSubmit = isSubmitting || processing || (intervalValue === RETENTION_CUSTOM && !customIntervalValue);
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
|
<Controller
|
|
name="enabled"
|
|
control={control}
|
|
render={({ field }) => (
|
|
<SwitchGroup
|
|
id="logs_enabled"
|
|
title={intl.getMessage('settings_log_dns_requests')}
|
|
checked={field.value}
|
|
onChange={field.onChange}
|
|
disabled={processing}
|
|
/>
|
|
)}
|
|
/>
|
|
|
|
<Controller
|
|
name="anonymize_client_ip"
|
|
control={control}
|
|
render={({ field }) => (
|
|
<SwitchGroup
|
|
id="logs_anonymize_client_ip"
|
|
title={intl.getMessage('settings_anonymize_client_ip')}
|
|
description={intl.getMessage('settings_anonymize_client_ip_desc')}
|
|
checked={field.value}
|
|
onChange={field.onChange}
|
|
disabled={processing}
|
|
/>
|
|
)}
|
|
/>
|
|
|
|
<RadioGroup
|
|
title={intl.getMessage('query_log_retention')}
|
|
disabled={processing}
|
|
value={intervalValue}
|
|
onChange={(val) => setValue('interval', Number(val))}
|
|
name="logs-interval"
|
|
options={[
|
|
{ text: getIntervalTitle(RETENTION_CUSTOM), value: RETENTION_CUSTOM },
|
|
...QUERY_LOG_INTERVALS_DAYS.map((interval) => ({
|
|
text: getIntervalTitle(interval),
|
|
value: interval,
|
|
})),
|
|
]}>
|
|
<RetentionCustomInput
|
|
control={control}
|
|
processing={processing}
|
|
intervalValue={intervalValue}
|
|
intervals={QUERY_LOG_INTERVALS_DAYS}
|
|
inputId="logs_config_custom_interval"
|
|
inputLabel={intl.getMessage('settings_log_rotation_hours')}
|
|
placeholder={intl.getMessage('settings_rotation_placeholder')}
|
|
/>
|
|
</RadioGroup>
|
|
|
|
<IgnoredDomains
|
|
control={control}
|
|
processing={processing}
|
|
ignoreEnabled={ignoreEnabled}
|
|
setValue={setValue}
|
|
switchId="logs_config_ignored_enabled"
|
|
textareaId="logs_config_ignored"
|
|
/>
|
|
|
|
<div className={theme.form.buttonGroup}>
|
|
<Button
|
|
type="submit"
|
|
id="logs_config_save"
|
|
variant="primary"
|
|
size="small"
|
|
disabled={disableSubmit}
|
|
className={theme.form.button}>
|
|
{intl.getMessage('save')}
|
|
</Button>
|
|
|
|
<Button
|
|
type="button"
|
|
id="logs_config_clear"
|
|
variant="secondary"
|
|
size="small"
|
|
onClick={onReset}
|
|
disabled={processingReset}
|
|
className={theme.form.button}>
|
|
{intl.getMessage('clear_query_log')}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|