Skip to content

Commit

Permalink
finish implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tprouvot committed Nov 14, 2024
1 parent 633ea4e commit a03e616
Showing 1 changed file with 23 additions and 35 deletions.
58 changes: 23 additions & 35 deletions addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -1056,13 +1056,11 @@ class AllDataBoxShortcut extends React.PureComponent {
});

let metadataShortcutSearchOptions = localStorage.getItem("metadataShortcutSearchOptions");
let metadataShortcutSearch = false;
//handle previous option which was not detailled by metadata type
let metadataShortcutSearch = localStorage.getItem("metadataShortcutSearch") != "false";
if (metadataShortcutSearchOptions) {
metadataShortcutSearchOptions = JSON.parse(metadataShortcutSearchOptions);
metadataShortcutSearch = metadataShortcutSearchOptions.find(elm => elm.checked == true).checked;
} else {
metadataShortcutSearch = true;
//TODO handle when setting is not available yet
metadataShortcutSearch = metadataShortcutSearchOptions.find(elm => elm.checked == true) != undefined;
}

//search for metadata if user did not disabled it
Expand All @@ -1071,23 +1069,20 @@ class AllDataBoxShortcut extends React.PureComponent {
flows: "SELECT DurableId, LatestVersionId, ApiName, Label, ProcessType FROM FlowDefinitionView WHERE Label LIKE '%" + shortcutSearch + "%' LIMIT 30",
profiles: "SELECT Id, Name, UserLicense.Name FROM Profile WHERE Name LIKE '%" + shortcutSearch + "%' LIMIT 30",
permissionSets: "SELECT Id, Name, Label, Type, LicenseId, License.Name, PermissionSetGroupId FROM PermissionSet WHERE Label LIKE '%" + shortcutSearch + "%' LIMIT 30",
networks: "SELECT Id, Name, Status, UrlPathPrefix FROM Network WHERE Name LIKE '%" + shortcutSearch + "%' LIMIT 50",
networks: "SELECT NetworkId, Network.Name, Network.Status, Network.UrlPathPrefix, SiteId FROM WebStoreNetwork WHERE Network.Name LIKE '%" + shortcutSearch + "%' LIMIT 50",
classes: "SELECT Id, Name, NamespacePrefix, ApiVersion, Status, LengthWithoutComments FROM ApexClass WHERE Name LIKE '%" + shortcutSearch + "%' LIMIT 50"
};
// If metadataShortcutSearchOptions is null, assume all options are checked
const defaultOptions = ["flows", "profiles", "permissionSets", "networks", "classes"].map(name => ({name, checked: true}));
const effectiveOptions = metadataShortcutSearchOptions || defaultOptions;

const compositeRequest = metadataShortcutSearchOptions
.filter(setting => setting.checked)
.map(setting => ({
method: "GET",
url: "/services/data/v" + apiVersion + "/query/?q=" + encodeURIComponent(queries[setting.name]),
referenceId: setting.name + "Select"
}));

const compositeQuery = {
compositeRequest
};
const compositeRequest = effectiveOptions.filter(setting => setting.checked).map(setting => ({
method: "GET",
url: "/services/data/v" + apiVersion + "/query/?q=" + encodeURIComponent(queries[setting.name]),
referenceId: setting.name + "Select"
}));

const searchResult = await sfConn.rest("/services/data/v" + apiVersion + "/composite", {method: "POST", body: compositeQuery});
const searchResult = await sfConn.rest("/services/data/v" + apiVersion + "/composite", {method: "POST", body: {compositeRequest}});
let results = searchResult.compositeResponse.filter((elm) => elm.httpStatusCode == 200 && elm.body.records.length > 0);

let enablePermSetSummary = localStorage.getItem("enablePermSetSummary") === "true";
Expand All @@ -1110,36 +1105,29 @@ class AllDataBoxShortcut extends React.PureComponent {
rec.detail = rec.attributes.type + " • " + rec.Type;
rec.detail += rec.License?.Name != null ? " • " + rec.License?.Name : "";

let psetOrGroupId;
let type;
if (rec.Type === "Group"){
psetOrGroupId = rec.PermissionSetGroupId;
type = "PermSetGroups";
} else {
psetOrGroupId = rec.Id;
type = "PermSets";
}
const isGroup = rec.Type === "Group";
let psetOrGroupId = isGroup ? rec.PermissionSetGroupId : rec.Id;
let type = isGroup ? "PermSetGroups" : "PermSets";
let endLink = enablePermSetSummary ? psetOrGroupId + "/summary" : "page?address=%2F" + psetOrGroupId;
rec.link = "/lightning/setup/" + type + "/" + endLink;
} else if (rec.attributes.type === "ApexClass"){
rec.link = "/lightning/setup/ApexClasses/page?address=%2F" + rec.Id;
rec.label = rec.Name;
rec.name = rec.NamespacePrefix ? rec.NamespacePrefix + "__" + rec.Name : rec.Name;
rec.detail = rec.attributes.type + " • " + rec.ApiVersion + ".0 • " + rec.Status + (rec.NamespacePrefix ? "" : " • Length: " + rec.LengthWithoutComments);
} else if (rec.attributes.type === "WebStoreNetwork"){
rec.link = `/sfsites/picasso/core/config/commeditor.jsp?servlet%2Fnetworks%2Fswitch%3FnetworkId%3D${rec.NetworkId}%26startURL%3D%252FcommunitySetup%252FcwApp.app%2523%252Fc%252Fhome&siteId=${rec.SiteId}&`;
rec.label = rec.Network.Name;
let url = rec.Network.UrlPathPrefix ? " • /" + rec.Network.UrlPathPrefix : "";
rec.name = rec.NetworkId + url;
rec.detail = "Network (" + rec.Network.Status + ") • Builder";
}
/*else if (rec.attributes.type === "Network"){
rec.link = "/sfsites/picasso/core/config/commeditor.jsp?servlet/networks/switch?networkId=" + rec.Id;
rec.label = rec.Name;
let url = rec.UrlPathPrefix ? " • /" + rec.UrlPathPrefix : "";
rec.name = rec.Id + url;
rec.detail = rec.attributes.type + " (" + rec.Status + ") • Builder";
}*/
rec.title = rec.name;
result.push(rec);
});
});
}
//if no result found, add the globzl search link
//if no result found, add the global search link
result.length > 0 ? result : result.push({link: "/one/one.app#" + this.getEncodedGlobalSearch(shortcutSearch), label: '"' + shortcutSearch + '"', detail: "No results found", name: "Use Global Search"});
return result;
} catch (err) {
Expand Down

0 comments on commit a03e616

Please sign in to comment.