{"version":3,"file":"ActionsMenuItem.mjs","sources":["../../../src/lib/elements/ActionsMenuItem/ActionsMenuItem.jsx"],"sourcesContent":["/*\nCopyright 2019 Iguazio Systems Ltd.\n\nLicensed under the Apache License, Version 2.0 (the \"License\") with\nan addition restriction as set forth herein. You may not use this\nfile except in compliance with the License. You may obtain a copy of\nthe License at http://www.apache.org/licenses/LICENSE-2.0.\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied. See the License for the specific language governing\npermissions and limitations under the License.\n\nIn addition, you may not use the software for any purposes that are\nillegal under applicable law, and the grant of the foregoing license\nunder the Apache 2.0 license is conditioned upon your compliance with\nsuch restriction.\n*/\nimport React from 'react'\nimport PropTypes from 'prop-types'\nimport classnames from 'classnames'\nimport { useDispatch, useSelector } from 'react-redux'\n\nimport Tooltip from '../../components/Tooltip/Tooltip'\nimport TextTooltipTemplate from '../../components/TooltipTemplate/TextTooltipTemplate'\n\nimport { performDetailsActionHelper } from '../../utils/common.util'\n\nimport './actionsMenuItem.scss'\n\nconst ActionsMenuItem = ({ dataItem = {}, index, isIconDisplayed, menuItem }) => {\n  const dispatch = useDispatch()\n  const changes = useSelector(store => store.commonDetailsStore.changes)\n\n  const iconClassNames = classnames(\n    'actions-menu__icon',\n    isIconDisplayed && 'actions-menu__icon_visible'\n  )\n  const menuClassNames = classnames(\n    'actions-menu__option',\n    menuItem.className && `actions-menu__option_${menuItem.className}`,\n    menuItem.disabled && 'actions-menu__option_disabled'\n  )\n\n  const handleActionClick = async () => {\n    if (!menuItem.disabled) {\n      if (menuItem.allowLeaveWarning) {\n        const actionCanBePerformed = await performDetailsActionHelper(changes, dispatch)\n\n        if (actionCanBePerformed) {\n          menuItem.onClick(dataItem)\n        }\n      } else {\n        menuItem.onClick(dataItem)\n      }\n    }\n  }\n\n  return (\n    <li\n      data-testid={`actions-menu__option-${index}`}\n      className={menuClassNames}\n      onClick={handleActionClick}\n    >\n      <Tooltip\n        template={<TextTooltipTemplate text={menuItem.tooltip} />}\n        hidden={!menuItem.tooltip}\n        key={menuItem.label}\n      >\n        <span className={iconClassNames}>{menuItem.icon}</span>\n        {menuItem.label}\n      </Tooltip>\n    </li>\n  )\n}\n\nActionsMenuItem.propTypes = {\n  dataItem: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),\n  index: PropTypes.number.isRequired,\n  isIconDisplayed: PropTypes.bool.isRequired,\n  menuItem: PropTypes.object.isRequired\n}\n\nexport default ActionsMenuItem\n"],"names":["ActionsMenuItem","dataItem","index","isIconDisplayed","menuItem","dispatch","useDispatch","changes","useSelector","store","iconClassNames","classnames","menuClassNames","handleActionClick","performDetailsActionHelper","jsx","jsxs","Tooltip","TextTooltipTemplate","PropTypes"],"mappings":";;;;;;;;;AA+BA,MAAMA,IAAkB,CAAC,EAAE,UAAAC,IAAW,CAAA,GAAI,OAAAC,GAAO,iBAAAC,GAAiB,UAAAC,QAAe;AAC/E,QAAMC,IAAWC,EAAA,GACXC,IAAUC,EAAY,CAAAC,MAASA,EAAM,mBAAmB,OAAO,GAE/DC,IAAiBC;AAAA,IACrB;AAAA,IACAR,KAAmB;AAAA,EAAA,GAEfS,IAAiBD;AAAA,IACrB;AAAA,IACAP,EAAS,aAAa,wBAAwBA,EAAS,SAAS;AAAA,IAChEA,EAAS,YAAY;AAAA,EAAA,GAGjBS,IAAoB,YAAY;AACpC,IAAKT,EAAS,aACRA,EAAS,oBACkB,MAAMU,EAA2BP,GAASF,CAAQ,KAG7ED,EAAS,QAAQH,CAAQ,IAG3BG,EAAS,QAAQH,CAAQ;AAAA,EAG/B;AAEA,SACE,gBAAAc;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,eAAa,wBAAwBb,CAAK;AAAA,MAC1C,WAAWU;AAAA,MACX,SAASC;AAAA,MAET,UAAA,gBAAAG;AAAA,QAACC;AAAA,QAAA;AAAA,UACC,UAAU,gBAAAF,EAACG,GAAA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