Enable models to override their cleanForNew method

Constraints were failing to clone because cleanForNew didn't remove `this.constraint` which casued the save method to attempt to save the existing constraint instead of creating a new constraint.

This enables models to be able to create their own cleanForNew method to remove custom props if necessary.

rancher/dashboard#2341
This commit is contained in:
Cody Jackson 2021-02-18 12:15:29 -07:00
parent 33f6763dcb
commit 9394ea05a4
3 changed files with 17 additions and 2 deletions

View File

@ -1,5 +1,4 @@
<script>
import { cleanForNew } from '@/plugins/steve/normalize';
import CreateEditView from '@/mixins/create-edit-view/impl';
import Loading from '@/components/Loading';
import ResourceYaml from '@/components/ResourceYaml';
@ -136,7 +135,7 @@ export default {
}
if ( realMode === _CLONE || realMode === _STAGE ) {
cleanForNew(model);
model.cleanForNew();
yaml = model.cleanYaml(yaml, realMode);
}
}

View File

@ -1,4 +1,5 @@
import jsyaml from 'js-yaml';
import { cleanForNew } from '@/plugins/steve/normalize';
export const ENFORCEMENT_ACTION_VALUES = {
DENY: 'deny',
@ -23,6 +24,15 @@ export default {
};
},
cleanForNew() {
return () => {
cleanForNew(this);
if (this.constraint) {
delete this.constraint;
}
};
},
saveYaml() {
return (yaml) => {
const parsed = jsyaml.safeLoad(yaml);

View File

@ -1137,6 +1137,12 @@ export default {
};
},
cleanForNew() {
return () => {
cleanForNew(this);
};
},
yamlForSave() {
return (yaml) => {
try {