1- /*
2- * SPDX-FileCopyrightText: 2024 Siemens AG
3- *
4- * SPDX-License-Identifier: MIT
5- *
6- * This source code is licensed under the MIT license found in the
7- * LICENSE file in the root directory of this source tree.
8- */
1+ /* * SPDX-FileCopyrightText: 2024 Siemens AG * * SPDX-License-Identifier: MIT * * This source code
2+ is licensed under the MIT license found in the * LICENSE file in the root directory of this source
3+ tree. */
94
105<script setup lang="ts">
116import { ref , computed , onMounted } from " vue" ;
@@ -14,7 +9,14 @@ import DataTableInstance from "./DataTable.vue";
149import AddDevicesModal from " ./AddDevicesModal.vue" ;
1510import { showModal } from " @/helpers/modal" ;
1611import { IxButton , IxChip , IxCategoryFilter , IxContentHeader , IxEmptyState } from " @siemens/ix-vue" ;
17- import { iconAddCircle , iconSuccess , iconMaintenanceWarning , iconError , iconInfo , iconProject } from " @siemens/ix-icons/icons" ;
12+ import {
13+ iconAddCircle ,
14+ iconSuccess ,
15+ iconMaintenanceWarning ,
16+ iconError ,
17+ iconInfo ,
18+ iconProject ,
19+ } from " @siemens/ix-icons/icons" ;
1820import { FilterState , LogicalFilterOperator } from " @siemens/ix" ;
1921import { useDeviceStore } from " @/store/deviceStore" ;
2022import type { Device , DeviceState } from " @/types" ;
@@ -44,7 +46,9 @@ const categories = computed(() => {
4446 const categoryMap = {} as Record <string , { label: string ; options: string [] }>;
4547
4648 keys .forEach ((key ) => {
47- const uniqueValues = Array .from (new Set (devices .map ((device ) => device [key as keyof Device ] ?? " " )));
49+ const uniqueValues = Array .from (
50+ new Set (devices .map ((device ) => device [key as keyof Device ] ?? " " )),
51+ );
4852 const kebabKey = key .replace (/ ([a-z ] )([A-Z ] )/ g , " $1-$2" ).toLowerCase ();
4953 let label = t (` device-details.${kebabKey } ` );
5054 if (label === ` device-details.${kebabKey } ` ) {
@@ -103,9 +107,9 @@ const toggleFilter = (status: string) => {
103107 categoryFilterState .value = wasActive
104108 ? { tokens: [], categories: [] }
105109 : {
106- tokens: [],
107- categories: [{ id: " status" , value: status , operator: LogicalFilterOperator .EQUAL }],
108- };
110+ tokens: [],
111+ categories: [{ id: " status" , value: status , operator: LogicalFilterOperator .EQUAL }],
112+ };
109113};
110114
111115const onCategoryFilterChanged = (event : CustomEvent <FilterState >) => {
@@ -130,55 +134,96 @@ defineExpose({
130134
131135<template >
132136 <IxContentHeader slot =" header" headerTitle =" Devices" >
133- <IxButton ghost class =" add-devices-button" :icon =" iconAddCircle" aria-label =" add device" @click =" addDeviceClick" >
137+ <IxButton
138+ ghost
139+ class =" add-devices-button"
140+ :icon =" iconAddCircle"
141+ aria-label =" add device"
142+ @click =" addDeviceClick"
143+ >
134144 Add device
135145 </IxButton >
136146 </IxContentHeader >
137147
138148 <section class =" devices-page" >
139149 <section class =" device-filter" >
140- <IxCategoryFilter placeholder =" Filter by" class =" category-filter" :filterState =" categoryFilterState"
141- :categories =" categories" @filterChanged =" onCategoryFilterChanged" />
150+ <IxCategoryFilter
151+ placeholder =" Filter by"
152+ class =" category-filter"
153+ :filterState =" categoryFilterState"
154+ :categories =" categories"
155+ @filterChanged =" onCategoryFilterChanged"
156+ />
142157
143158 <section class =" quick-filter" >
144- <IxChip :outline =" selectedStatus !== 'Online'" :icon =" iconSuccess" variant =" success"
145- @click =" () => toggleFilter('Online')" >
159+ <IxChip
160+ :outline =" selectedStatus !== 'Online'"
161+ :icon =" iconSuccess"
162+ variant =" success"
163+ @click =" () => toggleFilter('Online')"
164+ >
146165 {{ deviceState.Online }} online
147166 </IxChip >
148- <IxChip :outline =" selectedStatus !== 'Maintenance'" :icon =" iconMaintenanceWarning" variant =" warning"
149- @click =" () => toggleFilter('Maintenance')" >
167+ <IxChip
168+ :outline =" selectedStatus !== 'Maintenance'"
169+ :icon =" iconMaintenanceWarning"
170+ variant =" warning"
171+ @click =" () => toggleFilter('Maintenance')"
172+ >
150173 {{ deviceState.Maintenance }} maintenance
151174 </IxChip >
152- <IxChip :outline =" selectedStatus !== 'Error'" :icon =" iconError" variant =" alarm"
153- @click =" () => toggleFilter('Error')" >
175+ <IxChip
176+ :outline =" selectedStatus !== 'Error'"
177+ :icon =" iconError"
178+ variant =" alarm"
179+ @click =" () => toggleFilter('Error')"
180+ >
154181 {{ deviceState.Error }} error
155182 </IxChip >
156- <IxChip :outline =" selectedStatus !== 'Offline'" :icon =" iconInfo" variant =" neutral"
157- @click =" () => toggleFilter('Offline')" >
183+ <IxChip
184+ :outline =" selectedStatus !== 'Offline'"
185+ :icon =" iconInfo"
186+ variant =" neutral"
187+ @click =" () => toggleFilter('Offline')"
188+ >
158189 {{ deviceState.Offline }} offline
159190 </IxChip >
160191 </section >
161192 </section >
162193
163194 <template v-if =" deviceStore .devices .length > 0 && filteredDevices .length === 0 " >
164195 <div class =" empty-state-wrapper" >
165- <IxEmptyState :header =" t('device-quick-actions.no-devices-found') !== 'device-quick-actions.no-devices-found'
166- ? t('device-quick-actions.no-devices-found')
167- : 'No devices found'
168- " :sub-header =" t('device-quick-actions.no-devices-found-desc') !==
196+ <IxEmptyState
197+ :header ="
198+ t('device-quick-actions.no-devices-found') !== 'device-quick-actions.no-devices-found'
199+ ? t('device-quick-actions.no-devices-found')
200+ : 'No devices found'
201+ "
202+ :sub-header ="
203+ t('device-quick-actions.no-devices-found-desc') !==
169204 'device-quick-actions.no-devices-found-desc'
170- ? t('device-quick-actions.no-devices-found-desc')
171- : 'Please remove search terms or add a new device'
172- " :icon =" iconProject" :action =" t('reset-filter') !== 'reset-filter' ? t('reset-filter') : 'Reset Filter'"
173- @actionClick =" resetFilters" />
205+ ? t('device-quick-actions.no-devices-found-desc')
206+ : 'Please remove search terms or add a new device'
207+ "
208+ :icon =" iconProject"
209+ :action =" t('reset-filter') !== 'reset-filter' ? t('reset-filter') : 'Reset Filter'"
210+ @actionClick =" resetFilters"
211+ />
174212 </div >
175213 </template >
176214 <template v-else >
177- <DataTableInstance ref =" dataTableRef" :filterText =" ''" :selectedStatus =" selectedStatus" :selectedCategory =" categoryFilterState.categories.reduce((acc: Record<string, string>, cat) => {
178- acc[cat.id] = cat.value;
179- return acc;
180- }, {})
181- " @cell-clicked =" handleCellClicked" />
215+ <DataTableInstance
216+ ref =" dataTableRef"
217+ :filterText =" ''"
218+ :selectedStatus =" selectedStatus"
219+ :selectedCategory ="
220+ categoryFilterState.categories.reduce((acc: Record<string, string>, cat) => {
221+ acc[cat.id] = cat.value;
222+ return acc;
223+ }, {})
224+ "
225+ @cell-clicked =" handleCellClicked"
226+ />
182227 </template >
183228 </section >
184229</template >
0 commit comments