Skip to content
Snippets Groups Projects
Unverified Commit 1a411da8 authored by Nick Fitzpatrick's avatar Nick Fitzpatrick Committed by GitHub
Browse files

adding back events on persist and unpersist (#37708)

* adding back events on persist and unpersist

* adding e2e test

* using cy.clock to speed up timers
parent ee1e366a
No related branches found
No related tags found
No related merge requests found
import { restore } from "e2e/support/helpers";
import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
describe("issue 26470", { tags: "@external" }, () => {
beforeEach(() => {
restore("postgres_12");
cy.signInAsAdmin();
cy.request("POST", "/api/persist/enable");
});
it("Model Cache enable / disable button should update button text", () => {
cy.clock(Date.now());
cy.visit(`/admin/databases/${WRITABLE_DB_ID}`);
cy.button("Turn model caching on").click();
cy.button(/Done/).should("exist");
cy.tick(6000);
cy.button("Turn model caching off").should("exist");
});
});
......@@ -5,9 +5,15 @@ import ExternalLink from "metabase/core/components/ExternalLink";
import ActionButton from "metabase/components/ActionButton";
import TippyPopover from "metabase/components/Popover/TippyPopover";
import {
PERSIST_DATABASE,
UNPERSIST_DATABASE,
} from "metabase/admin/databases/database";
import { MetabaseApi } from "metabase/services";
import MetabaseSettings from "metabase/lib/settings";
import { useDispatch } from "metabase/lib/redux";
import type Database from "metabase-lib/metadata/Database";
import { getModelCacheSchemaName } from "metabase-lib/metadata/utils/models";
......@@ -51,6 +57,7 @@ function isLackPermissionsError(response: ErrorResponse) {
function ModelCachingControl({ database }: Props) {
const [error, setError] = useState<string | null>(null);
const dispatch = useDispatch();
const databaseId = database.id;
const isEnabled = database.isPersisted();
......@@ -67,8 +74,10 @@ function ModelCachingControl({ database }: Props) {
try {
if (isEnabled) {
await MetabaseApi.db_unpersist({ dbId: databaseId });
await dispatch({ type: UNPERSIST_DATABASE });
} else {
await MetabaseApi.db_persist({ dbId: databaseId });
await dispatch({ type: PERSIST_DATABASE });
}
} catch (error) {
const response = error as ErrorResponse;
......
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