Skip to content

Commit

Permalink
Automatically request SObject type when data export from an SObject r… (
Browse files Browse the repository at this point in the history
tprouvot#179)

…ecord (tprouvot#45)

---------

Co-authored-by: Thomas Prouvot <[email protected]>
  • Loading branch information
2 people authored and AntoineLeleu-Salesforce committed Jan 4, 2024
1 parent a1f9c0f commit 886f75a
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.22

- Automatically request SObject type for data import and SObject record id for data export [feature 45](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/45) SObject record (#45)) (contribution by [Olivier Dufour](https://github.com/dufoli))
- Add support to Hyperforce China Organizations [PR141](https://github.com/tprouvot/Salesforce-Inspector-reloaded/pull/141) (contribution by [Yaacov Elbaz](https://github.com/yaacov9))

## Version 1.21
Expand Down
3 changes: 3 additions & 0 deletions addon/data-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Model {
Succeeded: true,
Failed: true
};
if (args.has("sobject")) {
this.importType = args.get("sobject");
}
if (localStorage.getItem(sfHost + "_isSandbox") != "true") {
//change background color for production
document.body.classList.add("prod");
Expand Down
4 changes: 2 additions & 2 deletions addon/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ class Model {
if (!objectName) {
return undefined;
}
let query = "select Id from " + objectName;
let query = "SELECT Id FROM " + objectName;
if (this.recordData && this.recordData.Id) {
query += " where Id = '" + this.recordData.Id + "'";
query += " WHERE Id = '" + this.recordData.Id + "'";
}
return this.dataExportUrl(query);
}
Expand Down
66 changes: 51 additions & 15 deletions addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,44 @@ function initLinks({sfHost}){
class App extends React.PureComponent {
constructor(props) {
super(props);
let {sfHost} = this.props;
let hostArg = new URLSearchParams();
hostArg.set("host", sfHost);
this.state = {
isInSetup: false,
contextUrl: null,
apiVersionInput: apiVersion,
isFieldsPresent: false
isFieldsPresent: false,
exportHref: "data-export.html?" + hostArg,
importHref: "data-import.html?" + hostArg,
limitsHref: "limits.html?" + hostArg
};
this.onContextUrlMessage = this.onContextUrlMessage.bind(this);
this.onShortcutKey = this.onShortcutKey.bind(this);
this.onChangeApi = this.onChangeApi.bind(this);
this.onContextRecordChange = this.onContextRecordChange.bind(this);
}
onContextRecordChange(e) {
let {sfHost} = this.props;
let limitsArg = new URLSearchParams();
let exportArg = new URLSearchParams();
let importArg = new URLSearchParams();
exportArg.set("host", sfHost);
importArg.set("host", sfHost);
limitsArg.set("host", sfHost);
if (e.contextSobject) {
let query = "SELECT Id FROM " + e.contextSobject;
if (e.contextRecordId && (e.contextRecordId.length == 15 || e.contextRecordId.length == 18)) {
query += " WHERE Id = '" + e.contextRecordId + "'";
}
exportArg.set("query", query);
importArg.set("sobject", e.contextSobject);
}
this.setState({
exportHref: "data-export.html?" + exportArg,
importHref: "data-import.html?" + importArg,
limitsHref: "limits.html?" + limitsArg
});
}
onContextUrlMessage(e) {
if (e.source == parent && e.data.insextUpdateRecordId) {
Expand Down Expand Up @@ -171,7 +200,7 @@ class App extends React.PureComponent {
inInspector,
addonVersion
} = this.props;
let {isInSetup, contextUrl, apiVersionInput, isFieldsPresent} = this.state;
let {isInSetup, contextUrl, apiVersionInput, exportHref, importHref, limitsHref, isFieldsPresent} = this.state;
let clientId = localStorage.getItem(sfHost + "_clientId");
let hostArg = new URLSearchParams();
hostArg.set("host", sfHost);
Expand All @@ -198,16 +227,16 @@ class App extends React.PureComponent {
)
),
h("div", {className: "main"},
h(AllDataBox, {ref: "showAllDataBox", sfHost, showDetailsSupported: !inLightning && !inInspector, linkTarget, contextUrl, isFieldsPresent}),
h(AllDataBox, {ref: "showAllDataBox", sfHost, showDetailsSupported: !inLightning && !inInspector, linkTarget, contextUrl, onContextRecordChange: this.onContextRecordChange, isFieldsPresent}),
h("div", {className: "slds-p-vertical_x-small slds-p-horizontal_x-small slds-border_bottom"},
h("div", {className: "slds-m-bottom_xx-small"},
h("a", {ref: "dataExportBtn", href: "data-export.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "E"), "xport"))
h("a", {ref: "dataExportBtn", href: exportHref, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "E"), "xport"))
),
h("div", {className: "slds-m-bottom_xx-small"},
h("a", {ref: "dataImportBtn", href: "data-import.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "I"), "mport"))
h("a", {ref: "dataImportBtn", href: importHref, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Data ", h("u", {}, "I"), "mport"))
),
h("div", {},
h("a", {ref: "limitsBtn", href: "limits.html?" + hostArg, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Org ", h("u", {}, "L"), "imits"))
h("a", {ref: "limitsBtn", href: limitsHref, target: linkTarget, className: "page-button slds-button slds-button_neutral"}, h("span", {}, "Org ", h("u", {}, "L"), "imits"))
),
),
h("div", {className: "slds-p-vertical_x-small slds-p-horizontal_x-small"},
Expand Down Expand Up @@ -330,16 +359,18 @@ class AllDataBox extends React.PureComponent {
}

ensureKnownBrowserContext() {
let {contextUrl} = this.props;
let {contextUrl, onContextRecordChange} = this.props;
if (contextUrl) {
let recordId = getRecordId(contextUrl);
let path = getSfPathFromUrl(contextUrl);
let sobject = getSobject(contextUrl);
this.setState({
let context = {
contextRecordId: recordId,
contextPath: path,
contextSobject: sobject
});
};
this.setState(context);
onContextRecordChange(context);
}
}

Expand Down Expand Up @@ -488,7 +519,7 @@ class AllDataBox extends React.PureComponent {

render() {
let {activeSearchAspect, sobjectsLoading, contextRecordId, contextSobject, contextUserId, contextOrgId, contextPath, sobjectsList} = this.state;
let {sfHost, showDetailsSupported, linkTarget, isFieldsPresent} = this.props;
let {sfHost, showDetailsSupported, linkTarget, onContextRecordChange, isFieldsPresent} = this.props;

return (
h("div", {className: "slds-p-top_small slds-p-horizontal_x-small slds-p-bottom_x-small slds-border_bottom" + (this.isLoading() ? " loading " : "")},
Expand All @@ -499,7 +530,7 @@ class AllDataBox extends React.PureComponent {
h("li", {ref: "orgTab", onClick: this.onAspectClick, "data-aspect": this.SearchAspectTypes.org, className: (activeSearchAspect == this.SearchAspectTypes.org) ? "active" : ""}, h("span", {}, "O", h("u", {}, "r"), "g"))
),
(activeSearchAspect == this.SearchAspectTypes.sobject)
? h(AllDataBoxSObject, {ref: "showAllDataBoxSObject", sfHost, showDetailsSupported, sobjectsList, sobjectsLoading, contextRecordId, contextSobject, linkTarget, isFieldsPresent})
? h(AllDataBoxSObject, {ref: "showAllDataBoxSObject", sfHost, showDetailsSupported, sobjectsList, sobjectsLoading, contextRecordId, contextSobject, linkTarget, onContextRecordChange, isFieldsPresent})
: (activeSearchAspect == this.SearchAspectTypes.users)
? h(AllDataBoxUsers, {ref: "showAllDataBoxUsers", sfHost, linkTarget, contextUserId, contextOrgId, contextPath, setIsLoading: (value) => { this.setIsLoading("usersBox", value); }}, "Users")
: (activeSearchAspect == this.SearchAspectTypes.shortcuts)
Expand Down Expand Up @@ -814,8 +845,12 @@ class AllDataBoxSObject extends React.PureComponent {
}

onDataSelect(value) {
let {onContextRecordChange} = this.props;
this.setState({selectedValue: value}, () => {
this.loadRecordIdDetails();
if (value) {
onContextRecordChange({contextSobject: value.sobject.name, contextRecordId: value.recordId});
}
});
}

Expand Down Expand Up @@ -1910,10 +1945,11 @@ function getRecordId(href) {

function getSobject(href) {
let url = new URL(href);
if (url.pathname && url.pathname.endsWith("/list")){
let sobject = url.pathname.substring(0, url.pathname.lastIndexOf("/list"));
sobject = sobject.substring(sobject.lastIndexOf("/") + 1);
return sobject;
if (url.pathname) {
let match = url.pathname.match(/\/lightning\/[r|o]\/([a-zA-Z0-9_]+)\/[a-zA-Z0-9]+/);
if (match) {
return match[1];
}
}
return null;
}
Expand Down

0 comments on commit 886f75a

Please sign in to comment.