<commit_before>/*
 *
 * ArticleActionsPanel
 *
 */

import React from 'react'
import PropTypes from 'prop-types'
import R from 'ramda'

import { ICON_CMD } from 'config'
import { makeDebugger, THREAD } from 'utils'

import Informer from 'containers/Informer'
import PinOption from './PinOption'
import RefineOption from './RefineOption'
import EditOption from './EditOption'
import DeleteOption from './DeleteOption'

import { Wrapper, Option, OptionIcon, OptionTitle } from './styles'

/* eslint-disable-next-line */
const debug = makeDebugger('c:ArticleActionsPanel:index')

const ArticleActionsPanel = ({
  data,
  communityRaw,
  thread,
  onUndoPin,
  onPin,
  onSetRefined,
  onUnsetRefined,
  onEdit,
  onInform,
  onDelete,
}) => (
  <Wrapper>
    <PinOption
      passport={`${communityRaw}->${thread}.pin`}
      data={data}
      thread={thread}
      onPin={onPin}
      onUndoPin={onUndoPin}
    />
    <RefineOption
      passport={`${communityRaw}->${thread}.refinedtag.set`}
      data={data}
      thread={thread}
      onSetRefined={onSetRefined}
      onUnsetRefined={onUnsetRefined}
    />

    <EditOption
      passport="owner"
      ownerId={data.author.id}
      onEdit={onEdit}
      thread={thread}
    />

    <Informer>
      <Option onClick={onInform}>
        <OptionIcon src={`${ICON_CMD}/flag.svg`} />
        <OptionTitle>举报该内容</OptionTitle>
      </Option>
    </Informer>

    <DeleteOption
      passport="owner"
      ownerId={data.author.id}
      onDelete={onDelete}
    />
  </Wrapper>
)

ArticleActionsPanel.propTypes = {
  data: PropTypes.shape({
    id: PropTypes.string,
    pin: PropTypes.bool,
    author: PropTypes.shape({
      id: PropTypes.string,
    }),
    tags: PropTypes.arrayOf(
      PropTypes.shape({
        id: PropTypes.string,
        title: PropTypes.string,
        color: PropTypes.string,
        raw: PropTypes.string,
      })
    ),
  }).isRequired,
  communityRaw: PropTypes.string.isRequired,
  thread: PropTypes.oneOf(R.values(THREAD)),
  onInform: PropTypes.func,
  onDelete: PropTypes.func,
  onEdit: PropTypes.func,
  onPin: PropTypes.func,
  onUndoPin: PropTypes.func,
  onSetRefined: PropTypes.func,
  onUnsetRefined: PropTypes.func,
}

ArticleActionsPanel.defaultProps = {
  thread: THREAD.POST,
  onInform: debug,
  onDelete: debug,
  onEdit: debug,
  onPin: debug,
  onUndoPin: debug,
  onSetRefined: debug,
  onUnsetRefined: debug,
}

export default React.memo(ArticleActionsPanel)
<commit_msg>fix(article-action-panel): crash when ownerId valid in auth-hoc<commit_after>/*
 *
 * ArticleActionsPanel
 *
 */

import React from 'react'
import PropTypes from 'prop-types'
import R from 'ramda'

import { ICON_CMD } from 'config'
import { makeDebugger, THREAD } from 'utils'

import Informer from 'containers/Informer'
import PinOption from './PinOption'
import RefineOption from './RefineOption'
import EditOption from './EditOption'
import DeleteOption from './DeleteOption'

import { Wrapper, Option, OptionIcon, OptionTitle } from './styles'

/* eslint-disable-next-line */
const debug = makeDebugger('c:ArticleActionsPanel:index')

const ArticleActionsPanel = ({
  data,
  communityRaw,
  thread,
  onUndoPin,
  onPin,
  onSetRefined,
  onUnsetRefined,
  onEdit,
  onInform,
  onDelete,
}) => (
  <Wrapper>
    <PinOption
      passport={`${communityRaw}->${thread}.pin`}
      data={data}
      thread={thread}
      onPin={onPin}
      onUndoPin={onUndoPin}
    />
    <RefineOption
      passport={`${communityRaw}->${thread}.refinedtag.set`}
      data={data}
      thread={thread}
      onSetRefined={onSetRefined}
      onUnsetRefined={onUnsetRefined}
    />

    <EditOption
      passport="owner"
      ownerId={data.author && data.author.id}
      onEdit={onEdit}
      thread={thread}
    />

    <Informer>
      <Option onClick={onInform}>
        <OptionIcon src={`${ICON_CMD}/flag.svg`} />
        <OptionTitle>举报该内容</OptionTitle>
      </Option>
    </Informer>

    <DeleteOption
      passport="owner"
      ownerId={data.author && data.author.id}
      onDelete={onDelete}
    />
  </Wrapper>
)

ArticleActionsPanel.propTypes = {
  data: PropTypes.shape({
    id: PropTypes.string,
    pin: PropTypes.bool,
    author: PropTypes.shape({
      id: PropTypes.string,
    }),
    tags: PropTypes.arrayOf(
      PropTypes.shape({
        id: PropTypes.string,
        title: PropTypes.string,
        color: PropTypes.string,
        raw: PropTypes.string,
      })
    ),
  }).isRequired,
  communityRaw: PropTypes.string.isRequired,
  thread: PropTypes.oneOf(R.values(THREAD)),
  onInform: PropTypes.func,
  onDelete: PropTypes.func,
  onEdit: PropTypes.func,
  onPin: PropTypes.func,
  onUndoPin: PropTypes.func,
  onSetRefined: PropTypes.func,
  onUnsetRefined: PropTypes.func,
}

ArticleActionsPanel.defaultProps = {
  thread: THREAD.POST,
  onInform: debug,
  onDelete: debug,
  onEdit: debug,
  onPin: debug,
  onUndoPin: debug,
  onSetRefined: debug,
  onUnsetRefined: debug,
}

export default React.memo(ArticleActionsPanel)

{'fraction_non_alphanumeric': 0.12962226640159047, 'fraction_numerical': 0.0, 'mean_word_length': 3.2853492333901193, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3298259', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1702, 'n_words': 324}