Skip to content

Commit

Permalink
[data-export] Add 'Hide Object Columns' checkbox (#406)
Browse files Browse the repository at this point in the history
## Describe your changes

## Issue ticket number and link
#352

## Checklist before requesting a review
- [x] I have read and understand the [Contributions
section](https://github.com/tprouvot/Salesforce-Inspector-reloaded#contributions)
- [x] Target branch is releaseCandidate and not master
- [x] I have performed a self-review of my code
- [x] I ran the [unit
tests](https://github.com/tprouvot/Salesforce-Inspector-reloaded#unit-tests)
and my PR does not break any tests
- [x] I documented the changes I've made on the
[CHANGES.md](https://github.com/tprouvot/Salesforce-Inspector-reloaded/blob/master/CHANGES.md)
and followed actual conventions
- [x] I added a new section on
[how-to.md](https://github.com/tprouvot/Salesforce-Inspector-reloaded/blob/master/docs/how-to.md)
(optional)

---------

Co-authored-by: Thomas Prouvot <[email protected]>
  • Loading branch information
guillaumeSF and tprouvot authored May 17, 2024
1 parent e5c5f97 commit bb3fb7b
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Add option to customize org favicon [feature 180](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/180)
- Add tooltip to options [feature 399](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/399) (contribution by [Nathan Shulman](https://github.com/nshulman))
- Fixed popup button disappearance at 100%, also changed horizontal orientation to start at left [issue 404](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/404) (contribution by [Nathan Shulman](https://github.com/nshulman))
- Add option to hide object name columns in query results from Data Export page [feature 352](https://github.com/tprouvot/Salesforce-Inspector-reloaded/issues/352) (contribution by [Guillaume Fauritte](https://github.com/guillaumeSF))

## Version 1.23

Expand Down
1 change: 1 addition & 0 deletions addon/data-export.css
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ input[type=search] {
background-size: 1rem;
background-position: 10px 7px;
padding-left: 35px;
margin-right: 10px;
}

input[type=save] {
Expand Down
45 changes: 41 additions & 4 deletions addon/data-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Model {
this.winInnerHeight = 0;
this.queryAll = false;
this.queryTooling = false;
this.prefHideRelations = localStorage.getItem("hideObjectNameColumnsDataExport") == "true"; // default to false
this.autocompleteResults = {sobjectName: "", title: "\u00A0", results: []};
this.autocompleteClick = null;
this.isWorking = false;
Expand Down Expand Up @@ -142,6 +143,14 @@ class Model {
this.exportedData.updateVisibility();
this.updatedExportedData();
}
refreshColumnsVisibility() {
if (this.exportedData == null || this.exportedData.totalSize == 0) {
return;
}
// Recalculate visibility
this.exportedData.updateColumnsVisibility();
this.updatedExportedData();
}
setQueryName(value) {
this.queryName = value;
}
Expand Down Expand Up @@ -951,7 +960,9 @@ function RecordTable(vm) {
row.push(undefined);
}
header[c] = column;
rt.colVisibilities.push(true);
if (typeof record[field] == "object" && record[field] != null && vm.prefHideRelations) {
rt.colVisibilities.push(false);
} else { rt.colVisibilities.push(true); }
}
row[c] = record[field];
if (typeof record[field] == "object" && record[field] != null) {
Expand All @@ -973,7 +984,7 @@ function RecordTable(vm) {
records: [],
table: [],
rowVisibilities: [],
colVisibilities: [true],
colVisibilities: new Array(!vm.prefHideRelations),
countOfVisibleRecords: null,
isTooling: false,
totalSize: -1,
Expand Down Expand Up @@ -1003,15 +1014,29 @@ function RecordTable(vm) {
this.countOfVisibleRecords = countOfVisibleRecords;
vm.exportStatus = "Filtered " + countOfVisibleRecords + " records out of " + rt.records.length + " records";
},
filterColumns(table, colVis) {
let filteredArray = table.map(row => row.filter((_, index) => colVis[index]));
return filteredArray;
},
updateColumnsVisibility() {
let newColVisibilities = [];
for (const [_, el] of rt.table[1].entries()) {
if (typeof el == "object" && el !== null && vm.prefHideRelations){
newColVisibilities.push(false);
} else { newColVisibilities.push(true); }
}
rt.colVisibilities = newColVisibilities;
},
getVisibleTable() {
if (vm.resultsFilter) {
let filteredTable = [];
for (let i = 0; i < rt.table.length; i++) {
if (rt.rowVisibilities[i]) { filteredTable.push(rt.table[i]); }
}
return filteredTable;
if (vm.prefHideRelations) { return rt.filterColumns(filteredTable, rt.colVisibilities); } else { return filteredTable; }

}
return rt.table;
if (vm.prefHideRelations) { return rt.filterColumns(rt.table, rt.colVisibilities); } else { return rt.table; }
}
};
return rt;
Expand All @@ -1024,6 +1049,7 @@ class App extends React.Component {
super(props);
this.onQueryAllChange = this.onQueryAllChange.bind(this);
this.onQueryToolingChange = this.onQueryToolingChange.bind(this);
this.onPrefHideRelationsChange = this.onPrefHideRelationsChange.bind(this);
this.onSelectHistoryEntry = this.onSelectHistoryEntry.bind(this);
this.onSelectQueryTemplate = this.onSelectQueryTemplate.bind(this);
this.onClearHistory = this.onClearHistory.bind(this);
Expand Down Expand Up @@ -1056,6 +1082,12 @@ class App extends React.Component {
model.queryAutocompleteHandler();
model.didUpdate();
}
onPrefHideRelationsChange(e) {
let {model} = this.props;
model.prefHideRelations = e.target.checked;
model.refreshColumnsVisibility();
model.didUpdate();
}
onSelectHistoryEntry(e) {
let {model} = this.props;
model.selectedHistoryEntry = JSON.parse(e.target.value);
Expand Down Expand Up @@ -1357,6 +1389,11 @@ class App extends React.Component {
? h("button", {disabled: !model.canDelete(), onClick: this.onDeleteRecords, title: "Open the 'Data Import' page with preloaded records to delete (< 20k records). 'Id' field needs to be queried", className: "delete-btn"}, "Delete Records") : null,
),
h("input", {placeholder: "Filter Results", type: "search", value: model.resultsFilter, onInput: this.onResultsFilterInput}),
h("label", {title: "With this option, additionnal columns corresponding to Object names are removed from the query results and the exported data. These columns are useful during data import to automatically map objects."},
h("input", {type: "checkbox", checked: model.prefHideRelations, onChange: this.onPrefHideRelationsChange}),
" ",
h("span", {}, "Hide Object Columns")
),
h("span", {className: "result-status flex-right"},
h("span", {}, model.exportStatus),
perf && h("span", {className: "result-info", title: perf.batchStats}, perf.text),
Expand Down
1 change: 1 addition & 0 deletions addon/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class OptionsTabSelector extends React.Component {
{option: Option, props: {type: "toggle", title: "Display Query Execution Time", key: "displayQueryPerformance", default: true}},
{option: Option, props: {type: "toggle", title: "Use SObject context on Data Export ", key: "useSObjectContextOnDataImportLink", default: true}},
{option: Option, props: {type: "toggle", title: "Show 'Delete Records' button ", key: "showDeleteRecordsButton", default: true}},
{option: Option, props: {type: "toggle", title: "Hide additional Object columns by default on Data Export", key: "hideObjectNameColumnsDataExport", default: false}},
{option: Option, props: {type: "toggle", title: "Include formula fields from suggestion", key: "includeFormulaFieldsFromExportAutocomplete", default: true}},
{option: Option, props: {type: "text", title: "Query Templates", key: "queryTemplates", placeholder: "SELECT Id FROM// SELECT Id FROM WHERE//SELECT Id FROM WHERE IN//SELECT Id FROM WHERE LIKE//SELECT Id FROM ORDER BY//SELECT ID FROM MYTEST__c//SELECT ID WHERE"}}
]
Expand Down
6 changes: 6 additions & 0 deletions docs/how-to.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,9 @@ You can exclude formula fields to be included in the autocomplete by disable the
Navigate to [chrome://extensions/shortcut](chrome://extensions/shortcut) and choose dedicated shortcuts for the pages you want.

<img width="660" alt="Use Chrome Shortcuts" src="https://github.com/tprouvot/Salesforce-Inspector-reloaded/assets/35368290/382aea2d-5278-4dfe-89e6-6dcec4c724c9">

## Hide additional columns in query results

After running a query in the "Data Export" page, you can hide additional columns in the query results. These columns represent the name of the objects included in your query. They are useful to automatically map the fields to the correct object in the "Data Import" page. The columns are hidden in the exported files (CSV or Excel) as well. You can set a default value, using the 'Hide additionnal Object Name Columns by default on Data Export' option ("Options" -> "Data Export" tab).

![2024-05-16_17-54-24 (1)](https://github.com/guillaumeSF/Salesforce-Inspector-reloaded/assets/166603639/45fda19b-b426-4b11-91cb-4f0fbc5c47d7)

0 comments on commit bb3fb7b

Please sign in to comment.