All files / packages/tools/src/store/ToolGroupManager getToolGroupsWithToolName.ts

8.33% Statements 1/12
0% Branches 0/6
0% Functions 0/2
9.09% Lines 1/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36        1x                                                              
import { state } from '../index';
import { IToolGroup } from '../../types';
import { ToolModes } from '../../enums';
 
const MODES = [ToolModes.Active, ToolModes.Passive, ToolModes.Enabled];
 
/**
 * Returns the toolGroups that has the given toolName as active, passive
 * or enabled.
 * @param toolName - The name of the tool
 * @returns An array of tool groups.
 */
function getToolGroupsWithToolName(toolName: string): IToolGroup[] | [] {
  return state.toolGroups.filter(({ toolOptions }) => {
    const toolGroupToolNames = Object.keys(toolOptions);
 
    for (let i = 0; i < toolGroupToolNames.length; i++) {
      if (toolName !== toolGroupToolNames[i]) {
        continue;
      }
 
      /* filter out tools that don't have options */
      if (!toolOptions[toolName]) {
        continue;
      }
 
      if (MODES.includes(toolOptions[toolName].mode)) {
        return true;
      }
    }
    return false;
  });
}
 
export default getToolGroupsWithToolName;