<commit_before>// @flow
import * as React from 'react'
import * as Types from '../../constants/types/fs'
import * as Constants from '../../constants/fs'
import * as Styles from '../../styles'
import {fileUIName} from '../../constants/platform'
import {
  Box2,
  Box,
  ClickableBox,
  ProgressIndicator,
  Icon,
  Text,
  FloatingMenu,
  iconCastPlatformStyles,
  type OverlayParentProps,
} from '../../common-adapters'
import PathItemIcon from '../common/path-item-icon'
import PathItemInfo from '../common/path-item-info'
import StaticBreadcrumb from '../common/static-breadcrumb'
import {memoize} from 'lodash-es'
import DownloadTrackingHoc from './download-tracking-hoc'

type Props = {
  name: string,
  size: number,
  type: Types.PathType,
  lastModifiedTimestamp: number,
  lastWriter: string,
  childrenFolders: number,
  childrenFiles: number,
  itemStyles: Types.ItemStyles,
  actionIconClassName?: string,
  actionIconFontSize?: number,
  actionIconWhite?: boolean,
  path: Types.Path,
  pathElements: Array<string>,
  // Menu items
  showInFileUI?: () => void,
  ignoreFolder?: () => void,
  saveMedia?: (() => void) | 'disabled',
  shareNative?: (() => void) | 'disabled',
  download?: () => void,
  copyPath?: () => void,
}

const hideMenuOnClick = (onClick: (evt?: SyntheticEvent<>) => void, hideMenu: () => void) => (
  evt?: SyntheticEvent<>
) => {
  onClick(evt)
  hideMenu()
}

const ShareNative = DownloadTrackingHoc(
  ({downloading}) =>
    downloading ? (
      <Box2 direction="horizontal">
        <ProgressIndicator style={styles.progressIndicator} />
        <Text type="BodyBig" style={styles.menuRowTextDisabled}>
          Send to other app
        </Text>
      </Box2>
    ) : (
      <Text type="BodyBig" style={styles.menuRowText}>
        Send to other app
      </Text>
    )
)

const Save = DownloadTrackingHoc(
  ({downloading}) =>
    downloading ? (
      <Box2 direction="horizontal">
        <ProgressIndicator style={styles.progressIndicator} />
        <Text type="BodyBig" style={styles.menuRowTextDisabled}>
          Save
        </Text>
      </Box2>
    ) : (
      <Text type="BodyBig" style={styles.menuRowText}>
        Save
      </Text>
    )
)

const makeMenuItems = (props: Props, hideMenu: () => void) => {
  return [
    ...(props.showInFileUI
      ? [
          {
            title: 'Show in ' + fileUIName,
            onClick: hideMenuOnClick(props.showInFileUI, hideMenu),
          },
        ]
      : []),
    ...(props.ignoreFolder
      ? [
          {
            title: 'Ignore this folder',
            onClick: hideMenuOnClick(props.ignoreFolder, hideMenu),
            subTitle: 'The folder will no longer appear in your folders list.',
            danger: true,
          },
        ]
      : []),
    ...(props.saveMedia
      ? [
          {
            title: 'Save',
            view: <Save trackingPath={props.path} trackingIntent="camera-roll" />,
            onClick: props.saveMedia !== 'disabled' ? hideMenuOnClick(props.saveMedia, hideMenu) : undefined,
            disabled: props.saveMedia === 'disabled',
          },
        ]
      : []),
    ...(props.shareNative
      ? [
          {
            title: 'Send to other app',
            view: (
              <ShareNative
                trackingPath={props.path}
                trackingIntent="share"
                onFinish={hideMenu}
                cancelOnUnmount={true}
              />
            ),
            onClick: props.shareNative !== 'disabled' ? props.shareNative : undefined,
            disabled: props.shareNative === 'disabled',
          },
        ]
      : []),
    ...(props.download
      ? [
          {
            title: 'Download a copy',
            onClick: hideMenuOnClick(props.download, hideMenu),
          },
        ]
      : []),
    ...(props.copyPath
      ? [
          {
            title: 'Copy path',
            onClick: hideMenuOnClick(props.copyPath, hideMenu),<commit_msg>Reorder menu item options to have copy path in between show finder and download a copy (#13498)<commit_after>// @flow
import * as React from 'react'
import * as Types from '../../constants/types/fs'
import * as Constants from '../../constants/fs'
import * as Styles from '../../styles'
import {fileUIName} from '../../constants/platform'
import {
  Box2,
  Box,
  ClickableBox,
  ProgressIndicator,
  Icon,
  Text,
  FloatingMenu,
  iconCastPlatformStyles,
  type OverlayParentProps,
} from '../../common-adapters'
import PathItemIcon from '../common/path-item-icon'
import PathItemInfo from '../common/path-item-info'
import StaticBreadcrumb from '../common/static-breadcrumb'
import {memoize} from 'lodash-es'
import DownloadTrackingHoc from './download-tracking-hoc'

type Props = {
  name: string,
  size: number,
  type: Types.PathType,
  lastModifiedTimestamp: number,
  lastWriter: string,
  childrenFolders: number,
  childrenFiles: number,
  itemStyles: Types.ItemStyles,
  actionIconClassName?: string,
  actionIconFontSize?: number,
  actionIconWhite?: boolean,
  path: Types.Path,
  pathElements: Array<string>,
  // Menu items
  showInFileUI?: () => void,
  ignoreFolder?: () => void,
  saveMedia?: (() => void) | 'disabled',
  shareNative?: (() => void) | 'disabled',
  download?: () => void,
  copyPath?: () => void,
}

const hideMenuOnClick = (onClick: (evt?: SyntheticEvent<>) => void, hideMenu: () => void) => (
  evt?: SyntheticEvent<>
) => {
  onClick(evt)
  hideMenu()
}

const ShareNative = DownloadTrackingHoc(
  ({downloading}) =>
    downloading ? (
      <Box2 direction="horizontal">
        <ProgressIndicator style={styles.progressIndicator} />
        <Text type="BodyBig" style={styles.menuRowTextDisabled}>
          Send to other app
        </Text>
      </Box2>
    ) : (
      <Text type="BodyBig" style={styles.menuRowText}>
        Send to other app
      </Text>
    )
)

const Save = DownloadTrackingHoc(
  ({downloading}) =>
    downloading ? (
      <Box2 direction="horizontal">
        <ProgressIndicator style={styles.progressIndicator} />
        <Text type="BodyBig" style={styles.menuRowTextDisabled}>
          Save
        </Text>
      </Box2>
    ) : (
      <Text type="BodyBig" style={styles.menuRowText}>
        Save
      </Text>
    )
)

const makeMenuItems = (props: Props, hideMenu: () => void) => {
  return [
    ...(props.saveMedia
      ? [
          {
            title: 'Save',
            view: <Save trackingPath={props.path} trackingIntent="camera-roll" />,
            onClick: props.saveMedia !== 'disabled' ? hideMenuOnClick(props.saveMedia, hideMenu) : undefined,
            disabled: props.saveMedia === 'disabled',
          },
        ]
      : []),
    ...(props.shareNative
      ? [
          {
            title: 'Send to other app',
            view: (
              <ShareNative
                trackingPath={props.path}
                trackingIntent="share"
                onFinish={hideMenu}
                cancelOnUnmount={true}
              />
            ),
            onClick: props.shareNative !== 'disabled' ? props.shareNative : undefined,
            disabled: props.shareNative === 'disabled',
          },
        ]
      : []),
    ...(props.showInFileUI
      ? [
          {
            title: 'Show in ' + fileUIName,
            onClick: hideMenuOnClick(props.showInFileUI, hideMenu),
          },
        ]
      : []),
    ...(props.copyPath
      ? [
          {
            title: 'Copy path',
            onClick: hideMenuOnClick(props.copyPath, hideMenu),
          },
        ]
      : []),
    ...(props.download
      ? [
          {
            title: 'Download a copy',
            onClick: hideMenuOnClick(props.download, hideMenu),
          },
        ]
      : []),
    ...(props.ignoreFolder
      ? [
          {
            title: 'Ignore this folder',
            onClick: hideMenuOnClick(props.ignoreFolder, hideMenu),
            subTitle: 'The folder will no longer appear in your folders list.',
            danger: true,
{'fraction_non_alphanumeric': 0.14234031936127745, 'fraction_numerical': 0.0018712574850299401, 'mean_word_length': 2.1402271837054445, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 25, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5612139', 'n_tokens_mistral': 2340, 'n_tokens_neox': 2361, 'n_words': 511}