Skip to content

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

Browse directly from RCLS settings to saved questions (#77614)

Rodrigo López Dato89abda4d66b0
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.module.css b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.module.css
new file mode 100644
index 00000000000..c0c010922d5
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.module.css
@@ -0,0 +1,22 @@
+.policyCardButton:active {
+ transform: none;
+}
+
+.policyCardButtonInner {
+ justify-content: space-between;
+}
+
+.policyCardLabel {
+ padding-right: 2rem;
+}
+
+.optionsButton {
+ position: absolute;
+ right: 0.75rem;
+ top: 50%;
+ transform: translateY(-50%);
+}
+
+.optionsButton:active {
+ transform: translateY(-50%);
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx
index 06a2f594b76..24595ce9d9f 100644
--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.tsx
@@ -21,7 +21,18 @@ import { QuestionName } from "metabase/common/components/QuestionName";
import { useToggle } from "metabase/common/hooks/use-toggle";
import { useTranslateContent } from "metabase/content-translation/hooks";
import CS from "metabase/css/core/index.css";
-import { Button, Center, Icon, Loader, Radio, Stack } from "metabase/ui";
+import {
+ ActionIcon,
+ Box,
+ Button,
+ Center,
+ Icon,
+ Loader,
+ Menu,
+ Radio,
+ Stack,
+} from "metabase/ui";
+import * as Urls from "metabase/urls";
import { getName } from "metabase/utils/name";
import type {
GroupTableAccessPolicyDraft,
@@ -42,6 +53,8 @@ import {
DataAttributeMappingEditor,
} from "../AttributeMappingEditor";
+import S from "./EditSandboxingModal.module.css";
+
// eslint-disable-next-line ttag/no-module-declaration -- see metabase#55045
const ERROR_MESSAGE = t`An error occurred.`;
@@ -204,20 +217,50 @@ const EditSandboxingModal = ({
<div className={CS.pb2}>
{t`Pick a saved question that returns the custom view of this table that these users should see.`}
</div>
- <Button
- data-testid="custom-view-picker-button"
- onClick={showModal}
- fullWidth
- rightSection={<Icon name="ellipsis" />}
- styles={{
- inner: {
- justifyContent: "space-between",
- },
- root: { "&:active": { transform: "none" } },
- }}
- >
- {policyCard?.name ?? t`Select a question`}
- </Button>
+ <Box pos="relative">
+ <Button
+ data-testid="custom-view-picker-button"
+ onClick={showModal}
+ fullWidth
+ rightSection={policyCard ? undefined : <Icon name="ellipsis" />}
+ classNames={{
+ root: S.policyCardButton,
+ inner: S.policyCardButtonInner,
+ label: policyCard ? S.policyCardLabel : undefined,
+ }}
+ >
+ {policyCard?.name ?? t`Select a question`}
+ </Button>
+ {policyCard && (
+ <Menu position="bottom-end">
+ <Menu.Target>
+ <ActionIcon
+ aria-label={t`Question options`}
+ className={S.optionsButton}
+ >
+ <Icon name="ellipsis" />
+ </ActionIcon>
+ </Menu.Target>
+ <Menu.Dropdown>
+ <Menu.Item
+ component="a"
+ href={Urls.card(policyCard)}
+ target="_blank"
+ rel="noreferrer"
+ leftSection={<Icon name="external" />}
+ >
+ {t`Go to question`}
+ </Menu.Item>
+ <Menu.Item
+ onClick={showModal}
+ leftSection={<Icon name="refresh" />}
+ >
+ {t`Replace`}
+ </Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ )}
+ </Box>
{showPickerModal && (
<QuestionPickerModal
value={
diff --git a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.unit.spec.tsx
index 92c7bff3fc8..bea20155513 100644
--- a/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/sandboxes/components/EditSandboxingModal/EditSandboxingModal.unit.spec.tsx
@@ -318,5 +318,55 @@ describe("EditSandboxingModal", () => {
table_id: 1,
});
});
+
+ describe("selected question menu", () => {
+ const policyWithCard: GroupTableAccessPolicy = {
+ id: 1,
+ table_id: 1,
+ group_id: 1,
+ card_id: TEST_CARD.id,
+ permission_id: 50,
+ attribute_remappings: {
+ foo: ["dimension", ["field", 13, null]],
+ },
+ };
+
+ it("should allow opening the selected question in a new tab", async () => {
+ await setup({ shouldMockQuestions: true, policy: policyWithCard });
+
+ await userEvent.click(screen.getByLabelText("Question options"));
+
+ const link = await screen.findByRole("menuitem", {
+ name: /Go to question/,
+ });
+ expect(link).toHaveAttribute("href", "/question/1-sandbox-question");
+ expect(link).toHaveAttribute("target", "_blank");
+ });
+
+ it("should allow choosing a different question from the menu", async () => {
+ await setup({ shouldMockQuestions: true, policy: policyWithCard });
+
+ await userEvent.click(screen.getByLabelText("Question options"));
+ await userEvent.click(
+ await screen.findByRole("menuitem", {
+ name: /Replace/,
+ }),
+ );
+
+ expect(
+ await screen.findByTestId("entity-picker-modal"),
+ ).toBeInTheDocument();
+ });
+
+ it("should open the question picker when clicking the button outside the menu trigger", async () => {
+ await setup({ shouldMockQuestions: true, policy: policyWithCard });
+
+ await userEvent.click(screen.getByTestId("custom-view-picker-button"));
+
+ expect(
+ await screen.findByTestId("entity-picker-modal"),
+ ).toBeInTheDocument();
+ });
+ });
});
});