@@ -134,8 +134,8 @@ export default {
134134 data () {
135135 return {
136136 item: null ,
137- editedEnvironment: {} ,
138- editedSecretEnvironment: {} ,
137+ editedEnvironment: null ,
138+ editedSecretEnvironment: null ,
139139 inventory: null ,
140140 };
141141 },
@@ -185,7 +185,7 @@ export default {
185185 watch: {
186186 editedEnvironment: {
187187 handler (newVal , oldVal ) {
188- if (! this . item || oldVal == null || oldVal === undefined ) {
188+ if (oldVal == null ) {
189189 return ;
190190 }
191191 this .item .environment = JSON .stringify (this .editedEnvironment );
@@ -197,7 +197,7 @@ export default {
197197
198198 editedSecretEnvironment: {
199199 handler (newVal , oldVal ) {
200- if (! this . item || oldVal == null || oldVal === undefined ) {
200+ if (oldVal == null ) {
201201 return ;
202202 }
203203 this .item .secret = JSON .stringify (this .editedSecretEnvironment );
@@ -335,60 +335,17 @@ export default {
335335 }
336336 });
337337
338- // Build default vars; for enum/select try matching default by option.value
339- const defaultVars = {};
340- (this .template .survey_vars || []).forEach ((sv ) => {
341- const dv = sv .default_value ;
342-
343- if (dv === undefined || dv === null || dv === ' ' ) {
344- return ;
345- }
346-
347- if (Array .isArray (sv .values ) && sv .type === ' enum' ) {
348- const match = sv .values .find ((it ) => String (it .value ) === String (dv));
349- if (match) {
350- defaultVars[sv .name ] = match .value ;
351- }
352- return ;
353- }
354-
355- if (Array .isArray (sv .values ) && sv .type === ' select' ) {
356- // normalize to array
357- let arr = dv;
358- if (! Array .isArray (arr)) {
359- if (typeof arr === ' string' ) {
360- try {
361- const parsed = JSON .parse (arr);
362- arr = Array .isArray (parsed) ? parsed : [parsed];
363- } catch (e) {
364- arr = arr === ' ' ? [] : arr .split (' ,' ).map ((s ) => s .trim ());
365- }
366- } else {
367- arr = [arr];
368- }
369- }
370-
371- const mapped = arr .map ((d ) => {
372- const m = sv .values .find ((it ) => String (it .value ) === String (d));
373- return m ? m .value : null ;
374- }).filter ((v ) => v != null );
375-
376- if (mapped .length > 0 ) {
377- defaultVars[sv .name ] = mapped;
378- }
379- return ;
380- }
381-
382- // For other types (str, int, etc): use default value as-is
383- defaultVars[sv .name ] = dv;
384- });
385-
386- // Merge defaults into existing environment (preserves reactivity)
387- Object .keys (defaultVars).forEach ((key ) => {
388- if (this .editedEnvironment [key] === undefined ) {
389- this .$set (this .editedEnvironment , key, defaultVars[key]);
390- }
391- });
338+ const defaultVars = (this .template .survey_vars || [])
339+ .filter ((s ) => s .default_value )
340+ .reduce (
341+ (res , curr ) => ({
342+ ... res,
343+ [curr .name ]: curr .default_value ,
344+ }),
345+ {},
346+ );
347+
348+ this .editedEnvironment = { ... defaultVars, ... this .editedEnvironment };
392349
393350 // Ensure select type variables without values are initialized as empty arrays
394351 (this .template .survey_vars || []).forEach ((surveyVar ) => {
0 commit comments