use-context-menu.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. key: VersionHistoryContextMenuOptions.copyId,
  31. name: t('workflow.versionHistory.copyId'),
  32. },
  33. ]
  34. }, [isNamedVersion, t])
  35. return {
  36. deleteOperation,
  37. options,
  38. }
  39. }
  40. export default useContextMenu