From 7bba9ea362820f1a1c988c3b9af33f5b6ae224c1 Mon Sep 17 00:00:00 2001 From: rdbsolutions Date: Thu, 30 May 2024 17:55:43 +0100 Subject: [PATCH] delete reps on dash --- actions/azurestorage.js | 41 +++++++++++++- components/myportal/topthree_reps.js | 82 +++++++++++++++++++++++++++- components/myportal/viewall.js | 4 +- pages/api/file/deleteblobrep.js | 4 +- pages/api/file/getrepsblob.js | 12 +++- 5 files changed, 132 insertions(+), 11 deletions(-) diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 7a86779f..b7acd5e9 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -494,6 +494,41 @@ export const deleteBlobCase = async (containerName, blobName) => { return { "deleted": blobName }; }; +export const deleteBlobRep = async (containerName, blobName) => { + const creds = new DefaultAzureCredential(); + + const options = { + deleteSnapshots: "include", // or 'only' + }; + + const containerToken = await createContainerSas(containerName); + const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; + const containerClient = new ContainerClient(sasUrl); + + console.log("blob to delete:", blobName); + + for await (const blob of containerClient.listBlobsFlat({ + prefix: blobName, + })) { + console.log("------ :", blob.name); + const blockBlobClient = containerClient.getBlockBlobClient(blob.name); + console.log("=======:", await blockBlobClient.exists()); + + (await blockBlobClient.exists()) && + containerClient.deleteBlob(blob.name); + + //containerClient.deleteIfExists(); + //containerClient.deleteBlob(blob.name); + } + + // containerClient.deleteBlob(blobName); + // console.log(`deleted blob ${blobName}`); + // for await (const blob of containerClient.listBlobsFlat()) { + // console.log(" ------ :", blob.name); + // } + return { "deleted": blobName }; +}; + export const uploadFile = async (formContent, containerName, foldername) => { const containerToken = await createContainerSas(containerName); const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; @@ -887,7 +922,7 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => { console.log("is empt and an array"); for (const prop in repsBlobObj) { - //console.log(`Progress - ${prop}: ${repsBlobObj[prop].path}`); + console.log(`Progress - ${prop}: ${repsBlobObj[prop].path}`); blobClient = containerClient.getBlobClient(repsBlobObj[prop].path); downloadedBlob = await blobClient.download(0); let repBlobObj = await streamToBuffer( @@ -1100,7 +1135,7 @@ export const getRepsBlobs = async (containerName) => { for await (const blob of containerClient.findBlobsByTags( "blobType='Representation'" )) { - console.log(`-----Blob ${blobCount++}: ${blob.name}`); + console.log(`-----Get Rep Blob ${blobCount++}: ${blob.name}`); blobCount++; } @@ -1122,7 +1157,7 @@ export const getRepsBlobs = async (containerName) => { "blobType='Representation'", listOptions )) { - const blobClient = await containerClient.getBlobClient(blob.name); + const blobClient = containerClient.getBlobClient(blob.name); console.log("getreps blob:", blob); blob.name.split("/")[2].indexOf("_rep.json") > 0 && blob.name.split("/")[2].indexOf("undefined") < 0 && diff --git a/components/myportal/topthree_reps.js b/components/myportal/topthree_reps.js index 5795eeb1..32b4b084 100644 --- a/components/myportal/topthree_reps.js +++ b/components/myportal/topthree_reps.js @@ -9,12 +9,13 @@ import { getAwaitingSubmissionProxy, getPortalModuleDetailsProxy, getWatchedCasesProxy, + deleteMyRepresentationsFromBlob, + getRepsFromBlobProxy, } from "../../actions"; import { setAwaitingSubmission, setAwaitingSubmissionDetails, } from "../../store/awaitingSubmission/action"; -import { setCurrentReference } from "../../store/currentView/action"; import { setWatchedCases, setWatchedCasesDetails, @@ -22,6 +23,17 @@ import { import { getFormCollectionByID } from "../utils"; import { JSONPath as jsonpath } from "jsonpath-plus"; import transLookup from "../../data/lookuptranslations.json"; +import { + setMyRepresentations, + setMyRepresentationsDetails, + setMySubmittedReps, + setMySubmittedRepsDetails, +} from "../../store/myRepresentations/action"; +import { + setCurrentLinkedCases, + setCurrentReference, + setCurrentView, +} from "../../store/currentView/action"; const TopThree = (props) => { let { t } = useTranslation(); @@ -34,6 +46,8 @@ const TopThree = (props) => { setWatchedCasesDetails, setAwaitingSubmission, setAwaitingSubmissionDetails, + setMyRepresentations, + setMyRepresentationsDetails, } = props; const router = useRouter(); @@ -93,6 +107,33 @@ const TopThree = (props) => { }); }; + const deleteRepItem = (containerID, caseID, repfile) => { + let cookies = parseCookies(); + console.log("sssss", containerID, caseID, repfile); + + deleteMyRepresentationsFromBlob(containerID, caseID, repfile) + .then((data) => { + return data; + }) + .then(() => { + getRepsFromBlobProxy(containerID) + .then((data) => { + setMyRepresentations(data); + setMyRepresentationsDetails(data); + }) + .catch((err) => { + consoleLogger(err); + res.status(400).json(err); + }) + .then(() => { + setCurrentView({ + "viewName": "My Representations", + "viewKey": "myRepresentations", + }); + }); + }); + }; + const getDetails = (resultsObj, detailsType) => { //console.log(resultsObj); let detailsArr = []; @@ -247,6 +288,29 @@ const TopThree = (props) => { ] || ""} +
+ +
); }); @@ -276,6 +340,14 @@ const TopThree = (props) => { ); }; +const mapStateToProps = (state) => { + return { + // currentView: state.currentView, + accountDetails: state.accountDetails, + // search: state.search, + // searchResultsObj: state.searchResultsObj, + }; +}; const mapDispatchToProps = (dispatch) => { return { @@ -294,7 +366,13 @@ const mapDispatchToProps = (dispatch) => { setAwaitingSubmissionDetails: (awaitingSubmissionDetails) => { dispatch(setAwaitingSubmissionDetails(awaitingSubmissionDetails)); }, + setMyRepresentations: (myRepresentations) => { + dispatch(setMyRepresentations(myRepresentations)); + }, + setMyRepresentationsDetails: (myRepresentationsDetails) => { + dispatch(setMyRepresentationsDetails(myRepresentationsDetails)); + }, }; }; -export default connect(null, mapDispatchToProps)(TopThree); +export default connect(mapStateToProps, mapDispatchToProps)(TopThree); diff --git a/components/myportal/viewall.js b/components/myportal/viewall.js index 800286da..b772744f 100644 --- a/components/myportal/viewall.js +++ b/components/myportal/viewall.js @@ -620,7 +620,7 @@ const ViewAllResults = (props) => { )} - {/* {currentView.viewKey == "myRepresentations" && ( + {currentView.viewKey == "myRepresentations" && (
- )} */} + )} {currentView.viewKey == "watchedCases" && (