Skip to content
Snippets Groups Projects
Unverified Commit 7e4b7482 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Fix segments revision history (#45581)

* Fix segments revision history

* Simplify fetchSegments selector

* Fix breadcrumbs

* Add E2E reproduction for #45577
parent 26aaa6a8
No related branches found
No related tags found
No related merge requests found
......@@ -879,6 +879,52 @@ describe("scenarios > admin > datamodel > segments", () => {
modal().find("textarea").type("delete it");
modal().contains("button", "Retire").click();
});
it("should show segment revision history (metabase#45577)", () => {
cy.request("PUT", "/api/segment/1", {
description: "Medium orders",
revision_message: "Foo",
});
cy.visit("/admin/datamodel/segments");
cy.get("tr")
.filter(`:contains(${SEGMENT_NAME})`)
.icon("ellipsis")
.click();
popover().findByTextEnsureVisible("Revision History").click();
cy.log(
"Make sure revisions are displayed properly in admin table metadata",
);
cy.location("pathname").should(
"eq",
"/admin/datamodel/segment/1/revisions",
);
cy.findByTestId("breadcrumbs")
.should("contain", "Segments")
.and("contain", "Segment History");
assertRevisionHistory();
cy.log("Make sure revisions are displayed properly in /references");
cy.visit("/reference/segments/1/revisions");
assertRevisionHistory();
function assertRevisionHistory() {
cy.findByTestId("segment-revisions")
.findAllByRole("listitem")
.as("revisions")
.should("have.length", 2);
cy.get("@revisions")
.first()
.should("contain", "You edited the description")
.and("contain", "Foo");
cy.get("@revisions")
.last()
.should("contain", `You created "${SEGMENT_NAME}"`)
.and("contain", "All orders with a total under $100.");
}
});
});
});
......
......@@ -20,7 +20,7 @@ class RevisionHistory extends Component {
};
render() {
const { object, objectType, revisions, table, user } = this.props;
const { object, revisions, table, user } = this.props;
let userColorAssignments = {};
if (revisions) {
......@@ -37,13 +37,15 @@ class RevisionHistory extends Component {
<Breadcrumbs
className={CS.py4}
crumbs={[
objectType === "segment"
? [t`Segments`, `/admin/datamodel/segments?table=${table.id}`]
: [t`Metrics`, `/admin/datamodel/metrics?table=${table.id}`],
[this.props.objectType + t` History`],
[t`Segments`, `/admin/datamodel/segments?table=${table.id}`],
[t`Segment` + t` History`],
]}
/>
<div className={cx(CS.wrapper, CS.py4)} style={{ maxWidth: 950 }}>
<div
className={cx(CS.wrapper, CS.py4)}
style={{ maxWidth: 950 }}
data-testid="segment-revisions"
>
<h2 className={CS.mb4}>
{t`Revision History for`} &quot;{object.name}&quot;
</h2>
......
......@@ -5,25 +5,21 @@ import { connect } from "react-redux";
import Segments from "metabase/entities/segments";
import RevisionHistory from "../components/revisions/RevisionHistory";
import { fetchRevisions } from "../datamodel";
import { fetchSegmentRevisions } from "../datamodel";
import { getRevisions, getCurrentUser } from "../selectors";
const mapStateToProps = (state, props) => ({
objectType: props.params.entity,
id: props.params.id,
user: getCurrentUser(state),
revisions: getRevisions(state),
});
const mapDispatchToProps = { fetchRevisions };
const mapDispatchToProps = { fetchSegmentRevisions };
class RevisionHistoryApp extends Component {
componentDidMount() {
const { id, objectType } = this.props;
this.props.fetchRevisions({
entity: objectType === "metric" ? "legacy-metric" : objectType,
id,
});
const { id } = this.props;
this.props.fetchSegmentRevisions(id);
}
render() {
......
......@@ -21,11 +21,9 @@ export const updatePreviewSummary = createAction(
export const FETCH_REVISIONS = "metabase/admin/datamodel/FETCH_REVISIONS";
export const fetchRevisions = createThunkAction(
export const fetchSegmentRevisions = createThunkAction(
FETCH_REVISIONS,
({ entity, id }) =>
async () =>
RevisionsApi.get({ entity, id }),
id => async () => RevisionsApi.get({ entity: "segment", id }),
);
// reducers
......
......@@ -70,7 +70,7 @@ class SegmentRevisions extends Component {
: {};
return (
<div style={style} className={CS.full}>
<div style={style} className={CS.full} data-testid="segment-revisions">
<ReferenceHeader
name={t`Revision history for ${this.props.segment.name}`}
headerIcon="segment"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment