Skip to content

Commit

Permalink
fix dufoli#50 clear flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Dufgui committed May 10, 2024
1 parent 824769c commit 10de8bf
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 23 deletions.
47 changes: 31 additions & 16 deletions addon/button.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,47 @@
margin: 2px;
}

.checkboxScrollSandbox {
.headerFixed {
position: fixed;
top: 10px;
right: 78px;
z-index: 10000;
}
.checkboxScrollProd{
position: fixed;
top: 21px;
right: 78px;
z-index: 10000;

.clearFlowButton {
right: 250px;
}
.labelCheckboxScrollSandbox{
position: fixed;

.clearFlowButtonSandbox {
top: 7px;
right: 100px;
color: white;
z-index: 10000;
}
.labeCheckboxScrollProd{
position: fixed;

.clearFlowButtonProd {
top: 15px;
}

.checkboxScroll {
right: 78px;
}

.checkboxScrollSandbox {
top: 10px;
}

.checkboxScrollProd {
top: 21px;
}

.labeCheckboxScroll {
right: 100px;
color: white;
z-index: 10000;
}

.labelCheckboxScrollSandbox {
top: 7px;
}
.labeCheckboxScrollProd {
top: 15px;
}

.copiedText {
font-family: "Salesforce Sans", Arial, sans-serif;
color: #28a745;
Expand Down
36 changes: 32 additions & 4 deletions addon/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* global showStdPageDetails */
"use strict";



// sfdcBody = normal Salesforce page
// ApexCSIPage = Developer Console
// auraLoadingBox = Lightning / Salesforce1
Expand Down Expand Up @@ -42,16 +44,31 @@ function initButton(sfHost, inInspector) {
const checkboxState = iFrameLocalStorage.scrollOnFlowBuilder;
// Check local storage for the checkbox state
(checkboxState != null) ? (overflowCheckbox.checked = checkboxState) : (overflowCheckbox.checked = true);
// Create a new button element to clear old flow
const clearFlowButton = document.createElement("button");
clearFlowButton.textContent = "Clear old flow versions";
clearFlowButton.classList.add("headerFixed");
clearFlowButton.classList.add("clearFlowButton");
if (currentUrl.includes("sandbox")){
clearFlowButton.classList.add("clearFlowButtonSandbox");
} else {
clearFlowButton.classList.add("clearFlowButtonProd");
}

// Create a new label element for the checkbox
const overflowLabel = document.createElement("label");
overflowLabel.textContent = "Enable flow scrollability";
overflowLabel.htmlFor = "overflow-checkbox";
overflowCheckbox.classList.add("headerFixed");
overflowLabel.classList.add("headerFixed");
overflowCheckbox.classList.add("checkboxScroll");
overflowLabel.classList.add("labeCheckboxScroll");
if (currentUrl.includes("sandbox")){
overflowCheckbox.className = "checkboxScrollSandbox";
overflowLabel.className = "labelCheckboxScrollSandbox";
overflowCheckbox.classList.add("checkboxScrollSandbox");
overflowLabel.classList.add("labelCheckboxScrollSandbox");
} else {
overflowCheckbox.className = "checkboxScrollProd";
overflowLabel.className = "labeCheckboxScrollProd";
overflowCheckbox.classList.add("checkboxScrollProd");
overflowLabel.classList.add("labeCheckboxScrollProd");
}
// Get a reference to the <head> element
const head = document.head;
Expand All @@ -62,10 +79,21 @@ function initButton(sfHost, inInspector) {
// Append the <style> element to the <head> element
head.appendChild(style);
// Append the checkbox and label elements to the body of the document
headerFlow.appendChild(clearFlowButton);
headerFlow.appendChild(overflowCheckbox);
headerFlow.appendChild(overflowLabel);
// Set the overflow property to "auto"
overflowCheckbox.checked ? style.textContent = ".canvas {overflow : auto!important ; }" : style.textContent = ".canvas {overflow : hidden!important ; }";

clearFlowButton.addEventListener("click", () => {
let clearArgs = {
keep: 5
};
popupEl.contentWindow.postMessage({
clearOlderFlows: JSON.stringify(clearArgs)
}, "*");
});

// Listen for changes to the checkbox state
overflowCheckbox.addEventListener("change", function() {
// Check if the checkbox is currently checked
Expand Down
6 changes: 3 additions & 3 deletions addon/data-load.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,9 +923,9 @@ export class Editor extends React.Component {
if (selectionStart != selectionEnd) {
model.editor.setRangeText(closeChar, selectionEnd + 1, selectionEnd + 1, "preserve");
} else if (
(e.key !== "'" && e.key !== "\"") ||
(selectionEnd + 1 < model.editor.value.length && /[\w|\s]/.test(model.editor.value.substring(selectionEnd + 1, selectionEnd + 2))) ||
selectionEnd + 1 === model.editor.value.length) {
(e.key !== "'" && e.key !== "\"")
|| (selectionEnd + 1 < model.editor.value.length && /[\w|\s]/.test(model.editor.value.substring(selectionEnd + 1, selectionEnd + 2)))
|| selectionEnd + 1 === model.editor.value.length) {
model.editor.setRangeText(closeChar, selectionEnd + 1, selectionEnd + 1, "preserve");
}
}
Expand Down
39 changes: 39 additions & 0 deletions addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,50 @@ class App extends React.PureComponent {
isInSetup: locationHref.includes("/lightning/setup/"),
contextUrl: locationHref
});
} else if (e.data.clearOlderFlows) {
this.clearOlderFlows(e.data.clearOlderFlows.keep);
return;
}
this.setState({
isFieldsPresent: e.data.isFieldsPresent
});
}
async clearOlderFlows(keep) {
let {contextUrl, setIsLoading} = this.props;
if (!contextUrl) {
return;
}
try {
setIsLoading(true);
let recordId = getRecordId(contextUrl);
const flowSelect = "SELECT id, FlowDefinitionViewId, FlowDefinitionView.ApiName, VersionNumber, FlowDefinitionView.VersionNumber, FlowDefinitionView.LatestVersionId FROM FlowVersionView where DurableId = '" + recordId + "'";
const flowResults = await sfConn.rest("/services/data/v" + apiVersion + "/query/?q=" + flowSelect);
let flowDefinitionViewId;
let keepLatestVersionId;
flowResults.forEach(element => {
element.body.records.forEach(rec => {
flowDefinitionViewId = rec.FlowDefinitionViewId;
keepLatestVersionId = rec.FlowDefinitionView.LatestVersionId - keep;
});
});

const flowToDeleteQuery = "SELECT id FROM FlowVersionView where FlowDefinitionId = " + flowDefinitionViewId + " and VersionNumber < " + keepLatestVersionId;
const flowToDeleteResults = await sfConn.rest("/services/data/v" + apiVersion + "/query/?q=" + flowToDeleteQuery);
let flowToDelete = [];
flowToDeleteResults.forEach(element => {
element.body.records.forEach(rec => {
flowToDelete.push(rec.id);
});
});
//TODO redirect to delete
} catch (err) {
console.error("Unable to find shortcut", err);
return;
} finally {
setIsLoading(false);
}
}

updateReleaseNotesViewed(version) {
localStorage.setItem("latestReleaseNotesVersionViewed", version);
this.setState({
Expand Down

0 comments on commit 10de8bf

Please sign in to comment.