public/javascripts/index.js in pact_broker-2.84.0 vs public/javascripts/index.js in pact_broker-2.85.0
- old
+ new
@@ -22,18 +22,19 @@
return `This will delete ${rowData.consumerName} and ${
rowData.providerName
}, and all associated data (pacts, verifications, application versions, tags and webhooks) that are not associated with other integrations. Do you wish to continue?`;
}
-function createPactTagDeletionConfirmationText({
+function createPactTagOrBranchDeletionConfirmationText({
providerName,
consumerName,
- pactTagName
+ refName,
+ scope
}) {
return `This will delete the pacts for provider ${providerName} and all versions of ${
consumerName
- } with tag ${pactTagName}. Do you wish to continue?`;
+ } ${scope} ${refName}. Do you wish to continue?`;
}
function handleDeletePactsSelected(clickedElement) {
const tr = $(clickedElement).closest("tr");
const confirmationText = createPactDeletionConfirmationText(tr.data());
@@ -48,28 +49,30 @@
const tr = $(clickedElement).closest("tr");
const confirmationText = createIntegrationDeletionConfirmationText(tr.data());
handleDeleteResourcesSelected(tr, tr.data().integrationUrl, confirmationText);
}
-function handleDeleteTagSelected({
+function handleDeleteTagOrBranchSelected({
providerName,
consumerName,
- pactTagName,
- deletionUrl
+ refName,
+ deletionUrl,
+ scope
}) {
return function(clickedElement) {
const tr = $(clickedElement).closest("tr");
- const confirmationText = createPactTagDeletionConfirmationText({
+ const confirmationText = createPactTagOrBranchDeletionConfirmationText({
providerName,
consumerName,
- pactTagName
+ refName,
+ scope
});
handleDeleteResourcesSelected(
tr,
deletionUrl,
confirmationText,
- pactTagName
+ refName
);
};
}
function findRowsToBeDeleted(table, consumerName, providerName, tagName) {
@@ -132,57 +135,36 @@
row.closest("table"),
rowData.consumerName,
rowData.providerName,
tagName
);
- const isRefreshingThePage = !!tagName;
const cancelled = function() {
- unHighlightRows(rows);
+ unHighlightRows(row);
};
const confirmed = function() {
deleteResources(
deletionUrl,
- function() {
- handleDeletionSuccess(rows, isRefreshingThePage);
- },
+ handleDeletionSuccess,
function(response) {
- handleDeletionFailure(rows, response);
+ handleDeletionFailure(row, response);
}
);
};
- if (!isRefreshingThePage) {
- highlightRowsToBeDeleted(rows);
- }
+
+ highlightRowsToBeDeleted(row);
+
confirmDeleteResources(confirmationText, confirmed, cancelled);
}
-function hideDeletedRows(rows) {
- rows
- .children("td, th")
- .animate({ padding: 0 })
- .wrapInner("<div />")
- .children()
- .slideUp(function() {
- $(this)
- .closest("tr")
- .remove();
- });
-}
-
function refreshPage() {
const url = new URL(window.location);
- url.searchParams.delete("search");
window.location = url.toString();
}
-function handleDeletionSuccess(rows, isRefreshingThePage) {
- if (isRefreshingThePage) {
- return refreshPage();
- }
-
- hideDeletedRows(rows);
+function handleDeletionSuccess() {
+ return refreshPage();
}
function createErrorMessage(responseBody) {
if (
responseBody &&
@@ -226,39 +208,64 @@
}
});
}
function buildMaterialMenuItems(clickedElementData) {
- const baseOptions = [
- {
- type: "normal",
- text: "Delete pacts ...",
- click: handleDeletePactsSelected
- },
- {
- type: "normal",
- text: "Delete integration...",
- click: handleDeleteIntegrationsSelected
- }
- ];
-
- const taggedPacts = clickedElementData.taggedPacts || [];
const providerName = clickedElementData.providerName;
const consumerName = clickedElementData.consumerName;
- const taggedPactsOptions = taggedPacts.map(taggedPact => {
- const taggedPactObject = JSON.parse(taggedPact);
- const pactTagName = taggedPactObject.tag;
- const taggedPactUrl = taggedPactObject.deletionUrl;
- return {
- type: "normal",
- text: `Delete pacts for ${pactTagName}...`,
- click: handleDeleteTagSelected({
- providerName,
- consumerName,
- pactTagName,
- deletionUrl: taggedPactUrl
- })
- };
- });
- return [...baseOptions, ...taggedPactsOptions];
+ const branchOptions = (clickedElementData.pactBranches || []).map(branch => {
+ const refName = branch.name;
+ const deletionUrl = branch.deletionUrl;
+ return {
+ type: "normal",
+ text: `Delete pacts from branch ${refName}...`,
+ click: handleDeleteTagOrBranchSelected({
+ providerName,
+ consumerName,
+ refName,
+ deletionUrl: deletionUrl,
+ scope: "for branch"
+ })
+ };
+ });
+
+ const tagOptions = (clickedElementData.pactTags || []).map(tag => {
+ const refName = tag.name;
+ const deletionUrl = tag.deletionUrl;
+ return {
+ type: "normal",
+ text: `Delete pacts for tag ${refName}...`,
+ click: handleDeleteTagOrBranchSelected({
+ providerName,
+ consumerName,
+ refName,
+ deletionUrl,
+ scope: "with tag"
+ })
+ };
+ });
+
+
+ if (clickedElementData.view === "branch") {
+ return branchOptions;
+ } else if (clickedElementData.view === "tag") {
+ return tagOptions;
+ } else if (clickedElementData.view === "all") {
+ return [...branchOptions, ...tagOptions];
+ } else if (clickedElementData.index) {
+ return [
+ {
+ type: "normal",
+ text: "Delete pacts ...",
+ click: handleDeletePactsSelected
+ },
+ {
+ type: "normal",
+ text: "Delete integration...",
+ click: handleDeleteIntegrationsSelected
+ }
+ ];
+ } else {
+ return []
+ }
}