Skip to content

Commit d2b2afd

Browse files
joaomariolagopatrickelectric
authored andcommitted
frontend: Ednpoint(CreationDialog/Card): Fix ref
* Fix reference being directly passed to the edit modal and modifying original object even in cases where user cancel the action
1 parent 4535bd6 commit d2b2afd

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

core/frontend/src/components/autopilot/EndpointCard.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export default Vue.extend({
131131
return {
132132
userFriendlyEndpointType,
133133
show_edit_dialog: false,
134-
updated_endpoint: this.endpoint,
134+
updated_endpoint: { ...this.endpoint },
135135
}
136136
},
137137
computed: {
@@ -167,6 +167,7 @@ export default Vue.extend({
167167
this.updateEndpoint(this.updated_endpoint)
168168
},
169169
openEditDialog(): void {
170+
this.updated_endpoint = { ...this.endpoint }
170171
this.show_edit_dialog = true
171172
},
172173
async updateEndpoint(endpoint: AutopilotEndpoint): Promise<void> {

core/frontend/src/components/autopilot/EndpointCreationDialog.vue

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ import {
104104
isBaudrate, isFilepath, isIpAddress, isNotEmpty, isSocketPort,
105105
} from '@/utils/pattern_validators'
106106
107+
const defaultEndpointValue: AutopilotEndpoint = {
108+
name: 'My endpoint',
109+
owner: 'User',
110+
connection_type: EndpointType.udpin,
111+
place: '0.0.0.0',
112+
argument: 14550,
113+
protected: false,
114+
persistent: true,
115+
enabled: true,
116+
}
117+
107118
export default Vue.extend({
108119
name: 'EndpointCreationDialog',
109120
model: {
@@ -123,16 +134,7 @@ export default Vue.extend({
123134
type: Object as PropType<AutopilotEndpoint>,
124135
required: false,
125136
default() {
126-
return {
127-
name: 'My endpoint',
128-
owner: 'User',
129-
connection_type: EndpointType.udpin,
130-
place: '0.0.0.0',
131-
argument: 14550,
132-
protected: false,
133-
persistent: true,
134-
enabled: true,
135-
}
137+
return defaultEndpointValue
136138
},
137139
},
138140
},
@@ -165,6 +167,22 @@ export default Vue.extend({
165167
connection_type() {
166168
this.form.validate()
167169
},
170+
baseEndpoint: {
171+
deep: true,
172+
immediate: true,
173+
handler(newValue) {
174+
this.edited_endpoint = { ...newValue }
175+
},
176+
},
177+
show: {
178+
deep: true,
179+
immediate: true,
180+
handler(newValue) {
181+
if (newValue && !this.edit) {
182+
this.edited_endpoint = { ...defaultEndpointValue }
183+
}
184+
},
185+
},
168186
},
169187
methods: {
170188
validate_required_field(input: string): (true | string) {

0 commit comments

Comments
 (0)