The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Make segments read-only for published tables also on admin (#68651)
Andersonb871ae4909f9
diff --git a/e2e/test/scenarios/admin/datamodel/segments.cy.spec.ts b/e2e/test/scenarios/admin/datamodel/segments.cy.spec.tsindex 0dba62aaafd..e534701eef9 100644--- a/e2e/test/scenarios/admin/datamodel/segments.cy.spec.ts+++ b/e2e/test/scenarios/admin/datamodel/segments.cy.spec.ts@@ -1,7 +1,7 @@import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";const { H } = cy;-const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;+const { ORDERS, ORDERS_ID, PEOPLE_ID } = SAMPLE_DATABASE;describe("scenarios > admin > datamodel > segments", () => {beforeEach(() => {@@ -338,4 +338,101 @@ describe("scenarios > admin > datamodel > segments", () => {});});});++ describe("read-only remote sync", () => {+ const SEGMENT_IN_ORDERS = "Segment in Orders table (published)";+ const SEGMENT_IN_PEOPLE = "Segment in People table (Unpublished)";++ beforeEach(() => {+ H.activateToken("bleeding-edge");+ cy.log("set up remote sync");+ H.setupGitSync();+ H.configureGit("read-only");+ H.createLibrary();+ H.publishTables({ table_ids: [ORDERS_ID] });+ // Let's leave PEOPLE_ID unpublished++ cy.log("create segments");+ H.createSegment({+ name: SEGMENT_IN_ORDERS,+ description: "Hey oh",+ table_id: ORDERS_ID,+ definition: {+ type: "query",+ database: 1,+ query: {+ "source-table": ORDERS_ID,+ filter: ["<", ["field", ORDERS.TOTAL, null], 100],+ },+ },+ });++ H.createSegment({+ name: SEGMENT_IN_PEOPLE,+ description: "This is a segment in the PEOPLE table",+ table_id: PEOPLE_ID,+ definition: {+ type: "query",+ database: 1,+ query: {+ "source-table": PEOPLE_ID,+ filter: [">", ["field", 10, null], 100],+ },+ },+ });+ });++ it("can't edit published segment from segment list", () => {+ cy.visit("/admin/datamodel/segments");+ const getEllipsisIcon = (segmentName: string) => {+ return cy+ .findByTestId("segment-list-app")+ .contains(segmentName)+ .parent()+ .parent()+ .findByRole("img", { name: "ellipsis icon" });+ };++ cy.log("don't show edit or retire menu options");+ getEllipsisIcon(SEGMENT_IN_ORDERS).click();+ H.popover().contains("Edit Segment").should("not.exist");+ H.popover().contains("Retire Segment").should("not.exist");+ getEllipsisIcon(SEGMENT_IN_ORDERS).click(); // Exit menu dropdown++ getEllipsisIcon(SEGMENT_IN_PEOPLE).click();+ // For unpublished segments, the edit menu options are visible+ H.popover().contains("Edit Segment").should("be.visible");+ H.popover().contains("Retire Segment").should("be.visible");+ });++ it("can't edit published segment from segment detail page", () => {+ cy.visit("/admin/datamodel/segment/1");++ cy.findByRole("alert", {+ name: /This segment can't be edited/,+ }).should("be.visible");+ cy.findByLabelText("Name Your Segment").should("have.attr", "readonly");+ cy.findByLabelText("Describe Your Segment").should(+ "have.attr",+ "readonly",+ );+ cy.findByRole("button", { name: /Save changes/ }).should("not.exist");++ cy.log("can still edit a segment if table is not published");+ cy.visit("/admin/datamodel/segment/2");++ cy.findByRole("alert", {+ name: /This segment can't be edited/,+ }).should("not.exist");+ cy.findByLabelText("Name Your Segment").should(+ "not.have.attr",+ "readonly",+ );+ cy.findByLabelText("Describe Your Segment").should(+ "not.have.attr",+ "readonly",+ );+ cy.findByRole("button", { name: /Save changes/ }).should("be.visible");+ });+ });});diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/index.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/index.tsindex 7c249efab55..96c065c993d 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/index.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/index.ts@@ -3,6 +3,7 @@ import {PLUGIN_REDUX_MIDDLEWARES,PLUGIN_REMOTE_SYNC,} from "metabase/plugins";+import { getIsRemoteSyncReadOnly } from "metabase-enterprise/remote_sync/selectors";import { hasPremiumFeature } from "metabase-enterprise/settings";import { LibraryNav } from "./LibraryNav";@@ -44,6 +45,7 @@ export function initializePlugin() {PLUGIN_REMOTE_SYNC.useHasLibraryDirtyChanges = useHasLibraryDirtyChanges;PLUGIN_REMOTE_SYNC.useHasTransformDirtyChanges =useHasTransformDirtyChanges;+ PLUGIN_REMOTE_SYNC.getIsRemoteSyncReadOnly = getIsRemoteSyncReadOnly;PLUGIN_REDUX_MIDDLEWARES.push(remoteSyncListenerMiddleware.middleware);PLUGIN_REDUCERS.remoteSyncPlugin = remoteSyncReducer;diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.tsindex 42c51447692..5b63f6e32c7 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/selectors.ts@@ -61,9 +61,9 @@ export const getHasPendingMutation = createSelector(/*** Checks if the remote sync is enabled and in read-only mode.*/-export function getIsRemoteSyncReadOnly(state: State): boolean {+export const getIsRemoteSyncReadOnly = (state: State): boolean => {return !!(getSetting(state, "remote-sync-enabled") &&getSetting(state, "remote-sync-type") === "read-only");-}+};diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentActionSelect.tsx b/frontend/src/metabase/admin/datamodel/components/SegmentActionSelect.tsxindex 2c9c01598f4..e7c250a127d 100644--- a/frontend/src/metabase/admin/datamodel/components/SegmentActionSelect.tsx+++ b/frontend/src/metabase/admin/datamodel/components/SegmentActionSelect.tsx@@ -12,11 +12,13 @@ import { SegmentRetireModal } from "./SegmentRetireModal";interface SegmentActionSelectProps {object: Segment;onRetire: () => void;+ readOnly?: boolean;}export function SegmentActionSelect({object,onRetire,+ readOnly,}: SegmentActionSelectProps) {const [modalOpened, { open: openModal, close: closeModal }] =useDisclosure(false);@@ -30,19 +32,25 @@ export function SegmentActionSelect({</ActionIcon></Menu.Target><Menu.Dropdown p="sm">- <Menu.Item component={Link} to={Urls.dataModelSegment(object.id)}>- {t`Edit Segment`}- </Menu.Item>+ {!readOnly && (+ <Menu.Item component={Link} to={Urls.dataModelSegment(object.id)}>+ {t`Edit Segment`}+ </Menu.Item>+ )}<Menu.Itemcomponent={Link}to={Urls.dataModelSegmentRevisions(object.id)}>{t`Revision History`}</Menu.Item>- <Menu.Divider />- <Menu.Item className={S.dangerItem} onClick={openModal}>- {t`Retire Segment`}- </Menu.Item>+ {!readOnly && (+ <>+ <Menu.Divider />+ <Menu.Item className={S.dangerItem} onClick={openModal}>+ {t`Retire Segment`}+ </Menu.Item>+ </>+ )}</Menu.Dropdown></Menu><SegmentRetireModaldiff --git a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsxindex e27957e2464..7e34da57035 100644--- a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx+++ b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.tsx@@ -11,8 +11,10 @@ import {import { Button } from "metabase/common/components/Button/Button";import { FieldSet } from "metabase/common/components/FieldSet";import { useSelector } from "metabase/lib/redux";+import { PLUGIN_REMOTE_SYNC } from "metabase/plugins";import { SegmentEditor } from "metabase/querying/segments/components/SegmentEditor";import { getMetadata } from "metabase/selectors/metadata";+import { Alert } from "metabase/ui";import * as Lib from "metabase-lib";import type Metadata from "metabase-lib/v1/metadata/Metadata";import type { DatasetQuery, Segment, TableId } from "metabase-types/api";@@ -39,14 +41,16 @@ export interface SegmentFormProps {onSubmit: (values: Partial<Segment>) => void;}-const SegmentForm = ({+export const SegmentForm = ({segment,onIsDirtyChange,onSubmit,}: SegmentFormProps): JSX.Element => {const isNew = segment == null;const metadata = useSelector(getMetadata);-+ const isRemoteSyncReadOnly = useSelector(+ PLUGIN_REMOTE_SYNC.getIsRemoteSyncReadOnly,+ );const { isValid, getFieldProps, getFieldMeta, handleSubmit, dirty } =useFormik({initialValues: segment ?? {},@@ -54,6 +58,9 @@ const SegmentForm = ({validate: (values) => getFormErrors(values, metadata),onSubmit,});+ const tableId = isNew ? getFieldProps("table_id")?.value : segment?.table_id;+ const table = tableId ? metadata.tables[tableId] : undefined;+ const isReadOnly = isRemoteSyncReadOnly && !!table?.is_published;useEffect(() => {onIsDirtyChange(dirty);@@ -62,6 +69,17 @@ const SegmentForm = ({return (<FormRoot onSubmit={handleSubmit}><FormBody>+ {isReadOnly && (+ <Alert+ color="warning"+ display="inline-flex"+ mb="md"+ p="0.75rem"+ title={t`This segment can't be edited because this table is published and Remote Sync is in read-only mode.`}+ variant="outline"+ w="auto"+ />+ )}<FormLabeltitle={isNew ? t`Create Your Segment` : t`Edit Your Segment`}description={@@ -77,6 +95,7 @@ const SegmentForm = ({metadata,)}isNew={isNew}+ readOnly={isReadOnly}/></FormLabel><FormBodyContent>@@ -90,6 +109,7 @@ const SegmentForm = ({{...getFieldMeta("name")}id="name"placeholder={t`Something descriptive but not too long`}+ readOnly={isReadOnly}/></FormLabel><FormLabel@@ -102,9 +122,10 @@ const SegmentForm = ({{...getFieldMeta("description")}id="description"placeholder={t`This is a good place to be more specific about less obvious segment rules`}+ readOnly={isReadOnly}/></FormLabel>- {!isNew && (+ {!isNew && !isReadOnly && (<FieldSet legend={t`Reason For Changes`} noPadding={false}><FormLabelhtmlFor="revision_message"@@ -124,7 +145,7 @@ const SegmentForm = ({)}</FormBodyContent></FormBody>- {isNew && (+ {isNew && !isReadOnly && (<FormFooter><FormSection><SegmentFormActions isValid={isValid} />@@ -201,6 +222,3 @@ function getSegmentEditorProps(},};}--// eslint-disable-next-line import/no-default-export -- deprecated usage-export default SegmentForm;diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.unit.spec.tsx b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.unit.spec.tsxnew file mode 100644index 00000000000..1b5bdcda7c2--- /dev/null+++ b/frontend/src/metabase/admin/datamodel/components/SegmentForm/SegmentForm.unit.spec.tsx@@ -0,0 +1,110 @@+import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";+import {+ setupCardDataset,+ setupSchemaEndpoints,+ setupTableEndpoints,+} from "__support__/server-mocks";+import { mockSettings } from "__support__/settings";+import { act, renderWithProviders, screen } from "__support__/ui";+import type { EnterpriseSettings } from "metabase-types/api";+import {+ createMockDatabase,+ createMockSegment,+ createMockTable,+ createMockTokenFeatures,+} from "metabase-types/api/mocks";+import { createMockState } from "metabase-types/store/mocks";++import { SegmentForm } from "./SegmentForm";++type SetupOpts = {+ isTablePublished?: boolean;+ remoteSyncType?: EnterpriseSettings["remote-sync-type"];+};++const setup = ({ remoteSyncType, isTablePublished }: SetupOpts) => {+ const db = createMockDatabase();+ const table = createMockTable({+ is_published: isTablePublished,+ });+ const segment = createMockSegment({+ name: "My wonderful segment",+ table,+ });++ setupTableEndpoints(table);+ setupCardDataset();+ setupSchemaEndpoints(db);++ const state = createMockState({+ settings: mockSettings({+ "token-features": createMockTokenFeatures({+ remote_sync: true,+ }),+ "remote-sync-type": remoteSyncType,+ "remote-sync-enabled": !!remoteSyncType,+ }),+ });++ setupEnterpriseOnlyPlugin("remote_sync");++ renderWithProviders(+ <SegmentForm+ onIsDirtyChange={jest.fn()}+ onSubmit={jest.fn()}+ segment={segment}+ updatePreviewSummary={jest.fn()}+ />,+ {+ storeInitialState: state,+ },+ );+};++const getNameInput = () => screen.getByLabelText("Name Your Segment");+const getDescriptionInput = () =>+ screen.getByLabelText("Describe Your Segment");++describe("SegmentForm", () => {+ describe("remote sync read-only mode", () => {+ it("should make form read-only when remote sync is read-only and table is published", async () => {+ await act(() => {+ setup({ remoteSyncType: "read-only", isTablePublished: true });+ });+ expect(getNameInput()).toHaveAttribute("readonly");+ expect(getDescriptionInput()).toHaveAttribute("readonly");+ });++ it("should not make form read-only when remote sync is read-only and table is not published", async () => {+ await act(() => {+ setup({ remoteSyncType: "read-only", isTablePublished: false });+ });+ expect(getNameInput()).not.toHaveAttribute("readonly");+ expect(getDescriptionInput()).not.toHaveAttribute("readonly");+ });++ it("should not make form read-only when remote sync is read-write and table is published", async () => {+ await act(() => {+ setup({ remoteSyncType: "read-write", isTablePublished: true });+ });+ expect(getNameInput()).not.toHaveAttribute("readonly");+ expect(getDescriptionInput()).not.toHaveAttribute("readonly");+ });++ it("should not make form read-only when remote sync is read-write and table is not published", async () => {+ await act(() => {+ setup({ remoteSyncType: "read-write", isTablePublished: false });+ });+ expect(getNameInput()).not.toHaveAttribute("readonly");+ expect(getDescriptionInput()).not.toHaveAttribute("readonly");+ });++ it("should not make form read-only when remote sync is not set and table is published", async () => {+ await act(() => {+ setup({ remoteSyncType: undefined, isTablePublished: true });+ });+ expect(getNameInput()).not.toHaveAttribute("readonly");+ expect(getDescriptionInput()).not.toHaveAttribute("readonly");+ });+ });+});diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentForm/index.ts b/frontend/src/metabase/admin/datamodel/components/SegmentForm/index.tsindex cb73ecc2a91..dc8b4b6c71c 100644--- a/frontend/src/metabase/admin/datamodel/components/SegmentForm/index.ts+++ b/frontend/src/metabase/admin/datamodel/components/SegmentForm/index.ts@@ -1,2 +1 @@-// eslint-disable-next-line import/no-default-export -- deprecated usage-export { default } from "./SegmentForm";+export { SegmentForm } from "./SegmentForm";diff --git a/frontend/src/metabase/admin/datamodel/components/SegmentItem.tsx b/frontend/src/metabase/admin/datamodel/components/SegmentItem.tsxindex 55b41656034..691f8c48e50 100644--- a/frontend/src/metabase/admin/datamodel/components/SegmentItem.tsx+++ b/frontend/src/metabase/admin/datamodel/components/SegmentItem.tsx@@ -11,9 +11,10 @@ import S from "./SegmentItem.module.css";interface Props {segment: Segment;onRetire?: () => void;+ readOnly?: boolean;}-export const SegmentItem = ({ segment, onRetire }: Props) => {+export const SegmentItem = ({ segment, onRetire, readOnly }: Props) => {const canEdit = !!onRetire;return (@@ -54,7 +55,11 @@ export const SegmentItem = ({ segment, onRetire }: Props) => {{onRetire && (<Box component="td" className={S.cell} p="sm"><Flex justify="center">- <SegmentActionSelect object={segment} onRetire={onRetire} />+ <SegmentActionSelect+ object={segment}+ onRetire={onRetire}+ readOnly={readOnly}+ /></Flex></Box>)}diff --git a/frontend/src/metabase/admin/datamodel/containers/SegmentApp.jsx b/frontend/src/metabase/admin/datamodel/containers/SegmentApp.jsxindex b3c92474d67..904c1ab2e05 100644--- a/frontend/src/metabase/admin/datamodel/containers/SegmentApp.jsx+++ b/frontend/src/metabase/admin/datamodel/containers/SegmentApp.jsx@@ -9,7 +9,7 @@ import { Segments } from "metabase/entities/segments";import { Tables } from "metabase/entities/tables";import { connect } from "metabase/lib/redux";-import SegmentForm from "../components/SegmentForm";+import { SegmentForm } from "../components/SegmentForm";import { updatePreviewSummary } from "../datamodel";import { getPreviewSummary } from "../selectors";diff --git a/frontend/src/metabase/admin/datamodel/containers/SegmentListApp.jsx b/frontend/src/metabase/admin/datamodel/containers/SegmentListApp.jsxindex d75b2ad5a3d..244d3d07074 100644--- a/frontend/src/metabase/admin/datamodel/containers/SegmentListApp.jsx+++ b/frontend/src/metabase/admin/datamodel/containers/SegmentListApp.jsx@@ -13,11 +13,18 @@ import CS from "metabase/css/core/index.css";import { Segments } from "metabase/entities/segments";import { connect } from "metabase/lib/redux";import * as Urls from "metabase/lib/urls";+import { PLUGIN_REMOTE_SYNC } from "metabase/plugins";import { getUserIsAdmin } from "metabase/selectors/user";class SegmentListAppInner extends Component {render() {- const { segments, tableSelector, setArchived, isAdmin } = this.props;+ const {+ segments,+ tableSelector,+ setArchived,+ isAdmin,+ isRemoteSyncReadOnly,+ } = this.props;return (<div@@ -49,6 +56,7 @@ class SegmentListAppInner extends Component {isAdmin ? () => setArchived(segment, true) : undefined}segment={segment}+ readOnly={segment.table?.is_published && isRemoteSyncReadOnly}/>))}</tbody>@@ -66,7 +74,13 @@ class SegmentListAppInner extends Component {export const SegmentListApp = _.compose(Segments.loadList(),FilteredToUrlTable("segments"),- connect((state, props) => ({ isAdmin: getUserIsAdmin(state) }), {- setArchived: Segments.actions.setArchived,- }),+ connect(+ (state) => ({+ isAdmin: getUserIsAdmin(state),+ isRemoteSyncReadOnly: PLUGIN_REMOTE_SYNC.getIsRemoteSyncReadOnly(state),+ }),+ {+ setArchived: Segments.actions.setArchived,+ },+ ),)(SegmentListAppInner);diff --git a/frontend/src/metabase/plugins/oss/remote-sync.ts b/frontend/src/metabase/plugins/oss/remote-sync.tsindex c4b4790f33c..d94d28b35d0 100644--- a/frontend/src/metabase/plugins/oss/remote-sync.ts+++ b/frontend/src/metabase/plugins/oss/remote-sync.ts@@ -11,6 +11,7 @@ import {NotFoundPlaceholder,PluginPlaceholder,} from "metabase/plugins/components/PluginPlaceholder";+import type { State } from "metabase-types/store";export type CollectionsNavTreeProps = {collections: CollectionTreeItem[];@@ -43,6 +44,7 @@ const getDefaultPluginRemoteSync = () => ({useGitSyncVisible: () => ({ isVisible: false, currentBranch: null }),useHasLibraryDirtyChanges: () => false,useHasTransformDirtyChanges: () => false,+ getIsRemoteSyncReadOnly: () => false,});export const PLUGIN_REMOTE_SYNC: {@@ -68,6 +70,7 @@ export const PLUGIN_REMOTE_SYNC: {};useHasLibraryDirtyChanges: () => boolean;useHasTransformDirtyChanges: () => boolean;+ getIsRemoteSyncReadOnly: (state: State) => boolean;} = getDefaultPluginRemoteSync();/**diff --git a/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.module.css b/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.module.cssindex 0b03567495d..f76b9f7bc53 100644--- a/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.module.css+++ b/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.module.css@@ -5,6 +5,11 @@background-color: color-mix(in srgb, var(--mb-color-filter) 20%, transparent);border-radius: 0.75rem;overflow-wrap: anywhere;++ &.readOnly {+ cursor: default;+ pointer-events: none;+ }}.icon {diff --git a/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.tsx b/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.tsxindex 58663760ce5..681657992a6 100644--- a/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.tsx+++ b/frontend/src/metabase/querying/filters/components/FilterPanel/FilterPill/FilterPill.tsx@@ -1,3 +1,4 @@+import cx from "classnames";import type { HTMLAttributes, MouseEvent, Ref } from "react";import { forwardRef } from "react";import { t } from "ttag";@@ -8,10 +9,11 @@ import S from "./FilterPill.module.css";interface FilterPillProps extends HTMLAttributes<HTMLDivElement> {onRemoveClick?: () => void;+ readOnly?: boolean;}export const FilterPill = forwardRef(function FilterPill(- { children, onRemoveClick, ...props }: FilterPillProps,+ { children, onRemoveClick, readOnly, ...props }: FilterPillProps,ref: Ref<HTMLDivElement>,) {const handleRemoveClick = (event: MouseEvent) => {@@ -23,7 +25,7 @@ export const FilterPill = forwardRef(function FilterPill(<Flex{...props}ref={ref}- className={S.root}+ className={cx(S.root, { [S.readOnly]: readOnly })}align="center"gap="sm"px="sm"@@ -32,7 +34,7 @@ export const FilterPill = forwardRef(function FilterPill(data-testid="filter-pill">{children}- {onRemoveClick && (+ {onRemoveClick && !readOnly && (<IconclassName={S.icon}name="close"diff --git a/frontend/src/metabase/querying/segments/components/SegmentEditor/FilterStep/FilterStep.tsx b/frontend/src/metabase/querying/segments/components/SegmentEditor/FilterStep/FilterStep.tsxindex 1726a6c6eb8..e3f810fc9fb 100644--- a/frontend/src/metabase/querying/segments/components/SegmentEditor/FilterStep/FilterStep.tsx+++ b/frontend/src/metabase/querying/segments/components/SegmentEditor/FilterStep/FilterStep.tsx@@ -12,9 +12,15 @@ type FilterStepProps = {query: Lib.Query | undefined;stageIndex: number;onChange: (query: Lib.Query) => void;+ readOnly?: boolean;};-export function FilterStep({ query, stageIndex, onChange }: FilterStepProps) {+export function FilterStep({+ query,+ stageIndex,+ onChange,+ readOnly,+}: FilterStepProps) {const filters = query ? Lib.filters(query, stageIndex) : [];const hasFilters = filters.length > 0;@@ -31,14 +37,18 @@ export function FilterStep({ query, stageIndex, onChange }: FilterStepProps) {filterIndex={filterIndex}hasFilters={hasFilters}onChange={onChange}+ readOnly={readOnly}/>))}- <FilterPopover- query={query}- stageIndex={stageIndex}- hasFilters={hasFilters}- onChange={onChange}- />+ {!readOnly && (+ <FilterPopover+ query={query}+ stageIndex={stageIndex}+ hasFilters={hasFilters}+ onChange={onChange}+ readOnly={readOnly}+ />+ )}</Flex>) : (<AddFilterButton disabled />@@ -53,6 +63,7 @@ type FilterPopoverProps = {filter?: Lib.FilterClause;filterIndex?: number;hasFilters: boolean;+ readOnly?: boolean;onChange: (query: Lib.Query) => void;};@@ -63,6 +74,7 @@ function FilterPopover({filterIndex,hasFilters,onChange,+ readOnly,}: FilterPopoverProps) {const [isOpened, setIsOpened] = useState(false);const filterInfo = filter@@ -91,6 +103,7 @@ function FilterPopover({<FilterPillonClick={() => setIsOpened(!isOpened)}onRemoveClick={handleRemove}+ readOnly={readOnly}>{filterInfo.displayName}</FilterPill>@@ -98,6 +111,7 @@ function FilterPopover({<AddFilterButtoncompact={hasFilters}onClick={() => setIsOpened(!isOpened)}+ disabled={readOnly}/>)}</Popover.Target>diff --git a/frontend/src/metabase/querying/segments/components/SegmentEditor/SegmentEditor.tsx b/frontend/src/metabase/querying/segments/components/SegmentEditor/SegmentEditor.tsxindex c5f37710e57..f24dbf48b5b 100644--- a/frontend/src/metabase/querying/segments/components/SegmentEditor/SegmentEditor.tsx+++ b/frontend/src/metabase/querying/segments/components/SegmentEditor/SegmentEditor.tsx@@ -12,9 +12,15 @@ type SegmentEditorProps = {query: Lib.Query | undefined;isNew: boolean;onChange: (query: Lib.Query) => void;+ readOnly?: boolean;};-export function SegmentEditor({ query, isNew, onChange }: SegmentEditorProps) {+export function SegmentEditor({+ query,+ isNew,+ onChange,+ readOnly,+}: SegmentEditorProps) {return (<Flex className={S.root} data-testid="segment-editor"><DataStep@@ -23,7 +29,12 @@ export function SegmentEditor({ query, isNew, onChange }: SegmentEditorProps) {isNew={isNew}onChange={onChange}/>- <FilterStep query={query} stageIndex={STAGE_INDEX} onChange={onChange} />+ <FilterStep+ query={query}+ stageIndex={STAGE_INDEX}+ onChange={onChange}+ readOnly={readOnly}+ /><PreviewStep query={query} stageIndex={STAGE_INDEX} /></Flex>);