Skip to content

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

Refactor QuestionRowCount (#65837)

Fraser739b062e7c77
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 ddc51ca694c..2e49ea9821c 100644
--- a/frontend/src/metabase/query_builder/components/view/QuestionRowCount/QuestionRowCount.tsx
+++ b/frontend/src/metabase/query_builder/components/view/QuestionRowCount/QuestionRowCount.tsx
@@ -1,9 +1,9 @@
+import { useDisclosure } from "@mantine/hooks";
import cx from "classnames";
import { useMemo } from "react";
import { t } from "ttag";
import _ from "underscore";
-import PopoverWithTrigger from "metabase/common/components/PopoverWithTrigger";
import {
type NumberFormatter,
useNumberFormatter,
@@ -20,7 +20,7 @@ import {
getIsResultDirty,
getQuestion,
} from "metabase/query_builder/selectors";
-import { Box } from "metabase/ui";
+import { Box, Popover, UnstyledButton } from "metabase/ui";
import type { Limit } from "metabase-lib";
import * as Lib from "metabase-lib";
import type Question from "metabase-lib/v1/Question";
@@ -78,6 +78,7 @@ function QuestionRowCount({
className,
onChangeLimit,
}: QuestionRowCountProps) {
+ const [opened, { close, toggle }] = useDisclosure(false);
const { isEditable, isNative } = Lib.queryDisplayInfo(question.query());
const formatNumber = useNumberFormatter();
const message = useMemo(() => {
@@ -101,31 +102,42 @@ function QuestionRowCount({
return null;
}
+ if (!canChangeLimit) {
+ return (
+ <RowCountLabel
+ className={className}
+ data-testid="question-row-count"
+ highlighted={limit != null}
+ disabled={!canChangeLimit}
+ >
+ {message}
+ </RowCountLabel>
+ );
+ }
+
return (
- <PopoverWithTrigger
- triggerElement={
- <RowCountLabel
- className={className}
- data-testid="question-row-count"
- highlighted={limit != null}
- disabled={!canChangeLimit}
- >
- {message}
- </RowCountLabel>
- }
- id={POPOVER_ID}
- aria-role="dialog"
- disabled={!canChangeLimit}
- >
- {({ onClose }: { onClose: () => void }) => (
+ <Popover opened={opened} onClose={close} position="bottom-start">
+ <Popover.Target>
+ <UnstyledButton onClick={toggle} id={POPOVER_ID} aria-haspopup="dialog">
+ <RowCountLabel
+ className={className}
+ data-testid="question-row-count"
+ highlighted={limit != null}
+ disabled={false}
+ >
+ {message}
+ </RowCountLabel>
+ </UnstyledButton>
+ </Popover.Target>
+ <Popover.Dropdown>
<LimitPopover
className={CS.p2}
limit={limit}
onChangeLimit={handleLimitChange}
- onClose={onClose}
+ onClose={close}
/>
- )}
- </PopoverWithTrigger>
+ </Popover.Dropdown>
+ </Popover>
);
}
@@ -141,26 +153,21 @@ function RowCountLabel({
}) {
const label = t`Row count`;
const { highlighted, ...propsForChild } = props;
- return disabled ? (
+ return (
<Box
component="span"
- className={cx(QuestionRowCountS.RowCountStaticLabel, className)}
- {...propsForChild}
- aria-label={label}
- />
- ) : (
- <button
className={cx(
- QuestionRowCountS.RowCountButton,
+ disabled
+ ? QuestionRowCountS.RowCountStaticLabel
+ : QuestionRowCountS.RowCountButton,
{
- [QuestionRowCountS.isHighlighted]: highlighted,
+ [QuestionRowCountS.isHighlighted]: !disabled && highlighted,
},
className,
)}
{...propsForChild}
aria-label={label}
- aria-haspopup="dialog"
- aria-controls={POPOVER_ID}
+ aria-controls={disabled ? undefined : POPOVER_ID}
/>
);
}