@@ -7,6 +7,7 @@ import { useAuth } from '~/store/auth';
77
88export type StatusCode = 'all' | 'online' | 'ping-test-failed' | 'offline' | 'online-outdated' ;
99export type AdoptionOption = 'all' | 'adopted' | 'non-adopted' ;
10+ export type ProbeTypeOption = 'all' | 'hardware' | 'software' ;
1011
1112type StatusOption = {
1213 name : string ;
@@ -20,9 +21,10 @@ export interface Filter {
2021 by : string ;
2122 desc : boolean ;
2223 adoption : AdoptionOption ;
24+ probeType : ProbeTypeOption ;
2325}
2426
25- const DEFAULT_FILTER : Filter = { search : '' , status : 'all' , by : 'name' , desc : false , adoption : 'all' } as const ;
27+ const DEFAULT_FILTER : Filter = { search : '' , status : 'all' , by : 'name' , desc : false , adoption : 'all' , probeType : 'all' } as const ;
2628
2729export const SORTABLE_FIELDS : string [ ] = [ 'name' , 'location' , 'tags' ] as const ;
2830
@@ -35,6 +37,8 @@ export const STATUS_MAP: Record<StatusCode, StatusOption> = {
3537} as const ;
3638
3739export const ADOPTION_OPTIONS : string [ ] = [ 'all' , 'adopted' , 'non-adopted' ] as const ;
40+ export const PROBE_TYPE_OPTIONS : string [ ] = [ 'all' , 'hardware' , 'software' ] as const ;
41+ const ADMIN_FILTERS : ( keyof Filter ) [ ] = [ 'adoption' , 'probeType' ] as const ;
3842
3943interface ProbeFiltersOptions {
4044 active ?: MaybeRefOrGetter < boolean > ;
@@ -47,6 +51,7 @@ export const useProbeFilters = ({ active = () => true }: ProbeFiltersOptions = {
4751
4852 const filter = ref < Filter > ( { ...DEFAULT_FILTER } ) ;
4953 const anyFilterApplied = computed ( ( ) => ( Object . keys ( DEFAULT_FILTER ) as Array < keyof Filter > ) . some ( key => filter . value [ key ] !== DEFAULT_FILTER [ key ] ) ) ;
54+ const anyAdminFilterApplied = computed ( ( ) => ADMIN_FILTERS . some ( key => ! isDefault ( key ) ) ) ;
5055
5156 const onSortChange = ( event : DataTableSortEvent ) => {
5257 const { sortField = '' , sortOrder = 1 } = event ;
@@ -78,6 +83,7 @@ export const useProbeFilters = ({ active = () => true }: ProbeFiltersOptions = {
7883 ...filter . value . desc && { desc : 'true' } ,
7984 ...! isDefault ( 'status' ) && { status : filter . value . status } ,
8085 ...auth . isAdmin && ! isDefault ( 'adoption' ) && { adoption : filter . value . adoption } ,
86+ ...auth . isAdmin && ! isDefault ( 'probeType' ) && { type : filter . value . probeType } ,
8187 } ) ;
8288
8389 const onParamChange = ( ) => {
@@ -120,6 +126,9 @@ export const useProbeFilters = ({ active = () => true }: ProbeFiltersOptions = {
120126 ...! ignoredFields . includes ( 'adoption' ) && auth . isAdmin && ! isDefault ( 'adoption' , filter ) && {
121127 userId : filterValue . adoption === 'adopted' ? { _neq : null } : { _eq : null } ,
122128 } ,
129+ ...! ignoredFields . includes ( 'probeType' ) && auth . isAdmin && ! isDefault ( 'probeType' , filter ) && {
130+ hardwareDevice : filterValue . probeType === 'hardware' ? { _neq : null } : { _eq : null } ,
131+ } ,
123132 } ;
124133 } ;
125134
@@ -133,7 +142,8 @@ export const useProbeFilters = ({ active = () => true }: ProbeFiltersOptions = {
133142 ( ) => route . query . desc ,
134143 ( ) => route . query . status ,
135144 ( ) => route . query . adoption ,
136- ] , async ( [ search , by , desc , status , adoption ] ) => {
145+ ( ) => route . query . type ,
146+ ] , async ( [ search , by , desc , status , adoption , probeType ] ) => {
137147 if ( ! toValue ( active ) ) {
138148 return ;
139149 }
@@ -167,12 +177,19 @@ export const useProbeFilters = ({ active = () => true }: ProbeFiltersOptions = {
167177 } else {
168178 filter . value . adoption = DEFAULT_FILTER . adoption ;
169179 }
180+
181+ if ( typeof probeType === 'string' && PROBE_TYPE_OPTIONS . includes ( probeType ) && auth . isAdmin ) {
182+ filter . value . probeType = probeType as ProbeTypeOption ;
183+ } else {
184+ filter . value . probeType = DEFAULT_FILTER . probeType ;
185+ }
170186 } , { immediate : true } ) ;
171187
172188 return {
173189 // state
174190 filter,
175191 anyFilterApplied,
192+ anyAdminFilterApplied,
176193 // handlers
177194 onSortChange,
178195 onFilterChange,
0 commit comments