use-context-menu.ts 1.2 KB

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