Skip to content

Commit

Permalink
rmove double serialization and use only one serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dufoli committed May 28, 2024
1 parent dae66e2 commit 67f6f8d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 19 deletions.
32 changes: 18 additions & 14 deletions addon/data-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class QueryHistory {

add(entry) {
let history = this._get();
let historyIndex = history.findIndex(e => e.query == entry.query && e.useToolingApi == entry.useToolingApi);
let historyIndex = history.findIndex(e => ((e.query == entry.query && (!entry.name || e.name == entry.name)) || e.query == e.name + ":" + e.query) && e.useToolingApi == entry.useToolingApi);
if (historyIndex > -1) {
history.splice(historyIndex, 1);
}
Expand All @@ -42,7 +42,8 @@ class QueryHistory {

remove(entry) {
let history = this._get();
let historyIndex = history.findIndex(e => e.query == entry.query && e.useToolingApi == entry.useToolingApi);
//old and new format
let historyIndex = history.findIndex(e => ((e.query == entry.query && (!entry.name || e.name == entry.name)) || e.query == e.name + ":" + e.query) && e.useToolingApi == entry.useToolingApi);
if (historyIndex > -1) {
history.splice(historyIndex, 1);
}
Expand All @@ -58,7 +59,7 @@ class QueryHistory {
sort(storageKey, history) {
//sort only saved query not history
if (storageKey === "insextSavedQueryHistory") {
history.sort((a, b) => (a.query > b.query) ? 1 : ((b.query > a.query) ? -1 : 0));
history.sort((a, b) => ((a.name ? a.name + a.query : a.query) > (b.name ? b.name + b.query : b.query)) ? 1 : (((b.name ? b.name + b.query : b.query) > (a.name ? a.name + a.query : a.query)) ? -1 : 0));
}
this.list = history;
}
Expand Down Expand Up @@ -249,17 +250,20 @@ class Model {
this.queryHistory.clear();
}
selectSavedEntry() {
let delimiter = ":";
if (this.selectedSavedEntry != null) {
let queryStr = "";
if (this.selectedSavedEntry.query.includes(delimiter)) {
let query = this.selectedSavedEntry.query.split(delimiter);
this.queryName = query[0];
queryStr = this.selectedSavedEntry.query.substring(this.selectedSavedEntry.query.indexOf(delimiter) + 1);
//old format
let delimitermatch = this.selectedSavedEntry.query.match(/:\s*(select|find)[\S\s]*$/i);
if (delimitermatch) {
this.queryName = this.selectedSavedEntry.query.substring(0, delimitermatch.index);
this.editor.value = this.selectedSavedEntry.query.substring(delimitermatch.index + 1);
} else {
queryStr = this.selectedSavedEntry.query;
this.editor.value = this.selectedSavedEntry.query;
if (this.selectedSavedEntry.name) {
this.queryName = this.selectedSavedEntry.name;
} else {
this.queryName = "";
}
}
this.editor.value = queryStr;
this.queryTooling = this.selectedSavedEntry.useToolingApi;
this.editorAutocompleteHandler();
this.selectedSavedEntry = null;
Expand All @@ -269,13 +273,13 @@ class Model {
this.savedHistory.clear();
}
addToHistory() {
this.savedHistory.add({query: this.getQueryToSave(), useToolingApi: this.queryTooling});
this.savedHistory.add({query: this.getQueryToSave(), name: this.queryName, useToolingApi: this.queryTooling});
}
removeFromHistory() {
this.savedHistory.remove({query: this.getQueryToSave(), useToolingApi: this.queryTooling});
this.savedHistory.remove({query: this.getQueryToSave(), name: this.queryName, useToolingApi: this.queryTooling});
}
getQueryToSave() {
return this.queryName != "" ? this.queryName + ":" + this.editor.value : this.editor.value;
return this.editor.value;
}
autocompleteReload() {
this.describeInfo.reloadAll();
Expand Down
24 changes: 19 additions & 5 deletions addon/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,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: QueryTemplatesOption, props: {title: "Query Templates", key: "queryTemplates", placeholder: "SELECT..."}},
{option: QueryTemplatesOption, props: {title: "Saved Query History", key: "insextSavedQueryHistory", node: "query", defaultValue: "{\"useToolingApi\": false}", placeholder: "SELECT..."}}
{option: QueryTemplatesOption, props: {title: "Saved Query History", key: "insextSavedQueryHistory", node: "query", withName: true, defaultValue: "{\"useToolingApi\": false}", placeholder: "SELECT..."}}
]
},
{
Expand Down Expand Up @@ -565,6 +565,7 @@ class QueryTemplatesOption extends React.Component {
this.key = props.storageKey;
this.model = props.model;
this.title = props.title;
this.withName = props.withName;
this.node = props.node;
this.defaultValue = props.defaultValue;
this.placeholder = props.placeholder;
Expand All @@ -582,7 +583,11 @@ class QueryTemplatesOption extends React.Component {
this.addQueryTemplate = this.addQueryTemplate.bind(this);
this.deleteQueryTemplate = this.deleteQueryTemplate.bind(this);
this.onChangeQuery = this.onChangeQuery.bind(this);
this.onChangeName = this.onChangeName.bind(this);
this.state = {query: "", queryTemplates: this.queryTemplates};
if (this.withName) {
this.state.name = "";
}
}
deleteQueryTemplate(i) {
this.queryTemplates.splice(i, 1);
Expand All @@ -596,20 +601,26 @@ class QueryTemplatesOption extends React.Component {
if (this.defaultValue) {
elt = JSON.parse(this.defaultValue);
}
if (this.withName) {
elt.name = this.state.name;
}
elt[this.node] = this.state.query;
this.queryTemplates.push(elt);
} else {
this.queryTemplates.push(this.state.query);
}

this.setState({query: "", queryTemplates: this.queryTemplates});
this.setState({query: "", name: "", queryTemplates: this.queryTemplates});
localStorage.setItem(this.key, JSON.stringify(this.queryTemplates));
this.model.didUpdate();
}

onChangeQuery(e) {
this.setState({query: e.target.value});
}
onChangeName(e) {
this.setState({name: e.target.value});
}

render() {
return h("div", {},
Expand All @@ -619,16 +630,19 @@ class QueryTemplatesOption extends React.Component {
)
),
h("div", {className: "slds-grid slds-p-horizontal_small slds-p-vertical_xx-small"},
h("div", {className: "slds-form-element__control slds-col slds-size_10-of-12"},
h("textarea", {id: "tmplateQuery", className: "slds-input", value: this.state.query, placeholder: this.placeholder, onChange: this.onChangeQuery}),
this.withName ? h("div", {className: "slds-form-element__control slds-col slds-size_3-of-12"},
h("input", {id: "templateQueryName", className: "slds-input", value: this.state.name, placeholder: "Name", onChange: this.onChangeName}),
) : "",
h("div", {className: "slds-form-element__control " + this.withName ? "slds-col slds-size_7-of-12" : "slds-col slds-size_10-of-12"},
h("textarea", {id: "templateQuery", className: "slds-input", value: this.state.query, placeholder: this.placeholder, onChange: this.onChangeQuery}),
),
h("div", {className: "slds-form-element__control slds-col slds-col slds-size_2-of-12 text-align-middle"},
h("button", {onClick: this.addQueryTemplate, title: "Add", className: "slds-button slds-button_brand"}, "Add"),
)
), this.state.queryTemplates.map((l, i) =>
h("div", {key: "link" + i, className: "slds-grid slds-p-horizontal_small slds-p-vertical_xx-small"},
h("div", {className: "slds-col slds-size_10-of-12 text-align-middle"},
h("span", {}, this.node ? l[this.node] : l)
h("span", {}, ((this.withName && l.name) ? l.name + ":" : "") + (this.node ? l[this.node] : l))
),
h("div", {className: "slds-col slds-size_2-of-12 text-align-middle"},
h("button", {onClick: () => this.deleteQueryTemplate(i), title: "Delete", className: "slds-button slds-button_destructive"}, "Delete")
Expand Down

0 comments on commit 67f6f8d

Please sign in to comment.