diff --git a/addon/popup.js b/addon/popup.js index 29f783b1..e00e67be 100644 --- a/addon/popup.js +++ b/addon/popup.js @@ -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 @@ -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"; @@ -1110,15 +1105,9 @@ 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"){ @@ -1126,20 +1115,19 @@ class AllDataBoxShortcut extends React.PureComponent { 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) {