delete reps on dash
This commit is contained in:
+38
-3
@@ -494,6 +494,41 @@ export const deleteBlobCase = async (containerName, blobName) => {
|
|||||||
return { "deleted": 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) => {
|
export const uploadFile = async (formContent, containerName, foldername) => {
|
||||||
const containerToken = await createContainerSas(containerName);
|
const containerToken = await createContainerSas(containerName);
|
||||||
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
|
const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`;
|
||||||
@@ -887,7 +922,7 @@ export const downloadAllRepsFiles = async (containerName, repsBlobObj) => {
|
|||||||
console.log("is empt and an array");
|
console.log("is empt and an array");
|
||||||
|
|
||||||
for (const prop in repsBlobObj) {
|
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);
|
blobClient = containerClient.getBlobClient(repsBlobObj[prop].path);
|
||||||
downloadedBlob = await blobClient.download(0);
|
downloadedBlob = await blobClient.download(0);
|
||||||
let repBlobObj = await streamToBuffer(
|
let repBlobObj = await streamToBuffer(
|
||||||
@@ -1100,7 +1135,7 @@ export const getRepsBlobs = async (containerName) => {
|
|||||||
for await (const blob of containerClient.findBlobsByTags(
|
for await (const blob of containerClient.findBlobsByTags(
|
||||||
"blobType='Representation'"
|
"blobType='Representation'"
|
||||||
)) {
|
)) {
|
||||||
console.log(`-----Blob ${blobCount++}: ${blob.name}`);
|
console.log(`-----Get Rep Blob ${blobCount++}: ${blob.name}`);
|
||||||
blobCount++;
|
blobCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1122,7 +1157,7 @@ export const getRepsBlobs = async (containerName) => {
|
|||||||
"blobType='Representation'",
|
"blobType='Representation'",
|
||||||
listOptions
|
listOptions
|
||||||
)) {
|
)) {
|
||||||
const blobClient = await containerClient.getBlobClient(blob.name);
|
const blobClient = containerClient.getBlobClient(blob.name);
|
||||||
console.log("getreps blob:", blob);
|
console.log("getreps blob:", blob);
|
||||||
blob.name.split("/")[2].indexOf("_rep.json") > 0 &&
|
blob.name.split("/")[2].indexOf("_rep.json") > 0 &&
|
||||||
blob.name.split("/")[2].indexOf("undefined") < 0 &&
|
blob.name.split("/")[2].indexOf("undefined") < 0 &&
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ import {
|
|||||||
getAwaitingSubmissionProxy,
|
getAwaitingSubmissionProxy,
|
||||||
getPortalModuleDetailsProxy,
|
getPortalModuleDetailsProxy,
|
||||||
getWatchedCasesProxy,
|
getWatchedCasesProxy,
|
||||||
|
deleteMyRepresentationsFromBlob,
|
||||||
|
getRepsFromBlobProxy,
|
||||||
} from "../../actions";
|
} from "../../actions";
|
||||||
import {
|
import {
|
||||||
setAwaitingSubmission,
|
setAwaitingSubmission,
|
||||||
setAwaitingSubmissionDetails,
|
setAwaitingSubmissionDetails,
|
||||||
} from "../../store/awaitingSubmission/action";
|
} from "../../store/awaitingSubmission/action";
|
||||||
import { setCurrentReference } from "../../store/currentView/action";
|
|
||||||
import {
|
import {
|
||||||
setWatchedCases,
|
setWatchedCases,
|
||||||
setWatchedCasesDetails,
|
setWatchedCasesDetails,
|
||||||
@@ -22,6 +23,17 @@ import {
|
|||||||
import { getFormCollectionByID } from "../utils";
|
import { getFormCollectionByID } from "../utils";
|
||||||
import { JSONPath as jsonpath } from "jsonpath-plus";
|
import { JSONPath as jsonpath } from "jsonpath-plus";
|
||||||
import transLookup from "../../data/lookuptranslations.json";
|
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) => {
|
const TopThree = (props) => {
|
||||||
let { t } = useTranslation();
|
let { t } = useTranslation();
|
||||||
@@ -34,6 +46,8 @@ const TopThree = (props) => {
|
|||||||
setWatchedCasesDetails,
|
setWatchedCasesDetails,
|
||||||
setAwaitingSubmission,
|
setAwaitingSubmission,
|
||||||
setAwaitingSubmissionDetails,
|
setAwaitingSubmissionDetails,
|
||||||
|
setMyRepresentations,
|
||||||
|
setMyRepresentationsDetails,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const router = useRouter();
|
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) => {
|
const getDetails = (resultsObj, detailsType) => {
|
||||||
//console.log(resultsObj);
|
//console.log(resultsObj);
|
||||||
let detailsArr = [];
|
let detailsArr = [];
|
||||||
@@ -247,6 +288,29 @@ const TopThree = (props) => {
|
|||||||
] || ""}
|
] || ""}
|
||||||
</div>
|
</div>
|
||||||
</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
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
—
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</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) => {
|
const mapDispatchToProps = (dispatch) => {
|
||||||
return {
|
return {
|
||||||
@@ -294,7 +366,13 @@ const mapDispatchToProps = (dispatch) => {
|
|||||||
setAwaitingSubmissionDetails: (awaitingSubmissionDetails) => {
|
setAwaitingSubmissionDetails: (awaitingSubmissionDetails) => {
|
||||||
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);
|
||||||
|
|||||||
@@ -620,7 +620,7 @@ const ViewAllResults = (props) => {
|
|||||||
</button>
|
</button>
|
||||||
</dd>
|
</dd>
|
||||||
)}
|
)}
|
||||||
{/* {currentView.viewKey == "myRepresentations" && (
|
{currentView.viewKey == "myRepresentations" && (
|
||||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
|
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
|
||||||
<button
|
<button
|
||||||
title={t(
|
title={t(
|
||||||
@@ -648,7 +648,7 @@ const ViewAllResults = (props) => {
|
|||||||
—
|
—
|
||||||
</button>
|
</button>
|
||||||
</dd>
|
</dd>
|
||||||
)} */}
|
)}
|
||||||
{currentView.viewKey == "watchedCases" && (
|
{currentView.viewKey == "watchedCases" && (
|
||||||
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
|
<dd className="govuk-summary-list__value govuk-!-font-size-16 cardModuleItem ">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { hashAPIPath } from "../../../actions";
|
import { hashAPIPath } from "../../../actions";
|
||||||
import { deleteBlobCase } from "../../../actions/azurestorage";
|
import { deleteBlobCase, deleteBlobRep } from "../../../actions/azurestorage";
|
||||||
|
|
||||||
import nextConnect from "next-connect";
|
import nextConnect from "next-connect";
|
||||||
import middleware from "../middleware/middleware";
|
import middleware from "../middleware/middleware";
|
||||||
@@ -28,7 +28,7 @@ ApiProxy.get(async (req, res) => {
|
|||||||
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
|
// console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash);
|
||||||
|
|
||||||
//if (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 });
|
return res.status(200).json({ data: data });
|
||||||
});
|
});
|
||||||
// } else {
|
// } else {
|
||||||
|
|||||||
@@ -62,10 +62,18 @@ ApiProxy.get(async (req, res) => {
|
|||||||
"\n////////////////////////////\n getRepsBlobs:",
|
"\n////////////////////////////\n getRepsBlobs:",
|
||||||
data
|
data
|
||||||
);
|
);
|
||||||
let result = await downloadAllRepsFiles(containerName, data);
|
return data;
|
||||||
return res.status(200).json(result);
|
|
||||||
})
|
})
|
||||||
|
.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) => {
|
.catch((error) => {
|
||||||
console.log(
|
console.log(
|
||||||
"///////////////////////\ngetRepsFromBlob api in api route response: " +
|
"///////////////////////\ngetRepsFromBlob api in api route response: " +
|
||||||
|
|||||||
Reference in New Issue
Block a user