Skip to content

Commit

Permalink
Rename internal properties and ensure they don't break clone/save
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac committed Jun 14, 2024
1 parent e403a98 commit 3225ac2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 13 additions & 3 deletions shell/models/provisioning.cattle.io.cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export default class ProvCluster extends SteveModel {
* Instance of model extensions utility that we can use for accessing model helpers provided by extensions
*/
get modelExtensions() {
if (!this._modelExtensions) {
this._modelExtensions = new ModelExtensions(this, 'provisioner', (model) => model.machineProvider);
if (!this.__modelExtensions) {
this.__modelExtensions = new ModelExtensions(this, 'provisioner', (model) => model.machineProvider);
}

return this._modelExtensions;
return this.__modelExtensions;
}

/**
Expand All @@ -36,6 +36,16 @@ export default class ProvCluster extends SteveModel {
return this.modelExtensions.modelHelper;
}

// Ensure we remove the properties for the model extension from the model on save
// Otherwise we get a problem when editing a cluster
cleanForSave(data, forNew) {
super.cleanForSave(data, forNew);
delete data.__modelExtensions;
delete data.__modelHelper;

return data;
}

get details() {
const out = [
{
Expand Down
10 changes: 5 additions & 5 deletions shell/utils/model-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface IModel {
$axios: any;
$plugin: any;
t: any;
_modelHelper?: any;
__modelHelper?: any;
annotations: {[key: string]: string};
}

Expand Down Expand Up @@ -51,8 +51,8 @@ export class ModelExtensions {
*/
get modelHelper(): any {
// Use cached helper if set
if (this.model._modelHelper) {
return this.model._modelHelper;
if (this.model.__modelHelper) {
return this.model.__modelHelper;
}

// First ask all of the helpers that have a 'useForModel' function if they should be used
Expand All @@ -64,9 +64,9 @@ export class ModelExtensions {
}

// Cache for next time
this.model._modelHelper = helper ? this.instantiateModelHelper(helper) : undefined;
this.model.__modelHelper = helper ? this.instantiateModelHelper(helper) : undefined;

return this.model._modelHelper;
return this.model.__modelHelper;
}

/**
Expand Down

0 comments on commit 3225ac2

Please sign in to comment.