Hi,
I’m using the document service in an app. The list documents is invoked whenever one component is being loaded.
What I’ve seen is after I delete a document (from an internal component) or insert a new document from another page in the app, the documents list is not updated (it either includes the deleted element or is empty as it was before the document was added again).
My list code is as follows:
import { useQuery } from "@tanstack/react-query";
import { Meta } from "../models/Meta";
import { documentsClient, DocumentMetaData } from "@dynatrace-sdk/client-document";
async function fetcher() {
let res = await documentsClient.listDocuments({
filter: "type='haloAppDocument'",
pageSize: 50,
sort:"name"
});
const documents: DocumentMetaData[] = [];
if (res.documents) documents.push(...res.documents);
while (res.nextPageKey) {
res = await documentsClient.listDocuments({ pageKey: res.nextPageKey });
if (res.documents) documents.push(...res.documents);
}
return documents;
}
export const useListHaloDocuments = () => {
const meta: Meta = {
errorTitle: "Failed to query documents",
};
return useQuery({
queryFn: () => fetcher(),
queryKey: ["documents-list" ],
meta,
});
};
and deletion code (for example) is as follows:
let res = await documentsClient.deleteDocument({
id: haloAppDocument.documentId,
optimisticLockingVersion: haloAppDocument.documentMetaData.version
})
.then(()=> {
if (deleteFromListFunc!==undefined) {
deleteFromListFunc(haloAppDocument.documentId);
}
})
.catch((e) => {
showToast({
title: "Failed To Delete Document",
message : "An error occurred deleteing document "+haloAppDocument.documentName+". The error message was: "+e.message ,
type: "critical",
lifespan: 4000
});
});
Not sure if it helps understanding the issue but in eth dev tools I saw after each GET command to the list of documents with the right filter, a POST request to "http://localhost:3000/platform/document/v1/documents" that includes the details of the deleted document for example.
What is this POST request?
As a side note, I’ve seen recent posts abotu the new dynatrace react hooks which might handle this much easier (see React hooks | Dynatrace Developer), however could not find any decent example or documentation regarding the use of that. Should this be the solution?
What is the best practice to handle these doucments and their manipulations?