Skip to content

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

Make readOnly Notebook non-editable (#62388)

Romeo Van Snick43d2b9ac84fd
diff --git a/e2e/test/scenarios/admin/transforms.cy.spec.ts b/e2e/test/scenarios/admin/transforms.cy.spec.ts
index a0ddca12c58..96fca04cf6a 100644
--- a/e2e/test/scenarios/admin/transforms.cy.spec.ts
+++ b/e2e/test/scenarios/admin/transforms.cy.spec.ts
@@ -641,6 +641,154 @@ H.describeWithSnowplowEE("scenarios > admin > transforms", () => {
});
describe("queries", () => {
+ it("should render a readOnly preview of the MBQL query", () => {
+ cy.log("create a new transform that has all the steps");
+ createMbqlTransform({ visitTransform: true });
+ H.getTableId({ name: "Animals" }).then((tableId) => {
+ H.getFieldId({ tableId, name: "score" }).then((ANIMAL_SCORE) => {
+ H.getFieldId({ tableId, name: "name" }).then((ANIMAL_NAME) => {
+ H.createTransform(
+ {
+ name: "MBQL transform",
+ source: {
+ type: "query",
+ query: {
+ database: WRITABLE_DB_ID,
+ type: "query",
+ query: {
+ "source-table": tableId,
+ filter: [">", ["field", ANIMAL_SCORE, {}], 10],
+ aggregation: [
+ ["count"],
+ [
+ "aggregation-options",
+ ["+", ["count"], 1],
+ { name: "Foobar", "display-name": "Foobar" },
+ ],
+ ],
+ expressions: {
+ ScorePlusOne: ["+", ["field", ANIMAL_SCORE, {}], 1],
+ },
+ breakout: [
+ [
+ "field",
+ ANIMAL_SCORE,
+ { binning: { strategy: "num-bins", "num-bins": 10 } },
+ ],
+ ],
+ joins: [
+ {
+ "source-table": tableId,
+ condition: [
+ "=",
+ ["field", ANIMAL_SCORE, {}],
+ ["field", ANIMAL_SCORE, {}],
+ ],
+ alias: "animal_score",
+ },
+ ],
+ limit: 10,
+ "order-by": [["asc", ["field", ANIMAL_NAME, {}]]],
+ },
+ },
+ },
+ target: {
+ type: "table",
+ name: TARGET_TABLE,
+ schema: TARGET_SCHEMA,
+ },
+ tag_ids: [],
+ },
+ { visitTransform: true },
+ );
+ });
+ });
+ });
+
+ cy.log("Data step should be read-only");
+ H.getNotebookStep("data")
+ .findByRole("button")
+ .should("contain", "Animals")
+ .should("be.disabled");
+
+ cy.log("Join step should be read-only");
+ H.getNotebookStep("join")
+ .findAllByText("Animals")
+ .should("have.length", 4)
+ .eq(1)
+ .should("have.css", "pointer-events", "none");
+
+ cy.findByLabelText("Change join type").should("be.disabled");
+
+ H.getNotebookStep("join")
+ .findAllByText("Score")
+ .should("have.length", 2)
+ .first()
+ .click();
+ assertNoModals();
+
+ H.getNotebookStep("join")
+ .findAllByText("Score")
+ .should("have.length", 2)
+ .eq(1)
+ .click();
+ assertNoModals();
+
+ cy.log("Expression step should be read-only, but render editor");
+ H.getNotebookStep("expression").findByText("ScorePlusOne").click();
+ H.CustomExpressionEditor.value().should("equal", "[Score] + 1");
+ H.CustomExpressionEditor.nameInput()
+ .should("have.value", "ScorePlusOne")
+ .should("have.attr", "readonly");
+ H.popover().button("Done").click();
+
+ cy.log("Expression step should be read-only, but render popover");
+ H.getNotebookStep("filter")
+ .findByText("Score is greater than 10")
+ .click();
+ H.popover().within(() => {
+ cy.findByText("Score").should("be.visible");
+ cy.findByText("Greater than").should("be.visible");
+ cy.findByPlaceholderText("Enter a number")
+ .should("be.visible")
+ .should("have.value", 10);
+ });
+ H.main().click();
+
+ cy.log("Summarize step should be read-only");
+ H.getNotebookStep("summarize").findByText("Count").click();
+ H.CustomExpressionEditor.value().should("equal", "Count()");
+ H.CustomExpressionEditor.nameInput()
+ .should("have.value", "Count")
+ .should("have.attr", "readonly");
+ H.popover().button("Done").click();
+
+ H.getNotebookStep("summarize").findByText("Foobar").click();
+ H.CustomExpressionEditor.value().should("equal", "Count() + 1");
+ H.CustomExpressionEditor.nameInput()
+ .should("have.value", "Foobar")
+ .should("have.attr", "readonly");
+ H.popover().button("Done").click();
+
+ H.getNotebookStep("summarize").findByText("Score: 10 bins").click();
+ assertNoModals();
+
+ cy.log("Sort step should be read-only");
+ H.getNotebookStep("sort").findByText("Name").click();
+ assertNoModals();
+
+ cy.log("Limit step should be read-only");
+ H.getNotebookStep("limit")
+ .findByPlaceholderText("Enter a limit")
+ .should("have.value", 10)
+ .should("have.attr", "readonly");
+
+ function assertNoModals() {
+ H.entityPickerModal().should("not.exist");
+ H.popover({ skipVisibilityCheck: true }).should("not.exist");
+ }
+ });
+
it("should be able to update a MBQL query", () => {
cy.log("create a new transform");
createMbqlTransform({ visitTransform: true });
diff --git a/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.tsx b/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.tsx
index 8efec5b0972..17d3d21101e 100644
--- a/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.tsx
+++ b/frontend/src/metabase/common/components/AggregationPicker/AggregationPicker.tsx
@@ -46,6 +46,7 @@ export interface AggregationPickerProps {
onClose?: () => void;
onQueryChange: (query: Lib.Query) => void;
onBack?: () => void;
+ readOnly?: boolean;
}
type OperatorListItem = Lib.AggregationOperatorDisplayInfo & {
@@ -81,6 +82,7 @@ export function AggregationPicker({
onClose,
onQueryChange,
onBack,
+ readOnly,
}: AggregationPickerProps) {
const metadata = useSelector(getMetadata);
const displayInfo = clause
@@ -93,7 +95,13 @@ export function AggregationPicker({
isEditingExpression,
{ turnOn: openExpressionEditor, turnOff: closeExpressionEditor },
] = useToggle(
- isExpressionEditorInitiallyOpen(query, stageIndex, clause, operators),
+ isExpressionEditorInitiallyOpen({
+ query,
+ stageIndex,
+ clause,
+ operators,
+ readOnly,
+ }),
);
const [initialExpressionClause, setInitialExpressionClause] =
useState<DefinedClauseName | null>(null);
@@ -309,10 +317,15 @@ export function AggregationPicker({
withName
expressionMode="aggregation"
expressionIndex={clauseIndex}
- header={<ExpressionWidgetHeader onBack={closeExpressionEditor} />}
+ header={
+ <ExpressionWidgetHeader
+ onBack={readOnly ? undefined : closeExpressionEditor}
+ />
+ }
onChangeClause={handleClauseChange}
onClose={closeExpressionEditor}
initialExpressionClause={initialExpressionClause}
+ readOnly={readOnly}
/>
);
}
@@ -436,12 +449,23 @@ function getInitialOperator(
return operator ?? null;
}
-function isExpressionEditorInitiallyOpen(
- query: Lib.Query,
- stageIndex: number,
- clause: Lib.AggregationClause | undefined,
- operators: Lib.AggregationOperator[],
-): boolean {
+function isExpressionEditorInitiallyOpen({
+ query,
+ stageIndex,
+ clause,
+ operators,
+ readOnly,
+}: {
+ query: Lib.Query;
+ stageIndex: number;
+ clause: Lib.AggregationClause | undefined;
+ operators: Lib.AggregationOperator[];
+ readOnly?: boolean;
+}): boolean {
+ if (readOnly) {
+ return true;
+ }
+
if (!clause) {
return false;
}
diff --git a/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidget.tsx b/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidget.tsx
index 39b9e01d5c1..fbde932c332 100644
--- a/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidget.tsx
+++ b/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidget.tsx
@@ -36,6 +36,7 @@ export type ExpressionWidgetProps = {
header?: ReactNode;
initialExpressionClause?: DefinedClauseName | null;
availableColumns: Lib.ColumnMetadata[];
+ readOnly?: boolean;
onChangeClause?: (name: string, clause: Lib.ExpressionClause) => void;
onClose?: () => void;
@@ -56,6 +57,7 @@ export const ExpressionWidget = (props: ExpressionWidgetProps) => {
onChangeClause,
onClose,
initialExpressionClause,
+ readOnly,
} = props;
const [name, setName] = useState(initialName || "");
@@ -202,6 +204,7 @@ export const ExpressionWidget = (props: ExpressionWidgetProps) => {
hasHeader={Boolean(header)}
onCloseEditor={onClose}
initialExpressionClause={initialExpressionClause}
+ readOnly={readOnly}
/>
<LayoutFooter>
@@ -212,10 +215,11 @@ export const ExpressionWidget = (props: ExpressionWidgetProps) => {
onChange={setName}
onSubmit={handleSubmit}
expressionMode={expressionMode}
+ readOnly={readOnly}
/>
)}
<Flex py="sm" pr="sm" gap="sm">
- {onClose && (
+ {onClose && !readOnly && (
<Button
onClick={onClose}
variant="subtle"
@@ -228,7 +232,9 @@ export const ExpressionWidget = (props: ExpressionWidgetProps) => {
onClick={handleSubmit}
size="xs"
>
- {initialName || initialClause ? t`Update` : t`Done`}
+ {(initialName || initialClause) && !readOnly
+ ? t`Update`
+ : t`Done`}
</Button>
</Flex>
</Flex>
diff --git a/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.module.css b/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.module.css
index e50f8b9f3b7..616a8163848 100644
--- a/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.module.css
+++ b/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.module.css
@@ -9,8 +9,13 @@
.HeaderButton {
color: var(--mb-color-text-light);
- &:hover {
+ &:not(:disabled):hover {
color: var(--mb-color-brand);
}
+
+ &:disabled {
+ opacity: 1;
+ cursor: default;
+ }
}
}
diff --git a/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.tsx b/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.tsx
index c67ba77b265..2141e97abb5 100644
--- a/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.tsx
+++ b/frontend/src/metabase/query_builder/components/expressions/ExpressionWidget/ExpressionWidgetHeader.tsx
@@ -11,7 +11,7 @@ const DEFAULT_SECTION_NAME = t`Custom Expression`;
interface Props {
title?: string;
- onBack: () => void;
+ onBack?: () => void;
}
export const ExpressionWidgetHeader = ({
@@ -22,9 +22,10 @@ export const ExpressionWidgetHeader = ({
<Flex className={ExpressionWidgetHeaderS.Header}>
<Button
className={ExpressionWidgetHeaderS.HeaderButton}
- icon="chevronleft"
+ icon={onBack ? "chevronleft" : undefined}
onlyText
onClick={onBack}
+ disabled={!onBack}
>
{title}
</Button>
diff --git a/frontend/src/metabase/query_builder/components/expressions/NameInput/NameInput.tsx b/frontend/src/metabase/query_builder/components/expressions/NameInput/NameInput.tsx
index 4efd826d93a..d52e214c0f8 100644
--- a/frontend/src/metabase/query_builder/components/expressions/NameInput/NameInput.tsx
+++ b/frontend/src/metabase/query_builder/components/expressions/NameInput/NameInput.tsx
@@ -11,11 +11,13 @@ export function NameInput({
onChange,
onSubmit,
expressionMode,
+ readOnly,
}: {
value: string;
onChange: (value: string) => void;
onSubmit: () => void;
expressionMode: Lib.ExpressionMode;
+ readOnly?: boolean;
}) {
const handleChange = useCallback(
(evt: ChangeEvent<HTMLInputElement>) => {
@@ -45,6 +47,7 @@ export function NameInput({
placeholder={getPlaceholder(expressionMode)}
onChange={handleChange}
onKeyDown={handleKeyDown}
+ readOnly={readOnly}
classNames={{
root: S.root,
input: S.input,
diff --git a/frontend/src/metabase/querying/filters/components/DatePicker/DatePicker.tsx b/frontend/src/metabase/querying/filters/components/DatePicker/DatePicker.tsx
index f8b9f8f70b6..2f08f6c40fd 100644
--- a/frontend/src/metabase/querying/filters/components/DatePicker/DatePicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/DatePicker/DatePicker.tsx
@@ -27,6 +27,7 @@ type DatePickerProps = {
renderSubmitButton?: (props: DatePickerSubmitButtonProps) => ReactNode;
renderBackButton?: () => ReactNode;
onChange: (value: DatePickerValue) => void;
+ readOnly?: boolean;
};
export function DatePicker({
@@ -37,6 +38,7 @@ export function DatePicker({
renderSubmitButton = renderDefaultSubmitButton,
renderBackButton,
onChange,
+ readOnly,
}: DatePickerProps) {
const [type, setType] = useState(value?.type);
@@ -54,6 +56,7 @@ export function DatePicker({
renderSubmitButton={renderSubmitButton}
onChange={onChange}
onBack={handleBack}
+ readOnly={readOnly}
/>
);
case "relative":
@@ -64,6 +67,7 @@ export function DatePicker({
renderSubmitButton={renderSubmitButton}
onChange={onChange}
onBack={handleBack}
+ readOnly={readOnly}
/>
);
case "exclude":
@@ -75,6 +79,7 @@ export function DatePicker({
renderSubmitButton={renderSubmitButton}
onChange={onChange}
onBack={handleBack}
+ readOnly={readOnly}
/>
);
default:
diff --git a/frontend/src/metabase/querying/filters/components/DatePicker/ExcludeDatePicker/ExcludeDatePicker.tsx b/frontend/src/metabase/querying/filters/components/DatePicker/ExcludeDatePicker/ExcludeDatePicker.tsx
index d7ab8307cbd..4cc991568ba 100644
--- a/frontend/src/metabase/querying/filters/components/DatePicker/ExcludeDatePicker/ExcludeDatePicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/DatePicker/ExcludeDatePicker/ExcludeDatePicker.tsx
@@ -41,6 +41,7 @@ export interface ExcludeDatePickerProps {
renderSubmitButton?: (props: DatePickerSubmitButtonProps) => ReactNode;
onChange: (value: ExcludeDatePickerValue) => void;
onBack: () => void;
+ readOnly?: boolean;
}
export function ExcludeDatePicker({
@@ -50,6 +51,7 @@ export function ExcludeDatePicker({
renderSubmitButton = renderDefaultSubmitButton,
onChange,
onBack,
+ readOnly,
}: ExcludeDatePickerProps) {
const [unit, setUnit] = useState(value?.unit);
const [values, setValues] = useState(value?.values ?? []);
@@ -70,6 +72,7 @@ export function ExcludeDatePicker({
renderSubmitButton={renderSubmitButton}
onChange={onChange}
onBack={handleBack}
+ readOnly={readOnly}
/>
) : (
<ExcludeOptionPicker
@@ -90,6 +93,7 @@ interface ExcludeOptionPickerProps {
onChange: (value: ExcludeDatePickerValue) => void;
onSelectUnit: (unit: DatePickerExtractionUnit) => void;
onBack: () => void;
+ readOnly?: boolean;
}
export function ExcludeOptionPicker({
@@ -99,6 +103,7 @@ export function ExcludeOptionPicker({
onChange,
onSelectUnit,
onBack,
+ readOnly,
}: ExcludeOptionPickerProps) {
const unitOptions = useMemo(() => {
return getExcludeUnitOptions(availableOperators, availableUnits);
@@ -114,7 +119,11 @@ export function ExcludeOptionPicker({
return (
<Box miw={MIN_WIDTH}>
- <BackButton onClick={onBack}>{t`Exclude…`}</BackButton>
+ <BackButton
+ onClick={onBack}
+ disabled={readOnly}
+ withArrow={!readOnly}
+ >{t`Exclude…`}</BackButton>
<Divider />
<Box p="sm">
{unitOptions.map((option, index) => (
@@ -157,6 +166,7 @@ interface ExcludeValuePickerProps {
renderSubmitButton: (props: DatePickerSubmitButtonProps) => ReactNode;
onChange: (value: ExcludeDatePickerValue) => void;
onBack: () => void;
+ readOnly?: boolean;
}
function ExcludeValuePicker({
@@ -165,6 +175,7 @@ function ExcludeValuePicker({
renderSubmitButton,
onChange,
onBack,
+ readOnly,
}: ExcludeValuePickerProps) {
const [values, setValues] = useState(initialValues);
const option = useMemo(() => findExcludeUnitOption(unit), [unit]);
@@ -201,7 +212,7 @@ function ExcludeValuePicker({
return (
<Box component="form" miw={MIN_WIDTH} onSubmit={handleSubmit}>
- <BackButton onClick={onBack}>{option?.label}</BackButton>
+ {!readOnly && <BackButton onClick={onBack}>{option?.label}</BackButton>}
<Divider />
<Stack p="md">
<Checkbox
diff --git a/frontend/src/metabase/querying/filters/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx b/frontend/src/metabase/querying/filters/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx
index 781270c87c2..0886316a57c 100644
--- a/frontend/src/metabase/querying/filters/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/DatePicker/RelativeDatePicker/RelativeDatePicker.tsx
@@ -27,6 +27,7 @@ interface RelativeDatePickerProps {
renderSubmitButton?: (props: DatePickerSubmitButtonProps) => ReactNode;
onChange: (value: RelativeDatePickerValue) => void;
onBack: () => void;
+ readOnly?: boolean;
}
export function RelativeDatePicker({
@@ -35,6 +36,7 @@ export function RelativeDatePicker({
renderSubmitButton = renderDefaultSubmitButton,
onChange,
onBack,
+ readOnly,
}: RelativeDatePickerProps) {
const [value, setValue] = useState<RelativeDatePickerValue | undefined>(
initialValue ?? DEFAULT_VALUE,
@@ -57,7 +59,12 @@ export function RelativeDatePicker({
return (
<Tabs value={direction} onChange={handleTabChange}>
<Flex>
- <PopoverBackButton p="sm" onClick={onBack} />
+ <PopoverBackButton
+ p="sm"
+ onClick={onBack}
+ disabled={readOnly}
+ withArrow={!readOnly}
+ />
<Tabs.List className={S.TabList}>
{TABS.map((tab) => (
<Tabs.Tab key={tab.direction} value={tab.direction}>
diff --git a/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx b/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx
index 8952d8941be..4471b7ad851 100644
--- a/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/DatePicker/SpecificDatePicker/SpecificDatePicker.tsx
@@ -35,6 +35,7 @@ interface SpecificDatePickerProps {
renderSubmitButton?: (props: DatePickerSubmitButtonProps) => ReactNode;
onChange: (value: SpecificDatePickerValue) => void;
onBack: () => void;
+ readOnly?: boolean;
}
export function SpecificDatePicker({
@@ -44,6 +45,7 @@ export function SpecificDatePicker({
renderSubmitButton = renderDefaultSubmitButton,
onChange,
onBack,
+ readOnly,
}: SpecificDatePickerProps) {
const tabs = useMemo(() => getTabs(availableOperators), [availableOperators]);
const [value, setValue] = useState(() => initialValue ?? getDefaultValue());
@@ -75,7 +77,12 @@ export function SpecificDatePicker({
return (
<Tabs value={value.operator} onChange={handleTabChange}>
<Flex>
- <PopoverBackButton p="sm" onClick={onBack} />
+ <PopoverBackButton
+ p="sm"
+ onClick={onBack}
+ disabled={readOnly}
+ withArrow={!readOnly}
+ />
<Tabs.List className={S.TabList}>
{tabs.map((tab) => (
<Tabs.Tab key={tab.operator} value={tab.operator}>
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/BooleanFilterPicker/BooleanFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/BooleanFilterPicker/BooleanFilterPicker.tsx
index 476c2d42a95..9214fcd7bc6 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/BooleanFilterPicker/BooleanFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/BooleanFilterPicker/BooleanFilterPicker.tsx
@@ -17,6 +17,7 @@ export function BooleanFilterPicker({
column,
filter,
isNew,
+ readOnly,
withAddButton,
withSubmitButton,
onBack,
@@ -58,6 +59,7 @@ export function BooleanFilterPicker({
<FilterPickerHeader
columnName={columnInfo.longDisplayName}
onBack={onBack}
+ readOnly={readOnly}
/>
)}
<BooleanPicker value={value} withEmptyOptions onChange={setValue} />
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/CoordinateFilterPicker/CoordinateFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/CoordinateFilterPicker/CoordinateFilterPicker.tsx
index 49f4e0b308c..c4a80663659 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/CoordinateFilterPicker/CoordinateFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/CoordinateFilterPicker/CoordinateFilterPicker.tsx
@@ -31,6 +31,7 @@ export function CoordinateFilterPicker({
withSubmitButton,
onChange,
onBack,
+ readOnly,
}: FilterPickerWidgetProps) {
const columnInfo = useMemo(
() => Lib.displayInfo(query, stageIndex, column),
@@ -90,6 +91,7 @@ export function CoordinateFilterPicker({
<FilterPickerHeader
columnName={columnInfo.longDisplayName}
onBack={onBack}
+ readOnly={readOnly}
>
<FilterOperatorPicker
value={operator}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx
index d412efe61c5..6810b7b8595 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/DateFilterPicker/DateFilterPicker.tsx
@@ -19,6 +19,7 @@ export function DateFilterPicker({
withSubmitButton,
onChange,
onBack,
+ readOnly,
}: FilterPickerWidgetProps) {
const columnInfo = useMemo(() => {
return Lib.displayInfo(query, stageIndex, column);
@@ -62,12 +63,18 @@ export function DateFilterPicker({
}}
renderBackButton={() =>
onBack ? (
- <PopoverBackButton p="sm" onClick={onBack}>
+ <PopoverBackButton
+ p="sm"
+ onClick={onBack}
+ disabled={readOnly}
+ withArrow={!readOnly}
+ >
{columnInfo.longDisplayName}
</PopoverBackButton>
) : null
}
onChange={handleChange}
+ readOnly={readOnly}
/>
</div>
);
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
index d84fd0f2e7c..7f21cddde17 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/DefaultFilterPicker/DefaultFilterPicker.tsx
@@ -20,6 +20,7 @@ export function DefaultFilterPicker({
withSubmitButton,
onBack,
onChange,
+ readOnly,
}: FilterPickerWidgetProps) {
const columnInfo = useMemo(
() => Lib.displayInfo(query, stageIndex, column),
@@ -70,6 +71,7 @@ export function DefaultFilterPicker({
<FilterPickerHeader
columnName={columnInfo.longDisplayName}
onBack={onBack}
+ readOnly={readOnly}
/>
<div>
<Radio.Group value={operator} onChange={handleOperatorChange}>
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPicker.tsx
index dfe5fd3d947..ba3d7c8dd56 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPicker.tsx
@@ -29,6 +29,7 @@ export type FilterPickerProps = {
onSelect: (filter: Lib.Filterable) => void;
onClose?: () => void;
onBack?: () => void;
+ readOnly?: boolean;
} & Pick<
FilterColumnPickerProps,
"withColumnItemIcon" | "withColumnGroupIcon" | "withCustomExpression"
@@ -46,6 +47,7 @@ export function FilterPicker({
withColumnItemIcon,
withColumnGroupIcon,
withCustomExpression,
+ readOnly,
}: FilterPickerProps) {
const [filter, setFilter] = useState(initialFilter);
const [column, setColumn] = useState(
@@ -155,6 +157,7 @@ export function FilterPicker({
isNew={isNewFilter}
onChange={handleChange}
onBack={handleBack}
+ readOnly={readOnly}
/>
);
}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.module.css b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.module.css
new file mode 100644
index 00000000000..c5e0b9a276c
--- /dev/null
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.module.css
@@ -0,0 +1,3 @@
+.readOnly {
+ pointer-events: none;
+}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.tsx
index a407485fc98..ec79dd9a76a 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerBody/FilterPickerBody.tsx
@@ -1,3 +1,6 @@
+import cx from "classnames";
+
+import { Box } from "metabase/ui";
import * as Lib from "metabase-lib";
import { BooleanFilterPicker } from "../BooleanFilterPicker";
@@ -9,6 +12,8 @@ import { StringFilterPicker } from "../StringFilterPicker";
import { TimeFilterPicker } from "../TimeFilterPicker";
import type { FilterChangeOpts } from "../types";
+import S from "./FilterPickerBody.module.css";
+
interface FilterPickerBodyProps {
autoFocus?: boolean;
query: Lib.Query;
@@ -20,6 +25,7 @@ interface FilterPickerBodyProps {
withSubmitButton?: boolean;
onChange: (filter: Lib.ExpressionClause, opts: FilterChangeOpts) => void;
onBack?: () => void;
+ readOnly?: boolean;
}
export function FilterPickerBody({
@@ -33,6 +39,7 @@ export function FilterPickerBody({
withSubmitButton = true,
onChange,
onBack,
+ readOnly,
}: FilterPickerBodyProps) {
const FilterWidget = getFilterWidget(column);
if (!FilterWidget) {
@@ -40,18 +47,21 @@ export function FilterPickerBody({
}
return (
- <FilterWidget
- autoFocus={autoFocus}
- query={query}
- stageIndex={stageIndex}
- column={column}
- filter={filter}
- isNew={isNew}
- withAddButton={withAddButton}
- withSubmitButton={withSubmitButton}
- onChange={onChange}
- onBack={onBack}
- />
+ <Box className={cx({ [S.readOnly]: readOnly })}>
+ <FilterWidget
+ autoFocus={autoFocus}
+ query={query}
+ stageIndex={stageIndex}
+ column={column}
+ filter={filter}
+ isNew={isNew}
+ withAddButton={withAddButton}
+ withSubmitButton={withSubmitButton && !readOnly}
+ onChange={onChange}
+ onBack={onBack}
+ readOnly={readOnly}
+ />
+ </Box>
);
}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx
index c2b9cb926ea..e3cd947e30e 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/FilterPickerHeader/FilterPickerHeader.tsx
@@ -5,18 +5,25 @@ import { Flex, PopoverBackButton } from "metabase/ui";
interface FilterPickerHeaderProps {
columnName: string;
children?: ReactNode;
+ readOnly?: boolean;
onBack?: () => void;
}
export function FilterPickerHeader({
columnName,
children,
+ readOnly,
onBack,
}: FilterPickerHeaderProps) {
return (
<Flex px="md" pt="md" justify="space-between">
{onBack && (
- <PopoverBackButton pr="md" onClick={onBack}>
+ <PopoverBackButton
+ pr="md"
+ onClick={onBack}
+ disabled={readOnly}
+ withArrow={!readOnly}
+ >
{columnName}
</PopoverBackButton>
)}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.tsx
index ae59dffaac3..0c6e20b9c9a 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/NumberFilterPicker/NumberFilterPicker.tsx
@@ -29,6 +29,7 @@ export function NumberFilterPicker({
withSubmitButton,
onChange,
onBack,
+ readOnly,
}: FilterPickerWidgetProps) {
const columnInfo = useMemo(
() => Lib.displayInfo(query, stageIndex, column),
@@ -84,6 +85,7 @@ export function NumberFilterPicker({
<FilterPickerHeader
columnName={columnInfo.longDisplayName}
onBack={onBack}
+ readOnly={readOnly}
>
<FilterOperatorPicker
value={operator}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.tsx
index 390ad01096c..bea8c42fe45 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/StringFilterPicker/StringFilterPicker.tsx
@@ -27,6 +27,7 @@ export function StringFilterPicker({
withSubmitButton,
onChange,
onBack,
+ readOnly,
}: FilterPickerWidgetProps) {
const columnInfo = useMemo(
() => Lib.displayInfo(query, stageIndex, column),
@@ -83,6 +84,7 @@ export function StringFilterPicker({
<FilterPickerHeader
columnName={columnInfo.longDisplayName}
onBack={onBack}
+ readOnly={readOnly}
>
<FilterOperatorPicker
value={operator}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/TimeFilterPicker/TimeFilterPicker.tsx b/frontend/src/metabase/querying/filters/components/FilterPicker/TimeFilterPicker/TimeFilterPicker.tsx
index 77644426581..a4f91ad8173 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/TimeFilterPicker/TimeFilterPicker.tsx
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/TimeFilterPicker/TimeFilterPicker.tsx
@@ -26,6 +26,7 @@ export function TimeFilterPicker({
withSubmitButton,
onChange,
onBack,
+ readOnly,
}: FilterPickerWidgetProps) {
const columnInfo = useMemo(
() => Lib.displayInfo(query, stageIndex, column),
@@ -79,6 +80,7 @@ export function TimeFilterPicker({
<FilterPickerHeader
columnName={columnInfo.longDisplayName}
onBack={onBack}
+ readOnly={readOnly}
>
<FilterOperatorPicker
value={operator}
diff --git a/frontend/src/metabase/querying/filters/components/FilterPicker/types.ts b/frontend/src/metabase/querying/filters/components/FilterPicker/types.ts
index 3231eb11020..8e62835a9fc 100644
--- a/frontend/src/metabase/querying/filters/components/FilterPicker/types.ts
+++ b/frontend/src/metabase/querying/filters/components/FilterPicker/types.ts
@@ -12,6 +12,7 @@ export type FilterPickerWidgetProps = {
withSubmitButton: boolean;
onChange: (filter: Lib.ExpressionClause, opts: FilterChangeOpts) => void;
onBack?: () => void;
+ readOnly?: boolean;
};
export type FilterChangeOpts = {
diff --git a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx
index 775cb62a29f..f808d63c95f 100644
--- a/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/AggregateStep/AggregateStep.tsx
@@ -64,6 +64,7 @@ export function AggregateStep({
clauseIndex={index}
onQueryChange={updateQuery}
onClose={onClose}
+ readOnly={readOnly}
/>
)}
onReorder={handleReorderAggregation}
@@ -80,6 +81,7 @@ interface AggregationPopoverProps {
clauseIndex?: number;
onQueryChange: (query: Lib.Query) => void;
onClose: () => void;
+ readOnly?: boolean;
}
function AggregationPopover({
@@ -89,6 +91,7 @@ function AggregationPopover({
clauseIndex,
onQueryChange,
onClose,
+ readOnly,
}: AggregationPopoverProps) {
const isUpdate = clause != null && clauseIndex != null;
@@ -109,6 +112,7 @@ function AggregationPopover({
allowCustomExpressions
onQueryChange={onQueryChange}
onClose={onClose}
+ readOnly={readOnly}
/>
);
}
diff --git a/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx b/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx
index 7376a708de6..a32349b3fcd 100644
--- a/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/BreakoutStep/BreakoutStep.tsx
@@ -80,18 +80,20 @@ export function BreakoutStep({
hasAddButton={hasAddButton}
isAddButtonDisabled={isAddButtonDisabled}
renderName={renderBreakoutName}
- renderPopover={({ item: breakout, index, onClose }) => (
- <BreakoutPopover
- query={query}
- stageIndex={stageIndex}
- breakout={breakout}
- breakoutIndex={index}
- isMetric={isMetric}
- onAddBreakout={handleAddBreakout}
- onUpdateBreakoutColumn={handleUpdateBreakoutColumn}
- onClose={onClose}
- />
- )}
+ renderPopover={({ item: breakout, index, onClose }) =>
+ readOnly ? null : (
+ <BreakoutPopover
+ query={query}
+ stageIndex={stageIndex}
+ breakout={breakout}
+ breakoutIndex={index}
+ isMetric={isMetric}
+ onAddBreakout={handleAddBreakout}
+ onUpdateBreakoutColumn={handleUpdateBreakoutColumn}
+ onClose={onClose}
+ />
+ )
+ }
onReorder={handleReorderBreakout}
onRemove={handleRemoveBreakout}
data-testid="breakout-step"
diff --git a/frontend/src/metabase/querying/notebook/components/ClauseStep/ClausePopover.tsx b/frontend/src/metabase/querying/notebook/components/ClauseStep/ClausePopover.tsx
index 5c9041bb23a..86502eab651 100644
--- a/frontend/src/metabase/querying/notebook/components/ClauseStep/ClausePopover.tsx
+++ b/frontend/src/metabase/querying/notebook/components/ClauseStep/ClausePopover.tsx
@@ -8,7 +8,7 @@ import S from "./ClausePopover.module.css";
interface ClausePopoverProps {
isInitiallyOpen?: boolean;
- renderItem: (open: () => void) => JSX.Element | string;
+ renderItem: (open: () => void, hasPopover?: boolean) => JSX.Element | string;
renderPopover: (close: () => void) => JSX.Element | null;
}
@@ -38,6 +38,9 @@ export function ClausePopover({
}
}, [active]);
+ const content = renderPopover(handleClose);
+ const hasPopover = content !== null;
+
return (
<PreventPopoverExitProvider>
<Popover
@@ -47,11 +50,12 @@ export function ClausePopover({
trapFocus
onChange={handleChange}
classNames={{ dropdown: S.dropdown }}
+ disabled={!hasPopover}
>
- <Popover.Target>{renderItem(handleOpen)}</Popover.Target>
+ <Popover.Target>{renderItem(handleOpen, hasPopover)}</Popover.Target>
<Popover.Dropdown data-testid="clause-popover">
<Box className={S.dropdownContent} data-testid="popover-content">
- {renderPopover(handleClose)}
+ {content}
</Box>
</Popover.Dropdown>
</Popover>
diff --git a/frontend/src/metabase/querying/notebook/components/ClauseStep/ClauseStep.tsx b/frontend/src/metabase/querying/notebook/components/ClauseStep/ClauseStep.tsx
index f40397b2d8d..ba8af5b4ddf 100644
--- a/frontend/src/metabase/querying/notebook/components/ClauseStep/ClauseStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/ClauseStep/ClauseStep.tsx
@@ -22,6 +22,7 @@ type RenderItemOpts<T> = {
item: T;
index: number;
onOpen?: () => void;
+ hasPopover?: boolean;
};
type RenderPopoverOpts<T> = {
@@ -61,9 +62,19 @@ export const ClauseStep = <T,>({
onReorder,
...props
}: ClauseStepProps<T>): JSX.Element => {
- const renderItem = ({ item, index, onOpen }: RenderItemOpts<T>) => (
+ const renderItem = ({
+ item,
+ index,
+ onOpen,
+ hasPopover,
+ }: RenderItemOpts<T>) => (
<ClauseStepDndItem index={index} readOnly={readOnly}>
- <NotebookCellItem color={color} readOnly={readOnly} onClick={onOpen}>
+ <NotebookCellItem
+ color={color}
+ readOnly={readOnly}
+ onClick={onOpen}
+ hasPopover={hasPopover}
+ >
{renderName(item, index)}
{hasRemoveButton && (
<Icon
@@ -94,7 +105,9 @@ export const ClauseStep = <T,>({
{items.map((item, index) => (
<ClausePopover
key={index}
- renderItem={(onOpen) => renderItem({ item, index, onOpen })}
+ renderItem={(onOpen, hasPopover) =>
+ renderItem({ item, index, onOpen, hasPopover })
+ }
renderPopover={(onClose) => renderPopover({ item, index, onClose })}
/>
))}
diff --git a/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx b/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx
index 15161a193e3..fc7d2bfa5e4 100644
--- a/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/DataStep/DataStep.tsx
@@ -67,6 +67,7 @@ export const DataStep = ({
containerStyle={{ padding: 0 }}
rightContainerStyle={{ width: 37, padding: 0 }}
data-testid="data-step-cell"
+ disabled={readOnly}
>
<NotebookDataPicker
query={query}
diff --git a/frontend/src/metabase/querying/notebook/components/ExpressionStep/ExpressionStep.tsx b/frontend/src/metabase/querying/notebook/components/ExpressionStep/ExpressionStep.tsx
index f0968c9c35d..83c7b55736c 100644
--- a/frontend/src/metabase/querying/notebook/components/ExpressionStep/ExpressionStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/ExpressionStep/ExpressionStep.tsx
@@ -58,6 +58,7 @@ export const ExpressionStep = ({
reportTimezone={reportTimezone}
updateQuery={updateQuery}
onClose={onClose}
+ readOnly={readOnly}
/>
)}
isLastOpened={isLastOpened}
@@ -75,6 +76,7 @@ type ExpressionPopoverProps = {
reportTimezone: string;
updateQuery: (query: Lib.Query) => Promise<void>;
onClose: () => void;
+ readOnly?: boolean;
};
function ExpressionPopover({
@@ -85,6 +87,7 @@ function ExpressionPopover({
reportTimezone,
updateQuery,
onClose,
+ readOnly,
}: ExpressionPopoverProps) {
const expressionInfo = useMemo(
() =>
@@ -133,6 +136,7 @@ function ExpressionPopover({
onChangeClause={handleChangeClause}
reportTimezone={reportTimezone}
onClose={onClose}
+ readOnly={readOnly}
/>
);
}
diff --git a/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.tsx b/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.tsx
index cbffe682d71..bf1c74cb7b5 100644
--- a/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/FilterStep/FilterStep.tsx
@@ -80,6 +80,7 @@ export function FilterStep({
onAddFilter={handleAddFilter}
onUpdateFilter={handleUpdateFilter}
onClose={onClose}
+ readOnly={readOnly}
/>
)}
onReorder={handleReorderFilter}
@@ -100,6 +101,7 @@ interface FilterPopoverProps {
nextFilter: Lib.Filterable,
) => void;
onClose?: () => void;
+ readOnly?: boolean;
}
function FilterPopover({
@@ -110,6 +112,7 @@ function FilterPopover({
onAddFilter,
onUpdateFilter,
onClose,
+ readOnly,
}: FilterPopoverProps) {
return (
<FilterPicker
@@ -125,6 +128,7 @@ function FilterPopover({
}
}}
onClose={onClose}
+ readOnly={readOnly}
/>
);
}
diff --git a/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStrategyPicker/JoinStrategyPicker.tsx b/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStrategyPicker/JoinStrategyPicker.tsx
index e2cbff02a1f..58371a52a6a 100644
--- a/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStrategyPicker/JoinStrategyPicker.tsx
+++ b/frontend/src/metabase/querying/notebook/components/JoinStep/JoinStrategyPicker/JoinStrategyPicker.tsx
@@ -3,7 +3,7 @@ import { t } from "ttag";
import IconButtonWrapper from "metabase/common/components/IconButtonWrapper";
import SelectList from "metabase/common/components/SelectList";
-import { Icon, Popover } from "metabase/ui";
+import { Icon, Popover, Tooltip } from "metabase/ui";
import * as Lib from "metabase-lib";
import { getJoinStrategyIcon } from "../utils";
@@ -38,20 +38,26 @@ export function JoinStrategyPicker({
};
return (
- <Popover opened={isOpened} position="bottom-start" onChange={setIsOpened}>
+ <Popover
+ opened={isOpened}
+ position="bottom-start"
+ onChange={setIsOpened}
+ disabled={isReadOnly}
+ >
<Popover.Target>
- <IconButtonWrapper
- disabled={isReadOnly}
- aria-label={t`Change join type`}
- onClick={() => setIsOpened(!isOpened)}
- >
- <Icon
- className={S.JoinStrategyIcon}
- name={getJoinStrategyIcon(strategyInfo)}
- tooltip={t`Change join type`}
- size={32}
- />
- </IconButtonWrapper>
+ <Tooltip disabled={isReadOnly} label={t`Change join type`}>
+ <IconButtonWrapper
+ disabled={isReadOnly}
+ aria-label={t`Change join type`}
+ onClick={() => setIsOpened(!isOpened)}
+ >
+ <Icon
+ className={S.JoinStrategyIcon}
+ name={getJoinStrategyIcon(strategyInfo)}
+ size={32}
+ />
+ </IconButtonWrapper>
+ </Tooltip>
</Popover.Target>
<Popover.Dropdown>
<JoinStrategyDropdown
diff --git a/frontend/src/metabase/querying/notebook/components/LimitStep/LimitStep.tsx b/frontend/src/metabase/querying/notebook/components/LimitStep/LimitStep.tsx
index 6d1db67c6b6..32cf7931959 100644
--- a/frontend/src/metabase/querying/notebook/components/LimitStep/LimitStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/LimitStep/LimitStep.tsx
@@ -16,6 +16,7 @@ export function LimitStep({
step,
color,
updateQuery,
+ readOnly,
}: NotebookStepProps) {
const { stageIndex } = step;
@@ -52,6 +53,7 @@ export function LimitStep({
small
onBlur={handleBlur}
onChange={handleChange}
+ readOnly={readOnly}
/>
</NotebookCell>
);
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookCell/NotebookCell.tsx b/frontend/src/metabase/querying/notebook/components/NotebookCell/NotebookCell.tsx
index c9ebeade263..1fb8b073e9a 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookCell/NotebookCell.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookCell/NotebookCell.tsx
@@ -41,6 +41,7 @@ interface NotebookCellItemProps {
"data-testid"?: string;
ref?: React.Ref<HTMLDivElement>;
className?: string;
+ hasPopover?: boolean;
}
export const NotebookCellItem = forwardRef<
@@ -56,6 +57,7 @@ export const NotebookCellItem = forwardRef<
rightContainerStyle,
children,
readOnly,
+ hasPopover,
className,
...restProps
},
@@ -71,7 +73,9 @@ export const NotebookCellItem = forwardRef<
[S.inactive]: inactive,
[S.disabled]: disabled,
[S.cursorPointer]:
- (!inactive || restProps.onClick) && !readOnly && !disabled,
+ (!inactive || restProps.onClick) &&
+ !disabled &&
+ (!readOnly || hasPopover),
},
className,
)}
diff --git a/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx b/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx
index 59eeddff565..a3a6787032c 100644
--- a/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx
+++ b/frontend/src/metabase/querying/notebook/components/NotebookDataPicker/NotebookDataPicker.tsx
@@ -172,7 +172,7 @@ function ModernDataPicker({
<>
<Tooltip
label={t`${METAKEY}+click to open in new tab`}
- hidden={!table}
+ hidden={!table || isDisabled}
events={{ hover: true, focus: false, touch: false }}
>
<DataPickerTarget
diff --git a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.module.css b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.module.css
index 94bb16e1fc7..0ae2d3d5669 100644
--- a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.module.css
+++ b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.module.css
@@ -4,5 +4,8 @@
gap: 0.5rem;
color: var(--mb-color-text-white);
font-weight: 700;
- cursor: pointer;
+
+ &:not(:disabled) {
+ cursor: pointer;
+ }
}
diff --git a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx
index c17fe6d911d..b7f477e3d2f 100644
--- a/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/SortStep/SortStep.tsx
@@ -71,19 +71,22 @@ export function SortStep({
<SortDisplayName
displayInfo={Lib.displayInfo(query, stageIndex, clause)}
onToggleSortDirection={() => handleToggleOrderByDirection(clause)}
+ disabled={readOnly}
/>
)}
- renderPopover={({ item: orderBy, index, onClose }) => (
- <SortPopover
- query={query}
- stageIndex={stageIndex}
- orderBy={orderBy}
- orderByIndex={index}
- onAddOrderBy={handleAddOrderBy}
- onUpdateOrderByColumn={handleUpdateOrderByColumn}
- onClose={onClose}
- />
- )}
+ renderPopover={({ item: orderBy, index, onClose }) =>
+ readOnly ? null : (
+ <SortPopover
+ query={query}
+ stageIndex={stageIndex}
+ orderBy={orderBy}
+ orderByIndex={index}
+ onAddOrderBy={handleAddOrderBy}
+ onUpdateOrderByColumn={handleUpdateOrderByColumn}
+ onClose={onClose}
+ />
+ )
+ }
onReorder={handleReorderOrderBy}
onRemove={handleRemoveOrderBy}
/>
@@ -158,11 +161,13 @@ const checkColumnSelected = (
interface SortDisplayNameProps {
displayInfo: Lib.OrderByClauseDisplayInfo;
onToggleSortDirection: () => void;
+ disabled?: boolean;
}
function SortDisplayName({
displayInfo,
onToggleSortDirection,
+ disabled,
}: SortDisplayNameProps) {
const icon = displayInfo.direction === "asc" ? "arrow_up" : "arrow_down";
return (
@@ -173,6 +178,7 @@ function SortDisplayName({
event.stopPropagation();
onToggleSortDirection();
}}
+ disabled={disabled}
>
<Icon name={icon} />
<span>{displayInfo.longDisplayName}</span>
diff --git a/frontend/src/metabase/querying/notebook/types.ts b/frontend/src/metabase/querying/notebook/types.ts
index c051840335a..f6849ce30e7 100644
--- a/frontend/src/metabase/querying/notebook/types.ts
+++ b/frontend/src/metabase/querying/notebook/types.ts
@@ -37,6 +37,7 @@ export interface NotebookStep {
next: NotebookStep | null;
previous: NotebookStep | null;
previewQuery?: Lib.Query | null;
+ allowPopoverWhenReadOnly?: boolean;
}
export interface NotebookStepAction {
diff --git a/frontend/src/metabase/ui/components/buttons/PopoverBackButton/PopoverBackButton.tsx b/frontend/src/metabase/ui/components/buttons/PopoverBackButton/PopoverBackButton.tsx
index 4bb083c5a4c..0e9583a2921 100644
--- a/frontend/src/metabase/ui/components/buttons/PopoverBackButton/PopoverBackButton.tsx
+++ b/frontend/src/metabase/ui/components/buttons/PopoverBackButton/PopoverBackButton.tsx
@@ -6,10 +6,11 @@ import { Icon } from "metabase/ui";
import type { BoxProps } from "../../utils";
import { Button } from "../Button";
-export type PopoverBackButtonProps = BoxProps &
+export type PopoverBackButtonProps = { withArrow?: boolean } & BoxProps &
ButtonHTMLAttributes<HTMLButtonElement>;
export function PopoverBackButton(props: PopoverBackButtonProps) {
+ const { withArrow = true, ...rest } = props;
return (
<Button
p={0}
@@ -17,9 +18,9 @@ export function PopoverBackButton(props: PopoverBackButtonProps) {
c="var(--mb-color-text-primary)"
fz="1rem"
lh="1.25rem"
- {...props}
+ {...rest}
variant="subtle"
- leftSection={<Icon name="chevronleft" />}
+ leftSection={withArrow && <Icon name="chevronleft" />}
/>
);
}