Skip to content

Commit ebcf519

Browse files
committed
history: add tags, rename query and expand full query
1 parent a731fe1 commit ebcf519

File tree

3 files changed

+417
-52
lines changed

3 files changed

+417
-52
lines changed

addon/apex-runner.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class Model {
222222
this.editor.focus();
223223
}
224224
addToHistory() {
225-
this.savedHistory.add({script: this.editor.value, name: this.scriptName});
225+
this.savedHistory.add({script: this.editor.value, name: this.scriptName, tags: []});
226226
}
227227
saveClientId() {
228228
localStorage.setItem(this.sfHost + "_clientId", this.clientId);
@@ -1158,18 +1158,19 @@ class Model {
11581158
}
11591159
getHistory() {
11601160
let historyMap = new Map();
1161-
this.scriptHistory.list.forEach(q => historyMap.set(q.script, {value: q.script, label: q.script.substring(0, 300), favorite: false}));
1161+
this.scriptHistory.list.forEach(q => historyMap.set(q.script, {value: q.script, label: q.script.substring(0, 300), favorite: false, tags: q.tags || []}));
11621162
this.scriptTemplates.forEach(q => historyMap.set(q, {value: q, label: q, favorite: true}));
11631163
this.savedHistory.list.forEach(q => {
11641164
let delimiter = ":";
11651165
let itm;
11661166
if (q.name){
1167-
itm = {value: q.script, label: q.name, favorite: true};
1167+
itm = {value: q.script, label: q.name, name: q.name, favorite: true, tags: q.tags || []};
11681168
} else if (q.script.includes(delimiter)){
1169-
itm = {label: q.script.split(delimiter)[0], favorite: true};
1169+
itm = {label: q.script.split(delimiter)[0], favorite: true, tags: q.tags || []};
1170+
itm.name = itm.label;
11701171
itm.value = q.script.substring(itm.label.length + 1);
11711172
} else {
1172-
itm = {value: q.script, label: q.script, favorite: true};
1173+
itm = {value: q.script, label: q.script, favorite: true, tags: q.tags || []};
11731174
}
11741175
historyMap.set(itm.value, itm);
11751176
});
@@ -1208,13 +1209,22 @@ class Model {
12081209
}
12091210
updateHistoryItem(history) {
12101211
if (history.favorite) {
1211-
let itm = this.scriptHistory.list.find(item => item.script == history.value);
1212+
// For saved scripts (favorites), find and update in savedHistory
1213+
// Match by script value (name might be changing, so don't match by name)
1214+
let itm = this.savedHistory.list.find(item =>
1215+
item.script == history.value
1216+
);
12121217
if (itm) {
1213-
this.scriptHistory.remove(itm);
1218+
// Use tags from history if provided, otherwise preserve existing tags
1219+
const tagsToUse = Array.isArray(history.tags) ? history.tags : (itm.tags || []);
1220+
// Remove old entry
1221+
this.savedHistory.remove(itm);
1222+
// Add updated entry with new name and tags
1223+
let newSaved = {script: history.value, name: history.name, tags: tagsToUse};
1224+
this.savedHistory.add(newSaved);
12141225
}
1215-
let newSaved = {script: history.value};
1216-
this.savedHistory.add(newSaved);
12171226
} else {
1227+
// For regular history items, check if they're in savedHistory first
12181228
let itm = this.savedHistory.list.find(item => (item.script == history.value && item.name && item.name == history.label) || (item.script == history.label + ":" + history.value) || (item.script == history.value && item.script == history.label));
12191229
if (itm) {
12201230
this.savedHistory.remove(itm);
@@ -1225,10 +1235,18 @@ class Model {
12251235
localStorage.setItem("scriptTemplates", JSON.stringify(this.scriptTemplates));
12261236
}
12271237
}
1238+
// Find existing history item to preserve tags
1239+
let existingHistory = this.scriptHistory.list.find(item => item.script == history.value);
12281240
let newHistory = {script: history.value};
12291241
if (itm && itm.name) {
12301242
newHistory.name = itm.name;
12311243
}
1244+
// Preserve tags from history object or existing history item
1245+
if (Array.isArray(history.tags) && history.tags.length > 0) {
1246+
newHistory.tags = history.tags;
1247+
} else if (existingHistory && existingHistory.tags) {
1248+
newHistory.tags = existingHistory.tags;
1249+
}
12321250
this.scriptHistory.add(newHistory);
12331251
}
12341252
}

addon/data-export.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class Model {
258258
this.savedHistory.clear();
259259
}
260260
addToHistory() {
261-
this.savedHistory.add({query: this.editor.value, name: this.queryName, useToolingApi: this.queryTooling});
261+
this.savedHistory.add({query: this.editor.value, name: this.queryName, useToolingApi: this.queryTooling, tags: []});
262262
}
263263
removeFromHistory() {
264264
this.savedHistory.remove({query: this.editor.value, name: this.queryName, useToolingApi: this.queryTooling});
@@ -2071,19 +2071,19 @@ class Model {
20712071
//TODO query: this.editor.value, name: this.queryName, useToolingApi: this.queryTooling
20722072
getHistory() {
20732073
let historyMap = new Map();
2074-
this.queryHistory.list.forEach(q => historyMap.set(q.query, {value: q.query, label: q.query.substring(0, 300), favorite: false, useToolingApi: q.useToolingApi}));
2074+
this.queryHistory.list.forEach(q => historyMap.set(q.query, {value: q.query, label: q.query.substring(0, 300), favorite: false, useToolingApi: q.useToolingApi, tags: q.tags || []}));
20752075
this.queryTemplates.forEach(q => historyMap.set(q, {value: q, label: q, favorite: true, useToolingApi: false}));
20762076
this.savedHistory.list.forEach(q => {
20772077
let delimiter = ":";
20782078
let itm;
20792079
if (q.name){
2080-
itm = {value: q.query, label: q.name, name: q.name, favorite: true, useToolingApi: q.useToolingApi};
2080+
itm = {value: q.query, label: q.name, name: q.name, favorite: true, useToolingApi: q.useToolingApi, tags: q.tags || []};
20812081
} else if (q.query.includes(delimiter)){
2082-
itm = {label: q.query.split(delimiter)[0], favorite: true, useToolingApi: q.useToolingApi};
2082+
itm = {label: q.query.split(delimiter)[0], favorite: true, useToolingApi: q.useToolingApi, tags: q.tags || []};
20832083
itm.name = itm.label;
20842084
itm.value = q.query.substring(itm.label.length + 1);
20852085
} else {
2086-
itm = {value: q.query, label: q.query, favorite: true, useToolingApi: q.useToolingApi};
2086+
itm = {value: q.query, label: q.query, favorite: true, useToolingApi: q.useToolingApi, tags: q.tags || []};
20872087
}
20882088
historyMap.set(itm.value, itm);
20892089
});
@@ -2109,13 +2109,22 @@ class Model {
21092109
}
21102110
updateHistoryItem(history) {
21112111
if (history.favorite) {
2112-
let itm = this.queryHistory.list.find(item => (item.query == history.value) && (item.useToolingApi == history.useToolingApi));
2112+
// For saved queries (favorites), find and update in savedHistory
2113+
// Match by query value and useToolingApi (name might be changing, so don't match by name)
2114+
let itm = this.savedHistory.list.find(item =>
2115+
item.query == history.value && item.useToolingApi == history.useToolingApi
2116+
);
21132117
if (itm) {
2114-
this.queryHistory.remove(itm);
2118+
// Use tags from history if provided, otherwise preserve existing tags
2119+
const tagsToUse = Array.isArray(history.tags) ? history.tags : (itm.tags || []);
2120+
// Remove old entry
2121+
this.savedHistory.remove(itm);
2122+
// Add updated entry with new name and tags
2123+
let newSaved = {query: history.value, useToolingApi: history.useToolingApi ?? false, name: history.name, tags: tagsToUse};
2124+
this.savedHistory.add(newSaved);
21152125
}
2116-
let newSaved = {query: history.value, useToolingApi: history.useToolingApi ?? false};
2117-
this.savedHistory.add(newSaved);
21182126
} else {
2127+
// For regular history items, check if they're in savedHistory first
21192128
let itm = this.savedHistory.list.find(item => (item.useToolingApi == history.useToolingApi && ((item.query == history.value && item.name && item.name == history.label) || (item.query == history.label + ":" + history.value) || (item.query == history.value && item.query == history.label))));
21202129
if (itm) {
21212130
this.savedHistory.remove(itm);
@@ -2126,10 +2135,18 @@ class Model {
21262135
localStorage.setItem("queryTemplates", JSON.stringify(this.queryTemplates));
21272136
}
21282137
}
2138+
// Find existing history item to preserve tags
2139+
let existingHistory = this.queryHistory.list.find(item => item.query == history.value && item.useToolingApi == history.useToolingApi);
21292140
let newHistory = {query: history.value, useToolingApi: history.useToolingApi};
21302141
if (itm && itm.name) {
21312142
newHistory.name = itm.name;
21322143
}
2144+
// Preserve tags from history object or existing history item
2145+
if (Array.isArray(history.tags) && history.tags.length > 0) {
2146+
newHistory.tags = history.tags;
2147+
} else if (existingHistory && existingHistory.tags) {
2148+
newHistory.tags = existingHistory.tags;
2149+
}
21332150
this.queryHistory.add(newHistory);
21342151
}
21352152
}

0 commit comments

Comments
 (0)