From 9b1175a8883aad828689a34e6b922a273ef98f1d Mon Sep 17 00:00:00 2001 From: Felix Mosheev <9304194+felixmosh@users.noreply.github.com> Date: Sun, 4 Aug 2024 11:02:13 +0300 Subject: [PATCH] feat: allow overriding pollInterval value from server config, closes #789 --- packages/api/typings/app.ts | 4 +++ .../SettingsModal/SettingsModal.tsx | 36 ++++++++++--------- packages/ui/src/index.tsx | 4 +++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/api/typings/app.ts b/packages/api/typings/app.ts index febd3736..89c8c6b5 100644 --- a/packages/api/typings/app.ts +++ b/packages/api/typings/app.ts @@ -212,6 +212,10 @@ export type UIConfig = Partial<{ favIcon: FavIcon; locale: { lng?: string }; dateFormats?: DateFormats; + pollingInterval?: Partial<{ + showSetting: boolean; + forceInterval: number; + }>; }>; export type FavIcon = { diff --git a/packages/ui/src/components/SettingsModal/SettingsModal.tsx b/packages/ui/src/components/SettingsModal/SettingsModal.tsx index 2bd1a742..d8dcc38a 100644 --- a/packages/ui/src/components/SettingsModal/SettingsModal.tsx +++ b/packages/ui/src/components/SettingsModal/SettingsModal.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { useTranslation } from 'react-i18next'; import { useSettingsStore } from '../../hooks/useSettings'; +import { useUIConfig } from '../../hooks/useUIConfig'; import { InputField } from '../Form/InputField/InputField'; import { SelectField } from '../Form/SelectField/SelectField'; import { SwitchField } from '../Form/SwitchField/SwitchField'; @@ -14,6 +15,7 @@ export interface SettingsModalProps { } const pollingIntervals = [-1, 3, 5, 10, 20, 60, 60 * 5, 60 * 15]; +const languages = ['en-US', 'fr-FR', 'pt-BR', 'zh-CN']; export const SettingsModal = ({ open, onClose }: SettingsModalProps) => { const { @@ -29,8 +31,8 @@ export const SettingsModal = ({ open, onClose }: SettingsModalProps) => { defaultJobTab, setSettings, } = useSettingsStore((state) => state); + const { pollingInterval: uiConfigPollingInterval } = useUIConfig(); const { t, i18n } = useTranslation(); - const languages = ['en-US', 'fr-FR', 'pt-BR', 'zh-CN']; return ( @@ -44,21 +46,23 @@ export const SettingsModal = ({ open, onClose }: SettingsModalProps) => { setSettings({ language: event.target.value }); }} /> - ({ - text: - interval < 0 - ? t('SETTINGS.POLLING_OPTIONS.OFF') - : Math.floor(interval / 60) === 0 - ? t('SETTINGS.POLLING_OPTIONS.SECS', { count: interval }) - : t('SETTINGS.POLLING_OPTIONS.MINS', { count: interval / 60 }), - value: `${interval}`, - }))} - value={`${pollingInterval}`} - onChange={(event) => setSettings({ pollingInterval: +event.target.value })} - /> + {uiConfigPollingInterval?.showSetting !== false && ( + ({ + text: + interval < 0 + ? t('SETTINGS.POLLING_OPTIONS.OFF') + : Math.floor(interval / 60) === 0 + ? t('SETTINGS.POLLING_OPTIONS.SECS', { count: interval }) + : t('SETTINGS.POLLING_OPTIONS.MINS', { count: interval / 60 }), + value: `${interval}`, + }))} + value={`${pollingInterval}`} + onChange={(event) => setSettings({ pollingInterval: +event.target.value })} + /> + )}