delete reps on dash

This commit is contained in:
2024-05-30 17:55:43 +01:00
parent 86ead475c0
commit 7bba9ea362
5 changed files with 132 additions and 11 deletions
+38 -3
View File
@@ -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 &&
+80 -2
View File
@@ -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) => {
] || ""}
</div>
</div>
<div className="">
<button
title={t("case:do-you-want-to-delete-case-label")}
className=" cardModuleRemoveCase govuk-link govuk-link--no-underline govuk-link--inverse "
onClick={() => {
confirm(
t("case:do-you-want-to-delete-case-label") +
showTopThreeArr[key].pinswg_name +
"?\n" +
t(
"case:do-you-want-to-delete-case-disclaimer-label"
)
) &&
deleteRepItem(
props.accountDetails.containerID,
showTopThreeArr[key].pinswg_name,
showTopThreeArr[key].repfile_name
);
}}
>
&mdash;
</button>
</div>
</div>
);
});
@@ -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);
+2 -2
View File
@@ -620,7 +620,7 @@ const ViewAllResults = (props) => {
</button>
</dd>
)}
{/* {currentView.viewKey == "myRepresentations" && (
{currentView.viewKey == "myRepresentations" && (
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
<button
title={t(
@@ -648,7 +648,7 @@ const ViewAllResults = (props) => {
&mdash;
</button>
</dd>
)} */}
)}
{currentView.viewKey == "watchedCases" && (
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
<button
+2 -2
View File
@@ -1,5 +1,5 @@
import { hashAPIPath } from "../../../actions";
import { deleteBlobCase } from "../../../actions/azurestorage";
import { deleteBlobCase, deleteBlobRep } from "../../../actions/azurestorage";
import nextConnect from "next-connect";
import middleware from "../middleware/middleware";
@@ -28,7 +28,7 @@ ApiProxy.get(async (req, res) => {
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
//if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) {
await deleteBlobCase(containerName, casefolderID).then((data) => {
await deleteBlobRep(containerName, casefolderID).then((data) => {
return res.status(200).json({ data: data });
});
// } else {
+10 -2
View File
@@ -62,10 +62,18 @@ ApiProxy.get(async (req, res) => {
"\n////////////////////////////\n getRepsBlobs:",
data
);
let result = await downloadAllRepsFiles(containerName, data);
return res.status(200).json(result);
return data;
})
.then(async (data) => {
console.log("\n////////////////////////////\n now here:", data);
let result = await downloadAllRepsFiles(containerName, data);
return res
.setHeader("Cache-Control", "no-store")
.status(200)
.json(result);
})
.catch((error) => {
console.log(
"///////////////////////\ngetRepsFromBlob api in api route response: " +