<commit_before>import React, { useEffect } from 'react'
import { useQuery } from '@apollo/react-hooks'
import { useSelector } from 'react-redux'
import gql from 'graphql-tag'
import Filters from '../components/Filters'
import Spinner from '../components/Spinner'
import { getActiveLibrary } from '../stores/libraries/selector'

const GET_FILTERS = gql`
  query AllFilters($libraryId: UUID, $multiFilter: String) {
    allLocationTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
      parent {
        id
      }
    }
    allObjectTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allPersonTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allColorTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allStyleTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allCameras(libraryId: $libraryId) {
      id
      make
      model
    }
    allLenses(libraryId: $libraryId) {
      id
      name
    }
    allGenericTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      name
      id
    }
    allApertures(libraryId: $libraryId)
    allExposures(libraryId: $libraryId)
    allIsoSpeeds(libraryId: $libraryId)
    allFocalLengths(libraryId: $libraryId)
    allMeteringModes(libraryId: $libraryId)
    allDriveModes(libraryId: $libraryId)
    allShootingModes(libraryId: $libraryId)
  }
`

function createFilterSelection(sectionName, data, prefix = 'tag') {
  return {
    name: sectionName,
    items: data.map((tag) => {
      let item = {
        id: prefix + ':' + tag,
        name: tag,
      }
      if (tag.toString() === '[object Object]') {
        item.name = tag.name
        item.id = prefix + ':' + tag.id
        item.parent = tag.parent ? prefix + ':' + tag.parent.id : null
      }
      return item
    }),
  }
}

const FiltersContainer = ({ selectedFilters, onFilterToggle }) => {
  const user = useSelector((state) => state.user) // Using user here from Redux store so we can wait for any JWT tokens to be refreshed before running GraphQL queries that require authentication
  const activeLibrary = useSelector(getActiveLibrary)
  let filtersStr = ''
  if (activeLibrary) {
    filtersStr = `${selectedFilters
      .map((filter) => filter.id)
      .join(' ')}`
  }
  
  let variables = {}
  variables = { libraryId: activeLibrary?.id, multiFilter: filtersStr }
  const { loading, error, data, refetch } = useQuery(
    GET_FILTERS,
    {
      variables: variables,
    },
    { skip: !user }
  )
  useEffect(() => {
    refetch()

  }, [activeLibrary, refetch])

  })

  }, [activeLibrary, refetch])
  

  const getFilterdData = (type, array) => {
    const filterArr = selectedFilters.filter(s => s.group === type)
    return array.filter(c => !filterArr.find(rm => (rm.name === c.name)))
  }

  
  if (loading) return <Spinner />
  if (error) return `Error! ${error.message}`
<commit_msg>fix frontend releated issues got while merging other branches<commit_after>import React, { useEffect } from 'react'
import { useQuery } from '@apollo/react-hooks'
import { useSelector } from 'react-redux'
import gql from 'graphql-tag'
import Filters from '../components/Filters'
import Spinner from '../components/Spinner'
import { getActiveLibrary } from '../stores/libraries/selector'

const GET_FILTERS = gql`
  query AllFilters($libraryId: UUID, $multiFilter: String) {
    allLocationTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
      parent {
        id
      }
    }
    allObjectTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allPersonTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allColorTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allStyleTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      id
      name
    }
    allCameras(libraryId: $libraryId) {
      id
      make
      model
    }
    allLenses(libraryId: $libraryId) {
      id
      name
    }
    allGenericTags(libraryId: $libraryId, multiFilter: $multiFilter) {
      name
      id
    }
    allApertures(libraryId: $libraryId)
    allExposures(libraryId: $libraryId)
    allIsoSpeeds(libraryId: $libraryId)
    allFocalLengths(libraryId: $libraryId)
    allMeteringModes(libraryId: $libraryId)
    allDriveModes(libraryId: $libraryId)
    allShootingModes(libraryId: $libraryId)
  }
`

function createFilterSelection(sectionName, data, prefix = 'tag') {
  return {
    name: sectionName,
    items: data.map((tag) => {
      let item = {
        id: prefix + ':' + tag,
        name: tag,
      }
      if (tag.toString() === '[object Object]') {
        item.name = tag.name
        item.id = prefix + ':' + tag.id
        item.parent = tag.parent ? prefix + ':' + tag.parent.id : null
      }
      return item
    }),
  }
}

const FiltersContainer = ({ selectedFilters, onFilterToggle }) => {
  const user = useSelector((state) => state.user) // Using user here from Redux store so we can wait for any JWT tokens to be refreshed before running GraphQL queries that require authentication
  const activeLibrary = useSelector(getActiveLibrary)
  let filtersStr = ''
  if (activeLibrary) {
    filtersStr = `${selectedFilters
      .map((filter) => filter.id)
      .join(' ')}`
  }
  
  let variables = {}
  variables = { libraryId: activeLibrary?.id, multiFilter: filtersStr }
  const { loading, error, data, refetch } = useQuery(
    GET_FILTERS,
    {
      variables: variables,
    },
    { skip: !user }
  )
  useEffect(() => {
    refetch()

  }, [activeLibrary, refetch])

  const getFilterdData = (type, array) => {
    const filterArr = selectedFilters.filter(s => s.group === type)
    return array.filter(c => !filterArr.find(rm => (rm.name === c.name)))
  }

  
  if (loading) return <Spinner />
  if (error) return `Error! ${error.message}`

{'fraction_non_alphanumeric': 0.12360113579422081, 'fraction_numerical': 0.0, 'mean_word_length': 2.8883116883116884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4808002', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1887, 'n_words': 450}