use-context-menu.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { useMemo } from 'react'
  2. import { useTranslation } from 'react-i18next'
  3. import { VersionHistoryContextMenuOptions } from '../../../types'
  4. import type { ContextMenuProps } from './index'
  5. const useContextMenu = (props: ContextMenuProps) => {
  6. const {
  7. isNamedVersion,
  8. } = props
  9. const { t } = useTranslation()
  10. const deleteOperation = {
  11. key: VersionHistoryContextMenuOptions.delete,
  12. name: t('common.operation.delete'),
  13. }
  14. const options = useMemo(() => {
  15. return [
  16. {
  17. key: VersionHistoryContextMenuOptions.restore,
  18. name: t('workflow.common.restore'),
  19. },
  20. isNamedVersion
  21. ? {
  22. key: VersionHistoryContextMenuOptions.edit,
  23. name: t('workflow.versionHistory.editVersionInfo'),
  24. }
  25. : {
  26. key: VersionHistoryContextMenuOptions.edit,
  27. name: t('workflow.versionHistory.nameThisVersion'),
  28. },
  29. ]
  30. // eslint-disable-next-line react-hooks/exhaustive-deps
  31. }, [isNamedVersion])
  32. return {
  33. deleteOperation,
  34. options,
  35. }
  36. }
  37. export default useContextMenu