Skip to content

Commit d44a140

Browse files
committed
[feat] Add Clear Cache functionality in AllDataBox component
- Implemented a method to clear the SObjects List cache and refresh the data. - Added a button in the UI to trigger cache clearing when no matching objects are found. - Updated state management to handle search query and match count in AllDataBoxSObject component. - Enhanced troubleshooting documentation to guide users on clearing the cache from the Objects tab.
1 parent 19693df commit d44a140

3 files changed

Lines changed: 73 additions & 15 deletions

File tree

addon/components/AlertBanner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class AlertBanner extends React.PureComponent {
1515
),
1616
h("h2", {}, bannerText,
1717
h("p", {}, ""),
18-
link.props ? h("a", link.props, link.text) : link.text
18+
link && link.props ? h("a", link.props, link.text) : (link ? link.text : null)
1919
),
2020
onClose && h("div", {className: "slds-notify__close"},
2121
h("button", {className: "slds-button slds-button_icon slds-button_icon-small slds-button_icon-inverse", title: "Close", onClick: onClose},

addon/popup.js

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ class AllDataBox extends React.PureComponent {
957957
contextSobject: null,
958958
};
959959
this.onAspectClick = this.onAspectClick.bind(this);
960+
this.onClearSobjectsCache = this.onClearSobjectsCache.bind(this);
960961
this.parseContextUrl = this.ensureKnownBrowserContext.bind(this);
961962
}
962963

@@ -1119,6 +1120,20 @@ class AllDataBox extends React.PureComponent {
11191120
});
11201121
}
11211122

1123+
async onClearSobjectsCache() {
1124+
const {sfHost} = this.props;
1125+
await DataCache.clearCache(Constants.CACHE_SOBJECTS_LIST, sfHost, true, true);
1126+
this.setState({sobjectsList: null, sobjectsLoading: false}, () => {
1127+
this.loadSobjects();
1128+
});
1129+
if (this.props.showToast) {
1130+
this.props.showToast({
1131+
type: "success",
1132+
bannerText: "SObjects List cache cleared.",
1133+
});
1134+
}
1135+
}
1136+
11221137
render() {
11231138
let {
11241139
activeSearchAspect,
@@ -1234,6 +1249,8 @@ class AllDataBox extends React.PureComponent {
12341249
contextSobject,
12351250
linkTarget,
12361251
onContextRecordChange,
1252+
onClearSobjectsCache: this.onClearSobjectsCache,
1253+
showToast: this.props.showToast,
12371254
isFieldsPresent,
12381255
eventMonitorHref,
12391256
})
@@ -1580,9 +1597,19 @@ class AllDataBoxSObject extends React.PureComponent {
15801597
this.state = {
15811598
selectedValue: null,
15821599
recordIdDetails: null,
1600+
searchQuery: "",
1601+
searchMatchCount: 0,
15831602
};
15841603
this.onDataSelect = this.onDataSelect.bind(this);
15851604
this.getMatches = this.getMatches.bind(this);
1605+
this.onMatchingResultsChange = this.onMatchingResultsChange.bind(this);
1606+
}
1607+
1608+
onMatchingResultsChange(matchingResults, userQuery) {
1609+
this.setState({
1610+
searchQuery: userQuery || "",
1611+
searchMatchCount: matchingResults?.length ?? 0,
1612+
});
15861613
}
15871614

15881615
componentDidMount() {
@@ -1872,14 +1899,18 @@ class AllDataBoxSObject extends React.PureComponent {
18721899
isFieldsPresent,
18731900
eventMonitorHref,
18741901
} = this.props;
1875-
let {selectedValue, recordIdDetails} = this.state;
1902+
let {selectedValue, recordIdDetails, searchQuery, searchMatchCount} = this.state;
1903+
let {onClearSobjectsCache} = this.props;
1904+
const cacheEnabled = isSettingEnabled(Constants.ENABLE_SOBJECTS_LIST_CACHE, true);
1905+
const showClearCacheButton = cacheEnabled && searchQuery.trim().length > 0 && searchMatchCount === 0;
18761906
return h(
18771907
"div",
18781908
{className: "tab-container slds-p-horizontal_x-small"},
18791909
h(AllDataSearch, {
18801910
ref: "allDataSearch",
18811911
sfHost,
18821912
onDataSelect: this.onDataSelect,
1913+
onMatchingResultsChange: this.onMatchingResultsChange,
18831914
sobjectsList,
18841915
getMatches: this.getMatches,
18851916
inputSearchDelay: 0,
@@ -2206,15 +2237,34 @@ class AllDataBoxSObject extends React.PureComponent {
22062237
)
22072238
)
22082239
),
2209-
h(
2210-
"div",
2211-
{className: "slds-text-longform"},
2212-
h(
2213-
"h3",
2214-
{className: "slds-text-body_regular"},
2215-
"No record to display"
2240+
showClearCacheButton
2241+
? h(
2242+
"div",
2243+
{className: "slds-text-longform slds-m-top_small slds-m-bottom_small"},
2244+
h(
2245+
"p",
2246+
{className: "slds-text-body_regular slds-m-bottom_xx-small"},
2247+
"No matching objects found. Clear the cache to refresh the list and include newly created objects."
2248+
),
2249+
h(
2250+
"button",
2251+
{
2252+
className: "slds-button slds-button_neutral",
2253+
onClick: onClearSobjectsCache,
2254+
title: "Clear SObjects List cache and refresh"
2255+
},
2256+
"Clear Cache"
2257+
)
2258+
)
2259+
: h(
2260+
"div",
2261+
{className: "slds-text-longform"},
2262+
h(
2263+
"h3",
2264+
{className: "slds-text-body_regular"},
2265+
"No record to display"
2266+
)
22162267
)
2217-
)
22182268
)
22192269
)
22202270
);
@@ -4420,7 +4470,7 @@ class AllDataSearch extends React.PureComponent {
44204470
}
44214471
getMatchesDelayed(userQuery) {
44224472
let {queryDelayTimer} = this.state;
4423-
let {inputSearchDelay} = this.props;
4473+
let {inputSearchDelay, onMatchingResultsChange} = this.props;
44244474

44254475
if (queryDelayTimer) {
44264476
clearTimeout(queryDelayTimer);
@@ -4429,6 +4479,7 @@ class AllDataSearch extends React.PureComponent {
44294479
let {getMatches} = this.props;
44304480
const matchingResults = await getMatches(userQuery);
44314481
await this.setState({matchingResults});
4482+
onMatchingResultsChange?.(matchingResults, userQuery);
44324483
}, inputSearchDelay);
44334484

44344485
this.setState({queryDelayTimer});

docs/troubleshooting.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,22 @@ The extension caches the SObjects list to improve popup loading performance. Thi
128128

129129
**How to solve it:**
130130

131-
1. **Clear the SObjects List cache** (recommended for immediate results):
131+
1. **Clear the SObjects List cache from the Objects tab** (quickest when cache is enabled):
132+
* Open the extension and go to the "Objects" tab
133+
* Search for your new object name in the search field
134+
* If no results appear, a "Clear Cache" button will be displayed
135+
* Click the button to clear the cache and refresh the list
136+
* Your new object should appear after the refresh
137+
138+
2. **Clear the SObjects List cache from Options** (when the in-tab button is not shown, e.g. cache disabled):
132139
* Open the extension and click the "Options" button
133140
* Navigate to the "Cache" tab
134-
* Find the "SObjects List Cache Duration (hours)" setting
141+
* Find the "SObjects List Cache" setting
135142
* Click the "Clear Cache" button next to it
136143
* A success message will confirm the cache has been cleared
137144

138-
2. **Wait for cache expiration**:
145+
3. **Wait for cache expiration**:
139146
* The cache will automatically expire based on the configured duration (default: 8 hours when "Preload SObjects before popup opens" is enabled, 168 hours / 7 days when disabled)
140147
* After expiration, the extension will fetch fresh data on the next popup open
141148

142-
**Note:** The extension caches SObjects per org. If you switch between orgs, the extension uses the cache for the current org. For more details on cache configuration, see [SObjects List Cache Management](../how-to.md#sobjects-list-cache-management) in the how-to.
149+
**Note:** The "Clear Cache" button in the Objects tab is only displayed when SObjects List cache is enabled (Options > Cache tab) and a search returns no results. The extension caches SObjects per org. If you switch between orgs, the extension uses the cache for the current org. For more details on cache configuration, see [SObjects List Cache Management](../how-to.md#sobjects-list-cache-management) in the how-to.

0 commit comments

Comments
 (0)