{"size": 1294, "ext": "js", "max_stars_repo_path": "src/app/plugins/kubernetes/components/prometheus/ServiceAccountPicklist.js", "max_stars_repo_name": "rohitkishnan/pf9-ui-plugin", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/app/plugins/kubernetes/components/prometheus/ServiceAccountPicklist.js", "max_issues_repo_name": "rohitkishnan/pf9-ui-plugin", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/app/plugins/kubernetes/components/prometheus/ServiceAccountPicklist.js", "max_forks_repo_name": "rohitkishnan/pf9-ui-plugin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 31.5609756098, "max_line_length": 135, "alphanum_fraction": 0.7318392581}
import React, { forwardRef, useMemo } from 'react'
import Picklist from 'core/components/Picklist'
import { projectAs } from 'utils/fp'
import useDataLoader from 'core/hooks/useDataLoader'
import PropTypes from 'prop-types'
import { serviceAccountActions } from 'k8s/components/prometheus/actions'

// We need to use `forwardRef` as a workaround of an issue with material-ui Tooltip https://github.com/gregnb/mui-datatables/issues/595
const ServiceAccountPicklist = forwardRef(({ loading, clusterId, namespace, ...rest }, ref) => {
  const [services, servicesLoading] = useDataLoader(serviceAccountActions.list, {
    clusterId,
    namespace,
  })
  const options = useMemo(() =>
    projectAs({ label: 'name', value: 'name' }, services),
  [services])

  return <Picklist
    {...rest}
    ref={ref}
    loading={loading || servicesLoading}
    options={options}
  />
})

ServiceAccountPicklist.propTypes = {
  ...Picklist.propTypes,
  name: PropTypes.string,
  label: PropTypes.string,
  clusterId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
  namespace: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
}

ServiceAccountPicklist.defaultProps = {
  ...Picklist.defaultProps,
  name: 'serviceId',
  label: 'Current Service',
}

export default ServiceAccountPicklist
