@@ -299,7 +299,7 @@ const TechniquesTable = ({
299299 } ) ;
300300 }
301301
302- const filteredTechniques = allTechniques . map ( ( technique ) => {
302+ let filteredTechniques = allTechniques . map ( ( technique ) => {
303303 const updatedTechnique = { ...technique } ;
304304 Object . keys ( updatedTechnique ) . forEach ( ( key ) => {
305305 if ( ! filteredKeys . includes ( updatedTechnique [ key ] ) ) {
@@ -309,9 +309,66 @@ const TechniquesTable = ({
309309 return updatedTechnique ;
310310 } ) ;
311311
312+ if ( searchFilterType === 'risk_score' && filteredKeys && filteredKeys . length > 0 ) {
313+ const storedTechniques = JSON . parse ( localStorage . getItem ( 'techniques' ) ) || [ ] ;
314+
315+ // Get keys from the first object once to create fresh empty entries dynamically
316+ const baseKeys = Object . keys ( filteredTechniques [ 0 ] ) ;
317+ const createEmptyEntry = ( ) =>
318+ baseKeys . reduce ( ( acc , key ) => {
319+ acc [ key ] = '' ;
320+ return acc ;
321+ } , { } ) ;
322+
323+ const updatedTechniques = [ ...filteredTechniques ] ;
324+
325+ filteredKeys . forEach ( name => {
326+ const technique = storedTechniques . find ( t => t . name === name ) ;
327+ if ( ! technique ) return ;
328+
329+ let tactics ;
330+ try {
331+ // If tactics is a JSON string, parse it. Otherwise, assume it's an array.
332+ tactics = typeof technique . tactics === 'string' ? JSON . parse ( technique . tactics ) : technique . tactics ;
333+ } catch ( err ) {
334+ return ;
335+ }
336+
337+ tactics . forEach ( tactic => {
338+ const tacticKey = tactic . toLowerCase ( ) . replace ( / \s + / g, '_' ) ; // normalize key
339+
340+ // Check if tacticKey exists
341+ if ( ! ( tacticKey in updatedTechniques [ 0 ] ) ) {
342+ return ;
343+ }
344+
345+ // Check if this technique.name already exists in any entry's tacticKey to avoid duplicates
346+ const isDuplicate = updatedTechniques . some ( entry => entry [ tacticKey ] === technique . name ) ;
347+ if ( isDuplicate ) {
348+ return ;
349+ }
350+
351+ // Assign to first available object with empty slot
352+ let assigned = false ;
353+ for ( let i = 0 ; i < updatedTechniques . length ; i ++ ) {
354+ if ( ! updatedTechniques [ i ] [ tacticKey ] ) {
355+ updatedTechniques [ i ] [ tacticKey ] = technique . name ;
356+ assigned = true ;
357+ break ;
358+ }
359+ }
360+ // If none available, create new entry
361+ if ( ! assigned ) {
362+ const newEntry = createEmptyEntry ( ) ;
363+ newEntry [ tacticKey ] = technique . name ;
364+ updatedTechniques . push ( newEntry ) ;
365+ }
366+ } ) ;
367+ } ) ;
368+ }
369+
312370 if ( filteredTechniques . length > 0 ) {
313371 const result = consolidateData ( filteredTechniques ) ;
314-
315372 if ( result !== null && result . length > 0 ) {
316373 let index = Object . keys ( result [ 0 ] ) . findIndex ( key => result [ 0 ] [ key ] !== '' ) ;
317374 setFocusedCell ( { row : 0 , col : index } )
0 commit comments