All Downloads are FREE. Search and download functionalities are using the official Maven repository.

components.form.fields.multiple.CopyRowButton.tsx Maven / Gradle / Ivy

There is a newer version: 0.80.3
Show newest version
import { CopyButton } from 'components/form/fields/multiple';
import { MultipleButtonProps } from 'components/form/fields/multiple/MultipleTableRowActions';
import { copySelectedRows } from 'components/form/fields/utils/multiple-utils';
import { setStepIconTabIndices } from 'components/form/utils/task-utils';
import { useFieldInfo } from 'hooks/field';
import { useTranslation } from 'react-i18next';

const CopyRowButton = ({rows, index, selected, setSelected}: MultipleButtonProps) => {
  const { t }        = useTranslation()
  const { augProps } = useFieldInfo()

  const handleClick = () => {
    const at = index + 1
    const newRows = copySelectedRows(rows, [index], at)
    const newSelected = selected.map(id => id >= at ? id+1 : id) // adjust all ids higher than id
    augProps.setValue(newRows)
    setSelected([...newSelected, ...(selected.includes(at) ? [at] : [])])

    setStepIconTabIndices(1000)
  }

  return 
}

export default CopyRowButton




© 2015 - 2024 Weber Informatics LLC | Privacy Policy