perf(ui): use computed ref when possible
authorJérôme Benoit <jerome.benoit@sap.com>
Sun, 3 Mar 2024 21:15:12 +0000 (22:15 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sun, 3 Mar 2024 21:15:12 +0000 (22:15 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
ui/web/src/components/charging-stations/CSData.vue
ui/web/src/views/ChargingStationsView.vue

index 6a31e20bf862170610e1ab9a05ccf866511149ed..3eab286fbaabb998211e6a7f2a1af6afe488cbda 100644 (file)
@@ -9,7 +9,7 @@
     </td>
     <td class="cs-table__column">{{ getWSState() }}</td>
     <td class="cs-table__column">
-      {{ chargingStation?.bootNotificationResponse?.status ?? 'Ø' }}
+      {{ chargingStation.bootNotificationResponse?.status ?? 'Ø' }}
     </td>
     <td class="cs-table__column">
       {{ chargingStation.stationInfo.templateName }}
index f76e40e6aebaada6540231283cc77bad37896300..2546c6bf6fcf5de18af79086c306ddd68140c3fd 100644 (file)
         :status="state.simulatorState?.started"
         :on="() => startSimulator()"
         :off="() => stopSimulator()"
-        :class="
-          state.simulatorState?.started === true
-            ? 'simulator-stop-button'
-            : 'simulator-start-button'
-        "
+        :class="simulatorButtonClass"
       >
-        {{ state.simulatorState?.started === true ? 'Stop' : 'Start' }} Simulator
-        {{ state.simulatorState?.version != null ? ` (${state.simulatorState?.version})` : '' }}
+        {{ simulatorButtonMessage }}
       </ToggleButton>
       <ToggleButton
         :id="'add-charging-stations'"
 </template>
 
 <script setup lang="ts">
-import { getCurrentInstance, onMounted, ref } from 'vue'
+import { computed, getCurrentInstance, onMounted, ref } from 'vue'
 import { useToast } from 'vue-toast-notification'
 import CSTable from '@/components/charging-stations/CSTable.vue'
 import type { ResponsePayload, SimulatorState, UIServerConfigurationSection } from '@/types'
@@ -150,6 +145,14 @@ const state = ref<{
   uiServerIndex: getFromLocalStorage<number>('uiServerConfigurationIndex', 0)
 })
 
+const simulatorButtonClass = computed<string>(() =>
+  state.value.simulatorState?.started === true ? 'simulator-stop-button' : 'simulator-start-button'
+)
+const simulatorButtonMessage = computed<string>(
+  () =>
+    `${state.value.simulatorState?.started === true ? 'Stop' : 'Start'} Simulator ${state.value.simulatorState?.version != null ? `(${state.value.simulatorState.version})` : ''}`
+)
+
 const app = getCurrentInstance()
 
 const clearToggleButtons = (): void => {