refactor: cleanup default params in error handlers
[e-mobility-charging-stations-simulator.git] / ui / web / src / components / actions / AddChargingStations.vue
index f3450e1b0d307cfe1f6ad7c0d82e91644e32bace..a95cba2b07a9afdf72cf03a2be97b81def9db712 100644 (file)
@@ -1,15 +1,12 @@
 <template>
-  <h1 id="action">Action</h1>
-  <h2>Add Charging Stations</h2>
+  <h1 id="action">Add Charging Stations</h1>
   <p>Template:</p>
-  <select v-model="state.template">
+  <select :key="state.renderTemplates" v-model="state.template">
     <option disabled value="">Please select a template</option>
     <option
-      v-for="template in app?.appContext.config.globalProperties.$templates"
-      v-show="
-        Array.isArray(app?.appContext.config.globalProperties.$templates) &&
-        app.appContext.config.globalProperties.$templates.length > 0
-      "
+      v-for="template in $templates.value"
+      v-show="Array.isArray($templates.value) && $templates.value.length > 0"
+      :key="template"
     >
       {{ template }}
     </option>
@@ -24,7 +21,7 @@
     placeholder="number of stations"
   />
   <p>Template options overrides:</p>
-  <ul>
+  <ul id="template-options">
     <li>
       Supervision url:
       <input
@@ -72,7 +69,7 @@
     id="action-button"
     @click="
       () => {
-        uiClient
+        $uiClient
           .addChargingStations(state.template, state.numberOfStations, {
             supervisionUrls: state.supervisionUrl.length > 0 ? state.supervisionUrl : undefined,
             autoStart: convertToBoolean(state.autoStart),
 </template>
 
 <script setup lang="ts">
-import { getCurrentInstance, ref } from 'vue'
-import { useToast } from 'vue-toast-notification'
+import { getCurrentInstance, ref, watch } from 'vue'
+
 import Button from '@/components/buttons/Button.vue'
-import { convertToBoolean } from '@/composables'
+import { convertToBoolean, randomUUID } from '@/composables'
 
 const state = ref<{
+  renderTemplates: `${string}-${string}-${string}-${string}-${string}`
   template: string
   numberOfStations: number
   supervisionUrl: string
@@ -112,6 +110,7 @@ const state = ref<{
   ocppStrictCompliance: boolean
   enableStatistics: boolean
 }>({
+  renderTemplates: randomUUID(),
   template: '',
   numberOfStations: 1,
   supervisionUrl: '',
@@ -121,10 +120,9 @@ const state = ref<{
   enableStatistics: false
 })
 
-const app = getCurrentInstance()
-const uiClient = app?.appContext.config.globalProperties.$uiClient
-
-const $toast = useToast()
+watch(getCurrentInstance()!.appContext.config.globalProperties.$templates, () => {
+  state.value.renderTemplates = randomUUID()
+})
 </script>
 
 <style>
@@ -137,4 +135,9 @@ const $toast = useToast()
   width: 90%;
   text-align: left;
 }
+
+#template-options {
+  list-style: circle inside;
+  text-align: left;
+}
 </style>