Skip to content
Snippets Groups Projects
Unverified Commit 754ecb8e authored by Gustavo Saiani's avatar Gustavo Saiani Committed by GitHub
Browse files

Omit revision history item from list if no `diff` (#15942)

* Omit dashboard revision history items if no description

* Skip Revert button on topmost visible revision history entry

* Test that topmost revision history entry omits Revert button

* Lint

* Use diff as criterion for omitting revision entry

* Detail comment in shouldRenderRevisionHistory

* Render revision item if either before or after in diff is populated

* Update e2e test

* Use a more durable string to find element in test
parent 60d35e5a
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ export default class HistoryModal extends Component { ...@@ -24,7 +24,7 @@ export default class HistoryModal extends Component {
onClose: PropTypes.func.isRequired, onClose: PropTypes.func.isRequired,
}; };
revisionDescription(revision) { getRevisionDescription(revision) {
if (revision.is_creation) { if (revision.is_creation) {
return t`First revision.`; return t`First revision.`;
} else if (revision.is_reversion) { } else if (revision.is_reversion) {
...@@ -34,10 +34,27 @@ export default class HistoryModal extends Component { ...@@ -34,10 +34,27 @@ export default class HistoryModal extends Component {
} }
} }
shouldRenderRevisionEntry({ diff }) {
// diff may be null in "First revision"
// or in the earliest revision kept in store
if (diff === null) {
return true;
}
const { before, after } = diff;
return before !== null || after !== null;
}
render() { render() {
const { revisions, onRevert, onClose } = this.props; const { revisions, onRevert, onClose } = this.props;
const cellClassName = "p1 border-bottom"; const cellClassName = "p1 border-bottom";
// We must keep track of having skipped the Revert button
// because we are omitting certain revision entries,
// see function shouldRenderRevisionEntry
// They may be the very top entry so we have to use dedicated logic.
let hasSkippedMostRecentRevisionRevertButton = false;
return ( return (
<ModalContent title={t`Revision history`} onClose={onClose}> <ModalContent title={t`Revision history`} onClose={onClose}>
<table className="full"> <table className="full">
...@@ -50,29 +67,39 @@ export default class HistoryModal extends Component { ...@@ -50,29 +67,39 @@ export default class HistoryModal extends Component {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{revisions.map((revision, index) => ( {revisions.map((revision, index) => {
<tr key={revision.id}> if (this.shouldRenderRevisionEntry(revision)) {
<td className={cellClassName}> const shouldRenderRevertButton =
{formatDate(revision.timestamp)} onRevert && hasSkippedMostRecentRevisionRevertButton;
</td> hasSkippedMostRecentRevisionRevertButton = true;
<td className={cellClassName}>{revision.user.common_name}</td>
<td className={cellClassName}> return (
<span>{this.revisionDescription(revision)}</span> <tr key={revision.id}>
</td> <td className={cellClassName}>
<td className={cellClassName}> {formatDate(revision.timestamp)}
{index !== 0 && onRevert && ( </td>
<ActionButton <td className={cellClassName}>
actionFn={() => onRevert(revision)} {revision.user.common_name}
className="Button Button--small Button--danger text-uppercase" </td>
normalText={t`Revert`} <td className={cellClassName}>
activeText={t`Reverting…`} <span>{this.getRevisionDescription(revision)}</span>
failedText={t`Revert failed`} </td>
successText={t`Reverted`} <td className={cellClassName}>
/> {shouldRenderRevertButton && (
)} <ActionButton
</td> actionFn={() => onRevert(revision)}
</tr> className="Button Button--small Button--danger text-uppercase"
))} normalText={t`Revert`}
activeText={t`Reverting…`}
failedText={t`Revert failed`}
successText={t`Reverted`}
/>
)}
</td>
</tr>
);
}
})}
</tbody> </tbody>
</table> </table>
</ModalContent> </ModalContent>
......
...@@ -528,17 +528,22 @@ describe("collection permissions", () => { ...@@ -528,17 +528,22 @@ describe("collection permissions", () => {
cy.signInAsAdmin(); cy.signInAsAdmin();
}); });
it.skip("shouldn't record history steps when there was no diff (metabase#1926)", () => { it("shouldn't render revision history steps when there was no diff (metabase#1926)", () => {
cy.signInAsAdmin(); cy.signInAsAdmin();
cy.createDashboard("foo").then(({ body }) => { cy.createDashboard("foo").then(({ body }) => {
visitAndEditDashboard(body.id); visitAndEditDashboard(body.id);
}); });
// Save the dashboard without any changes made to it (TODO: we should probably disable "Save" button in the first place) // Save the dashboard without any changes made to it (TODO: we should probably disable "Save" button in the first place)
saveDashboard(); saveDashboard();
// Take a look at the generated history - there shouldn't be anything other than "First revision" (dashboard created) cy.icon("pencil").click();
cy.icon("ellipsis").click(); saveDashboard();
cy.findByText("Revision history").click();
cy.findAllByRole("button", { name: "Revert" }).should("not.exist"); openRevisionHistory();
cy.findByText("First revision.");
cy.findAllByText("Revert").should("not.exist");
}); });
it.skip("dashboard should update properly on revert (metabase#6884)", () => { it.skip("dashboard should update properly on revert (metabase#6884)", () => {
...@@ -706,3 +711,8 @@ function saveDashboard() { ...@@ -706,3 +711,8 @@ function saveDashboard() {
clickButton("Save"); clickButton("Save");
cy.findByText("You're editing this dashboard.").should("not.exist"); cy.findByText("You're editing this dashboard.").should("not.exist");
} }
function openRevisionHistory() {
cy.icon("ellipsis").click();
cy.findByText("Revision history").click();
}
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