From 5b2613524c36bf73ab067e33760d76f31c7a576a Mon Sep 17 00:00:00 2001 From: maksis Date: Sat, 28 Dec 2024 11:10:06 +0200 Subject: [PATCH] Don't display an empty checkbox in confirm dialog --- src/components/semantic/CheckboxDialog.tsx | 12 +++++++----- src/utils/DebugUtils.ts | 6 ++++++ src/utils/ValueUtils.ts | 5 +++++ src/utils/WidgetUtils.ts | 4 ++-- 4 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 src/utils/ValueUtils.ts diff --git a/src/components/semantic/CheckboxDialog.tsx b/src/components/semantic/CheckboxDialog.tsx index c516ab13..86a95a0f 100644 --- a/src/components/semantic/CheckboxDialog.tsx +++ b/src/components/semantic/CheckboxDialog.tsx @@ -28,11 +28,13 @@ const CheckboxDialog: React.FC = ({ return ( - (checked.current = state)} - caption={checkboxCaption} - /> + {checkboxCaption && ( + (checked.current = state)} + caption={checkboxCaption} + /> + )} ); }; diff --git a/src/utils/DebugUtils.ts b/src/utils/DebugUtils.ts index aaa380f3..efe25b76 100644 --- a/src/utils/DebugUtils.ts +++ b/src/utils/DebugUtils.ts @@ -1,3 +1,5 @@ +import { getRandomInt } from './ValueUtils'; + const REPORT_RERENDER = true; export const MemoReporter = REPORT_RERENDER @@ -19,3 +21,7 @@ export const MemoReporter = REPORT_RERENDER return true; } : () => undefined; // Use the default prop comparison from React.memo + +export const getDebugId = () => { + return getRandomInt(1, 1000000); +}; diff --git a/src/utils/ValueUtils.ts b/src/utils/ValueUtils.ts new file mode 100644 index 00000000..33742b85 --- /dev/null +++ b/src/utils/ValueUtils.ts @@ -0,0 +1,5 @@ +export const getRandomInt = (min: number, max: number) => { + const minCeiled = Math.ceil(min); + const maxFloored = Math.floor(max); + return Math.floor(Math.random() * (maxFloored - minCeiled) + minCeiled); // The maximum is exclusive and the minimum is inclusive +}; diff --git a/src/utils/WidgetUtils.ts b/src/utils/WidgetUtils.ts index 5c09ccec..b504e226 100644 --- a/src/utils/WidgetUtils.ts +++ b/src/utils/WidgetUtils.ts @@ -1,8 +1,8 @@ import * as UI from 'types/ui'; import { getModuleT, toI18nKey } from './TranslationUtils'; +import { getRandomInt } from './ValueUtils'; -export const createWidgetId = (typeId: string) => - `${typeId}_${Math.floor(Math.random() * 100000000 + 1)}`; +export const createWidgetId = (typeId: string) => `${typeId}_${getRandomInt(1, 1000000)}`; // Key for widget settings in local storage (should not be accessed directly by the widget) export const widgetIdToSettingKey = (id: string) => `widget_${id}`;