Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Convert LimitPopover to TypeScript (#69076)

Frasere385103a21ec
diff --git a/frontend/src/metabase/query_builder/components/LimitPopover.jsx b/frontend/src/metabase/query_builder/components/LimitPopover.tsx
similarity index 65%
rename from frontend/src/metabase/query_builder/components/LimitPopover.jsx
rename to frontend/src/metabase/query_builder/components/LimitPopover.tsx
index 24f898d63b0..f381f145ba2 100644
--- a/frontend/src/metabase/query_builder/components/LimitPopover.jsx
+++ b/frontend/src/metabase/query_builder/components/LimitPopover.tsx
@@ -1,5 +1,5 @@
-/* eslint-disable react/prop-types */
import cx from "classnames";
+import type { KeyboardEvent } from "react";
import { t } from "ttag";
import { Radio } from "metabase/common/components/Radio";
@@ -8,34 +8,54 @@ import { formatNumber } from "metabase/lib/formatting";
import { LimitInput } from "metabase/query_builder/components/LimitInput";
import { HARD_ROW_LIMIT } from "metabase-lib/v1/queries/utils";
-const CustomRowLimit = ({ limit, onChangeLimit, onClose }) => {
+interface CustomRowLimitProps {
+ limit: number | null;
+ onChangeLimit: (limit: number | null) => void;
+ onClose: () => void;
+}
+
+const CustomRowLimit = ({
+ limit,
+ onChangeLimit,
+ onClose,
+}: CustomRowLimitProps) => {
return (
<LimitInput
small
- defaultValue={limit}
+ defaultValue={limit ?? undefined}
className={cx({ [cx(CS.textBrand, CS.borderBrand)]: limit != null })}
placeholder={t`Pick a limit`}
- onKeyPress={(e) => {
+ onKeyPress={(e: KeyboardEvent<HTMLInputElement>) => {
if (e.nativeEvent.isComposing) {
return;
}
if (e.key === "Enter") {
- const value = parseInt(e.target.value, 10);
+ const value = parseInt(e.currentTarget.value, 10);
if (value > 0) {
onChangeLimit(value);
} else {
onChangeLimit(null);
}
- if (onClose) {
- onClose();
- }
+ onClose();
}
}}
/>
);
};
-export const LimitPopover = ({ limit, onChangeLimit, onClose, className }) => (
+interface LimitPopoverProps {
+ limit: number | null;
+ onChangeLimit: (limit: number | null) => void;
+ onClose: () => void;
+ className?: string;
+}
+
+export const LimitPopover = ({
+ limit,
+ onChangeLimit,
+ onClose,
+ className,
+}: LimitPopoverProps) => (
<div className={cx(className, CS.textBold, CS.textMedium)}>
<Radio
vertical
@@ -57,7 +77,7 @@ export const LimitPopover = ({ limit, onChangeLimit, onClose, className }) => (
value: "custom",
},
]}
- onChange={(value) =>
+ onChange={(value: string) =>
value === "maximum" ? onChangeLimit(null) : onChangeLimit(2000)
}
/>
diff --git a/frontend/src/metabase/query_builder/components/view/QuestionRowCount/QuestionRowCount.tsx b/frontend/src/metabase/query_builder/components/view/QuestionRowCount/QuestionRowCount.tsx
index aaf9f01976b..50f52f8baee 100644
--- a/frontend/src/metabase/query_builder/components/view/QuestionRowCount/QuestionRowCount.tsx
+++ b/frontend/src/metabase/query_builder/components/view/QuestionRowCount/QuestionRowCount.tsx
@@ -90,8 +90,8 @@ function QuestionRowCountInner({
: getRowCountMessage(result, formatNumber);
}, [question, result, isResultDirty, isNative, formatNumber]);
- const handleLimitChange = (limit: number) => {
- onChangeLimit(limit > 0 ? limit : null);
+ const handleLimitChange = (limit: number | null) => {
+ onChangeLimit(limit !== null && limit > 0 ? limit : null);
};
const canChangeLimit = !isNative && isEditable;