Skip to content

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

Update document cache with creation result (#62612)

Nick Fitzpatrick4f1ff924a8ca
diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.ts
index f9b2dec4b68..4bf099798cb 100644
--- a/e2e/test/scenarios/documents/documents.cy.spec.ts
+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts
@@ -20,6 +20,10 @@ H.describeWithSnowplowEE("documents", () => {
});
it("should allow you to create a new document from the new button and save", () => {
+ const getDocumentStub = cy.stub();
+
+ cy.intercept("GET", "/api/ee/document/1", getDocumentStub);
+
cy.visit("/");
H.newButton("Document").click();
@@ -41,9 +45,13 @@ H.describeWithSnowplowEE("documents", () => {
);
H.entityPickerModalItem(1, "First collection").click();
H.entityPickerModal().findByRole("button", { name: "Select" }).click();
+
+ // We should not show a loading state in between creating a document and viewing the created document.
+ cy.location("pathname").should("eq", "/document/1");
cy.title().should("eq", "Test Document · Metabase");
H.expectUnstructuredSnowplowEvent({ event: "document_created" });
+ cy.wrap(getDocumentStub).should("not.have.been.called");
H.appBar()
.findByRole("link", { name: /First collection/ })
diff --git a/enterprise/frontend/src/metabase-enterprise/api/document.ts b/enterprise/frontend/src/metabase-enterprise/api/document.ts
index 9d2caf62b9f..095e303872a 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/document.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/document.ts
@@ -26,6 +26,17 @@ export const documentApi = EnterpriseApi.injectEndpoints({
body,
}),
invalidatesTags: (_, error) => (error ? [] : [listTag("document")]),
+ async onQueryStarted(_props, { dispatch, queryFulfilled }) {
+ await queryFulfilled.then(async ({ data }) => {
+ await dispatch(
+ documentApi.util.upsertQueryData(
+ "getDocument",
+ { id: data.id },
+ data,
+ ),
+ );
+ });
+ },
}),
updateDocument: builder.mutation<Document, UpdateDocumentRequest>({
query: (document) => ({
diff --git a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx
index 11a49eb1bbf..adbea023c76 100644
--- a/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/documents/components/Editor/Editor.tsx
@@ -193,7 +193,7 @@ export const Editor: React.FC<EditorProps> = ({
if (isLoading) {
return (
<Box className={cx(S.editor, DND_IGNORE_CLASS_NAME)}>
- <Loader />
+ <Loader data-testid="editor-loader" />
</Box>
);
}