Skip to content

Commit aa36ed1

Browse files
mihaelabalutoiuDany9966
authored andcommitted
Add forceRefresh to schema and options cache to fix
`Reload Options` button `Schema` and `options values` were fetched fresh on reload but the `localStorage` cache was never updated, so subsequent loads still returned stale data. Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
1 parent 3816f73 commit aa36ed1

5 files changed

Lines changed: 51 additions & 8 deletions

File tree

config.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ const conf: Config = {
134134
{
135135
name: "olvm",
136136
types: ["destination"],
137-
requiredFields: ["cluster"]
137+
requiredFields: ["cluster"],
138138
},
139139
{
140140
name: "rhev",
141141
types: ["destination"],
142-
requiredFields: ["cluster"]
143-
}
142+
requiredFields: ["cluster"],
143+
},
144144
],
145145

146146
/*
@@ -202,7 +202,13 @@ const conf: Config = {
202202
hiddenUsers: ["barbican", "coriolis"],
203203

204204
// The list of user roles to hide in the UI
205-
hiddenUserRoles: ["audit", "creator", "observer", "service", "key-manager:service-admin"],
205+
hiddenUserRoles: [
206+
"audit",
207+
"creator",
208+
"observer",
209+
"service",
210+
"key-manager:service-admin",
211+
],
206212

207213
// By default, if a field name contains `password` in it (ex.: `user_password`),
208214
// it will be rendered as a password input

src/components/modules/TransferModule/TransferItemModal/TransferItemModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,10 @@ class TransferItemModal extends React.Component<Props, State> {
483483
try {
484484
await providerStore.loadOptionsSchema({
485485
providerName: endpoint.type,
486-
requiresWindowsImage: this.requiresWindowsImage,
487486
optionsType,
488487
useCache,
488+
forceRefresh: !useCache,
489+
requiresWindowsImage: this.requiresWindowsImage,
489490
});
490491
} catch (err) {
491492
if (optionsType === "destination") {
@@ -500,6 +501,7 @@ class TransferItemModal extends React.Component<Props, State> {
500501
endpointId: endpoint.id,
501502
providerName: endpoint.type,
502503
useCache,
504+
forceRefresh: !useCache,
503505
requiresWindowsImage: this.requiresWindowsImage,
504506
});
505507
}

src/components/smart/WizardPage/WizardPage.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,18 +491,25 @@ class WizardPage extends React.Component<Props, State> {
491491
await providerStore.loadOptionsSchema({
492492
providerName: endpoint.type,
493493
optionsType,
494+
forceRefresh: true,
494495
requiresWindowsImage: this.requiresWindowsImage,
495496
});
496497
const getSchema = () =>
497498
optionsType === "source"
498499
? providerStore.sourceSchema
499500
: providerStore.destinationSchema;
501+
wizardStore.updateData(
502+
optionsType === "source"
503+
? { sourceOptions: undefined }
504+
: { destOptions: undefined },
505+
);
500506
wizardStore.fillWithDefaultValues(optionsType, getSchema());
501507

502508
await providerStore.getOptionsValues({
503509
optionsType,
504510
endpointId: endpoint.id,
505511
providerName: endpoint.type,
512+
forceRefresh: true,
506513
requiresWindowsImage: this.requiresWindowsImage,
507514
});
508515
wizardStore.fillWithDefaultValues(optionsType, getSchema());

src/sources/ProviderSource.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ class ProviderSource {
4242
providerName: ProviderTypes;
4343
optionsType: "source" | "destination";
4444
useCache?: boolean | null;
45+
forceRefresh?: boolean;
4546
quietError?: boolean | null;
4647
requiresWindowsImage?: boolean;
4748
}): Promise<Field[]> {
4849
const {
4950
providerName,
5051
optionsType,
5152
useCache,
53+
forceRefresh,
5254
quietError,
5355
requiresWindowsImage,
5456
} = opts;
@@ -57,9 +59,15 @@ class ProviderSource {
5759
? providerTypes.SOURCE_TRANSFER
5860
: providerTypes.TARGET_TRANSFER;
5961

62+
const url = `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/providers/${providerName}/schemas/${schemaTypeInt}`;
63+
64+
if (forceRefresh) {
65+
Api.removeFromCache(url);
66+
}
67+
6068
try {
6169
const response = await Api.send({
62-
url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/providers/${providerName}/schemas/${schemaTypeInt}`,
70+
url,
6371
cache: useCache,
6472
quietError,
6573
});
@@ -88,9 +96,17 @@ class ProviderSource {
8896
endpointId: string;
8997
envData: { [prop: string]: any } | null | undefined;
9098
cache?: boolean | null;
99+
forceRefresh?: boolean;
91100
quietError?: boolean;
92101
}): Promise<OptionValues[]> {
93-
const { optionsType, endpointId, envData, cache, quietError } = opts;
102+
const {
103+
optionsType,
104+
endpointId,
105+
envData,
106+
cache,
107+
forceRefresh,
108+
quietError,
109+
} = opts;
94110
let envString = "";
95111
if (envData) {
96112
envString = `?env=${DomUtils.encodeToBase64Url(envData)}`;
@@ -100,8 +116,14 @@ class ProviderSource {
100116
const fieldName =
101117
optionsType === "source" ? "source_options" : "destination_options";
102118

119+
const url = `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/endpoints/${endpointId}/${callName}${envString}`;
120+
121+
if (forceRefresh) {
122+
Api.removeFromCache(url);
123+
}
124+
103125
const response = await Api.send({
104-
url: `${configLoader.config.servicesUrls.coriolis}/${Api.projectId}/endpoints/${endpointId}/${callName}${envString}`,
126+
url,
105127
cache,
106128
cancelId: endpointId,
107129
quietError,

src/stores/ProviderStore.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,15 @@ class ProviderStore {
236236
providerName: ProviderTypes;
237237
optionsType: "source" | "destination";
238238
useCache?: boolean;
239+
forceRefresh?: boolean;
239240
quietError?: boolean;
240241
requiresWindowsImage?: boolean;
241242
}): Promise<Field[]> {
242243
const {
243244
providerName,
244245
optionsType,
245246
useCache,
247+
forceRefresh,
246248
quietError,
247249
requiresWindowsImage,
248250
} = options;
@@ -272,6 +274,7 @@ class ProviderStore {
272274
providerName,
273275
optionsType,
274276
useCache,
277+
forceRefresh,
275278
quietError,
276279
requiresWindowsImage,
277280
});
@@ -330,6 +333,7 @@ class ProviderStore {
330333
requiresWindowsImage?: boolean;
331334
envData?: { [prop: string]: any } | null;
332335
useCache?: boolean;
336+
forceRefresh?: boolean;
333337
quietError?: boolean;
334338
allowMultiple?: boolean;
335339
}): Promise<OptionValues[]> {
@@ -339,6 +343,7 @@ class ProviderStore {
339343
endpointId,
340344
envData,
341345
useCache,
346+
forceRefresh,
342347
quietError,
343348
allowMultiple,
344349
requiresWindowsImage,
@@ -386,6 +391,7 @@ class ProviderStore {
386391
endpointId,
387392
envData,
388393
cache: useCache,
394+
forceRefresh,
389395
quietError,
390396
});
391397
this.getOptionsValuesSuccess({

0 commit comments

Comments
 (0)