Skip to content

Commit

Permalink
[popup] Detect SObject on listview page (#126)
Browse files Browse the repository at this point in the history
Fix #121
  • Loading branch information
tprouvot authored Jul 19, 2023
2 parents 9bc6b5f + 5af3166 commit c85f265
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Version 1.20

## General

- Update pop-up release note link to github pages
- Detect SObject on listview page [feature 121](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/121) (idea by [Mehdi Cherfaoui](https://github.com/mehdisfdc))

# Version 1.19

## General
Expand Down
39 changes: 29 additions & 10 deletions addon/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ class AllDataBox extends React.PureComponent {
contextUserId: null,
contextOrgId: null,
contextPath: null,
contextSobject: null
};
this.onAspectClick = this.onAspectClick.bind(this);
this.parseContextUrl = this.ensureKnownBrowserContext.bind(this);
Expand Down Expand Up @@ -298,9 +299,11 @@ class AllDataBox extends React.PureComponent {
if (contextUrl) {
let recordId = getRecordId(contextUrl);
let path = getSfPathFromUrl(contextUrl);
let sobject = getSobject(contextUrl);
this.setState({
contextRecordId: recordId,
contextPath: path
contextPath: path,
contextSobject: sobject
});
}
}
Expand Down Expand Up @@ -427,7 +430,7 @@ class AllDataBox extends React.PureComponent {
}

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

return (
Expand All @@ -439,7 +442,7 @@ class AllDataBox extends React.PureComponent {
),

(activeSearchAspect == this.SearchAspectTypes.sobject)
? h(AllDataBoxSObject, { ref: "showAllDataBoxSObject", sfHost, showDetailsSupported, sobjectsList, sobjectsLoading, contextRecordId, linkTarget })
? h(AllDataBoxSObject, { ref: "showAllDataBoxSObject", sfHost, showDetailsSupported, sobjectsList, sobjectsLoading, contextRecordId, contextSobject, linkTarget })
: (activeSearchAspect == this.SearchAspectTypes.users)
? h(AllDataBoxUsers, { ref: "showAllDataBoxUsers", sfHost, linkTarget, contextUserId, contextOrgId, contextPath, setIsLoading: (value) => { this.setIsLoading("usersBox", value); } }, "Users")
: "AllData aspect " + activeSearchAspect + " not implemented"
Expand Down Expand Up @@ -606,22 +609,28 @@ class AllDataBoxSObject extends React.PureComponent {
}

componentDidMount() {
let { contextRecordId } = this.props;
this.updateSelection(contextRecordId);
let { contextRecordId, contextSobject } = this.props;
this.updateSelection(contextRecordId, contextSobject);
}

componentDidUpdate(prevProps) {
let { contextRecordId, sobjectsLoading } = this.props;
let { contextRecordId, sobjectsLoading, contextSobject } = this.props;
if (prevProps.contextRecordId !== contextRecordId) {
this.updateSelection(contextRecordId);
this.updateSelection(contextRecordId, contextSobject);
}
if (prevProps.sobjectsLoading !== sobjectsLoading && !sobjectsLoading) {
this.updateSelection(contextRecordId);
this.updateSelection(contextRecordId, contextSobject);
}
}

async updateSelection(query) {
let match = this.getBestMatch(query);
async updateSelection(query, contextSobject) {
let match;
if (query === "list"){
match = this.getBestMatch(contextSobject);
} else {
match = this.getBestMatch(query);
}

await this.setState({ selectedValue: match });
this.loadRecordIdDetails();
}
Expand Down Expand Up @@ -1555,6 +1564,16 @@ function getRecordId(href) {
return null;
}

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;
}
return null;
}

function getSfPathFromUrl(href) {
let url = new URL(href);
if (url.protocol.endsWith("-extension:")) {
Expand Down

0 comments on commit c85f265

Please sign in to comment.