feat: cache canned responses and agents in IndexedDB
Converts the canned-response and agent API clients to CacheEnabledApiClient subclasses and wires revalidate actions into the corresponding Vuex modules, so settings pages and pickers stop fetching the same lists on every visit. The canned-response search box continues to bypass the cache and hit the network directly, so server-side ordering stays authoritative. Also fixes a pre-existing gap in teams/revalidate: SET_TEAMS merges into a record dict by id and never removes missing entries, so a team deleted server-side would survive a reconnect-driven revalidate. Now matches the get action by emitting CLEAR_TEAMS first. Each affected spec clears its IDB store before every case, since the preflight-throws-on-axios-reject pattern they relied on is going away in the next commit.
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
/* global axios */
|
||||
|
||||
import ApiClient from './ApiClient';
|
||||
import CacheEnabledApiClient from './CacheEnabledApiClient';
|
||||
|
||||
class Agents extends ApiClient {
|
||||
class Agents extends CacheEnabledApiClient {
|
||||
constructor() {
|
||||
super('agents', { accountScoped: true });
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
get cacheModelName() {
|
||||
return 'account_user';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
extractDataFromResponse(response) {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
marshallData(dataToParse) {
|
||||
return { data: dataToParse };
|
||||
}
|
||||
|
||||
bulkInvite({ emails }) {
|
||||
return axios.post(`${this.url}/bulk_create`, {
|
||||
emails,
|
||||
|
||||
@@ -1,15 +1,32 @@
|
||||
/* global axios */
|
||||
|
||||
import ApiClient from './ApiClient';
|
||||
import CacheEnabledApiClient from './CacheEnabledApiClient';
|
||||
|
||||
class CannedResponse extends ApiClient {
|
||||
class CannedResponse extends CacheEnabledApiClient {
|
||||
constructor() {
|
||||
super('canned_responses', { accountScoped: true });
|
||||
}
|
||||
|
||||
get({ searchKey }) {
|
||||
const url = searchKey ? `${this.url}?search=${searchKey}` : this.url;
|
||||
return axios.get(url);
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
get cacheModelName() {
|
||||
return 'canned_response';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
extractDataFromResponse(response) {
|
||||
return response.data;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
marshallData(dataToParse) {
|
||||
return { data: dataToParse };
|
||||
}
|
||||
|
||||
get({ searchKey } = {}) {
|
||||
if (searchKey) {
|
||||
return axios.get(`${this.url}?search=${searchKey}`);
|
||||
}
|
||||
return super.get(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user