@@ -33,11 +33,11 @@ import {
33
33
import { cellGenericFormatter } from './CellGenericFormat'
34
34
import { ModalService } from '../utilities'
35
35
import { useLazyGenericGetRequestQuery , useLazyGenericPostRequestQuery } from 'src/store/api/app'
36
- import { debounce , update } from 'lodash-es'
36
+ import { debounce } from 'lodash-es'
37
37
import { useSearchParams } from 'react-router-dom'
38
38
import CopyToClipboard from 'react-copy-to-clipboard'
39
39
import { setDefaultColumns } from 'src/store/features/app'
40
- import { end } from '@popperjs/core '
40
+ import M365Licenses from 'src/data/M365Licenses '
41
41
42
42
const FilterComponent = ( { filterText, onFilter, onClear, filterlist, onFilterPreset } ) => (
43
43
< >
@@ -277,28 +277,29 @@ export default function CippTable({
277
277
debounceSetGraphFilter ( query )
278
278
return data
279
279
} else if ( filterText . startsWith ( 'Complex:' ) ) {
280
- const conditions = filterText . slice ( 9 ) . split ( ';' )
280
+ // Split conditions by ';' and 'or', and trim spaces
281
+ const conditions = filterText
282
+ . slice ( 9 )
283
+ . split ( / \s * o r \s * | \s * ; \s * / i) // Split by 'or' or ';', case insensitive, with optional spaces
284
+ . map ( ( condition ) => condition . trim ( ) )
281
285
282
- return conditions . reduce ( ( filteredData , condition ) => {
283
- const match = condition . trim ( ) . match ( / ( \w + ) \s * ( e q | n e | l i k e | n o t l i k e | g t | l t ) \s * ( .+ ) / )
286
+ return data . filter ( ( item ) => {
287
+ // Check if any condition is met for the item
288
+ return conditions . some ( ( condition ) => {
289
+ const match = condition . match ( / ( \w + ) \s * ( e q | n e | l i k e | n o t l i k e | g t | l t ) \s * ( .+ ) / )
284
290
285
- if ( ! match ) {
286
- return filteredData // Keep the current filtered data as is
287
- }
291
+ if ( ! match ) return false
288
292
289
- let [ property , operator , value ] = match . slice ( 1 )
290
- value = escapeRegExp ( value ) // Escape special characters
293
+ let [ property , operator , value ] = match . slice ( 1 )
294
+ value = escapeRegExp ( value ) // Escape special characters
291
295
292
- return filteredData . filter ( ( item ) => {
293
- // Find the actual key in the item that matches the property (case insensitive)
294
296
const actualKey = Object . keys ( item ) . find (
295
297
( key ) => key . toLowerCase ( ) === property . toLowerCase ( ) ,
296
298
)
297
299
298
300
if ( ! actualKey ) {
299
- //set the error message so the user understands the key is not found.
300
301
console . error ( `FilterError: Property "${ property } " not found.` )
301
- return false // Keep the item if the property is not found
302
+ return false
302
303
}
303
304
304
305
switch ( operator ) {
@@ -315,17 +316,19 @@ export default function CippTable({
315
316
case 'lt' :
316
317
return parseFloat ( item [ actualKey ] ) < parseFloat ( value )
317
318
default :
318
- return true
319
+ return false // Should not reach here normally
319
320
}
320
321
} )
321
- } , data )
322
+ } )
322
323
} else {
323
324
return data . filter (
324
325
( item ) => JSON . stringify ( item ) . toLowerCase ( ) . indexOf ( filterText . toLowerCase ( ) ) !== - 1 ,
325
326
)
326
327
}
327
328
}
328
329
330
+ // Helper functions like `debounce` and `escapeRegExp` should be defined somewhere in your code
331
+ // For example, a simple escapeRegExp function could be:
329
332
const filteredItems = Array . isArray ( data ) ? filterData ( data , filterText ) : [ ]
330
333
331
334
const applyFilter = ( e ) => {
@@ -630,74 +633,64 @@ export default function CippTable({
630
633
return null
631
634
} )
632
635
633
- var exportData = filteredItems
634
-
635
- var filtered =
636
- Array . isArray ( exportData ) && exportData . length > 0
637
- ? exportData . map ( ( obj ) =>
638
- // eslint-disable-next-line no-sequences
639
- /* keys.reduce((acc, curr) => ((acc[curr] = obj[curr]), acc), {}),*/
640
- keys . reduce ( ( acc , curr ) => {
641
- const key = curr . split ( '/' )
642
- if ( key . length > 1 ) {
643
- let property = obj
644
- for ( let x = 0 ; x < key . length ; x ++ ) {
645
- if (
646
- Object . prototype . hasOwnProperty . call ( property , key [ x ] ) &&
647
- property [ key [ x ] ] !== null
648
- ) {
649
- property = property [ key [ x ] ]
650
- } else {
651
- property = 'n/a'
652
- break
653
- }
654
- }
655
- acc [ curr ] = property
656
- } else {
657
- if ( typeof exportFormatter [ curr ] === 'function' ) {
658
- acc [ curr ] = exportFormatter [ curr ] ( { cell : obj [ curr ] } )
659
- } else {
660
- acc [ curr ] = obj [ curr ]
661
- }
662
- }
663
- return acc
664
- } , { } ) ,
665
- )
666
- : [ ]
636
+ // Define the flatten function
637
+ const flatten = ( obj , prefix = '' ) => {
638
+ return Object . keys ( obj ) . reduce ( ( output , key ) => {
639
+ const newKey = prefix ? `${ prefix } .${ key } ` : key
640
+ const value = obj [ key ] === null ? '' : obj [ key ]
667
641
668
- const flatten = ( obj , prefix ) => {
669
- let output = { }
670
- for ( let k in obj ) {
671
- let val = obj [ k ]
672
- if ( val === null ) {
673
- val = ''
674
- }
675
- const newKey = prefix ? prefix + '.' + k : k
676
- if ( typeof val === 'object' ) {
677
- if ( Array . isArray ( val ) ) {
678
- const { ...arrToObj } = val
679
- const newObj = flatten ( arrToObj , newKey )
680
- output = { ...output , ...newObj }
681
- } else {
682
- const newObj = flatten ( val , newKey )
683
- output = { ...output , ...newObj }
684
- }
642
+ if ( typeof value === 'object' && ! Array . isArray ( value ) ) {
643
+ Object . assign ( output , flatten ( value , newKey ) )
685
644
} else {
686
- output = { ... output , [ newKey ] : val }
645
+ output [ newKey ] = value
687
646
}
688
- }
689
- return output
647
+ return output
648
+ } , { } )
690
649
}
691
- filtered = filtered . map ( ( item ) => flatten ( item ) )
692
650
693
- let dataFlat
651
+ // Define the applyFormatter function
652
+ const applyFormatter = ( obj ) => {
653
+ return Object . keys ( obj ) . reduce ( ( acc , key ) => {
654
+ const formatter = exportFormatter [ key ]
655
+ // Since the keys after flattening will be dot-separated, we need to adjust this to support nested keys if necessary.
656
+ const keyParts = key . split ( '.' )
657
+ const finalKeyPart = keyParts [ keyParts . length - 1 ]
658
+ const formattedValue =
659
+ typeof formatter === 'function' ? formatter ( { cell : obj [ key ] } ) : obj [ key ]
660
+ acc [ key ] = formattedValue
661
+ return acc
662
+ } , { } )
663
+ }
694
664
695
- if ( Array . isArray ( data ) ) {
696
- dataFlat = data . map ( ( item ) => flatten ( item ) )
697
- } else {
698
- dataFlat = [ ]
665
+ // Process exportData function
666
+ const processExportData = ( exportData , selectedColumns ) => {
667
+ //filter out the columns that are not selected via selectedColumns
668
+ exportData = exportData . map ( ( item ) => {
669
+ return Object . keys ( item )
670
+ . filter ( ( key ) => selectedColumns . find ( ( o ) => o . exportSelector === key ) )
671
+ . reduce ( ( obj , key ) => {
672
+ obj [ key ] = item [ key ]
673
+ return obj
674
+ } , { } )
675
+ } )
676
+ return Array . isArray ( exportData ) && exportData . length > 0
677
+ ? exportData . map ( ( obj ) => {
678
+ const flattenedObj = flatten ( obj )
679
+ return applyFormatter ( flattenedObj )
680
+ } )
681
+ : [ ]
699
682
}
700
683
684
+ // Applying the processExportData function to both filteredItems and data
685
+ var filtered = processExportData ( filteredItems , updatedColumns )
686
+
687
+ // Adjusted dataFlat processing to include formatting
688
+ let dataFlat = Array . isArray ( data )
689
+ ? data . map ( ( item ) => {
690
+ const flattenedItem = flatten ( item )
691
+ return applyFormatter ( flattenedItem )
692
+ } )
693
+ : [ ]
701
694
if ( ! disablePDFExport ) {
702
695
if ( dynamicColumns === true ) {
703
696
defaultActions . push ( [
0 commit comments