Skip to content

Commit

Permalink
Don't display an empty checkbox in confirm dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
maksis committed Dec 28, 2024
1 parent f0d054d commit 5b26135
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/components/semantic/CheckboxDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ const CheckboxDialog: React.FC<CheckboxDialogProps> = ({

return (
<ConfirmDialog onApproved={onApprove} {...other}>
<Checkbox
checked={false}
onChange={(state) => (checked.current = state)}
caption={checkboxCaption}
/>
{checkboxCaption && (
<Checkbox
checked={false}
onChange={(state) => (checked.current = state)}
caption={checkboxCaption}
/>
)}
</ConfirmDialog>
);
};
Expand Down
6 changes: 6 additions & 0 deletions src/utils/DebugUtils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getRandomInt } from './ValueUtils';

const REPORT_RERENDER = true;

export const MemoReporter = REPORT_RERENDER
Expand All @@ -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);
};
5 changes: 5 additions & 0 deletions src/utils/ValueUtils.ts
Original file line number Diff line number Diff line change
@@ -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
};
4 changes: 2 additions & 2 deletions src/utils/WidgetUtils.ts
Original file line number Diff line number Diff line change
@@ -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}`;
Expand Down

0 comments on commit 5b26135

Please sign in to comment.