From 3225ac2e659577442c94fd27ab030dc12ecec44d Mon Sep 17 00:00:00 2001 From: Neil MacDougall Date: Fri, 14 Jun 2024 16:19:20 +0100 Subject: [PATCH] Rename internal properties and ensure they don't break clone/save --- shell/models/provisioning.cattle.io.cluster.js | 16 +++++++++++++--- shell/utils/model-extensions.ts | 10 +++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/shell/models/provisioning.cattle.io.cluster.js b/shell/models/provisioning.cattle.io.cluster.js index 436ecb5c861..bc61ae1ae5c 100644 --- a/shell/models/provisioning.cattle.io.cluster.js +++ b/shell/models/provisioning.cattle.io.cluster.js @@ -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; } /** @@ -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 = [ { diff --git a/shell/utils/model-extensions.ts b/shell/utils/model-extensions.ts index 25465aa5d91..6a2bbc14b26 100644 --- a/shell/utils/model-extensions.ts +++ b/shell/utils/model-extensions.ts @@ -23,7 +23,7 @@ interface IModel { $axios: any; $plugin: any; t: any; - _modelHelper?: any; + __modelHelper?: any; annotations: {[key: string]: string}; } @@ -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 @@ -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; } /**