<commit_before>import React, {useState} from 'react'
import PropTypes from 'prop-types'
import _get from 'lodash/get'
import {intlShape} from 'react-intl'
import EntityDetailApp from 'tocco-entity-detail/src/main'
import {Prompt} from 'react-router'
import styled from 'styled-components'
import {theme, StyledScrollbar, scale} from 'tocco-ui'

import {currentViewPropType} from '../../utils/propTypes'

const EntityDetailAppWrapper = styled.div`
  margin: 0;
  background-color: ${theme.color('paper')};
  padding: 0 0 0 1.5rem;
  overflow-y: auto;
  height: 100%;
  ${StyledScrollbar}

  .StyledRelationsViewWrapper {
    background-color: ${theme.color('paper')};
    position: sticky;
    top: 0;
    z-index: 1;
    padding-bottom: ${scale.space(-0.5)};
    display: flex;
    flex-wrap: wrap;

    & > * {
      margin-top: ${scale.space(-0.5)};
    }
  }
`

const CreateView = props => {
  const {
    currentViewInfo,
    history,
    match,
    intl,
    dispatchEmittedAction
  } = props

  const [touched, setTouched] = useState(false)

  const mode = 'create'

  if (!currentViewInfo) return null

  const {model, reverseRelation, key} = currentViewInfo
  const entityName = model.name

  const isMultiReverseRelation = _get(model, `paths.${reverseRelation}.multi`, false)

  const defaultValues = [
    ...((reverseRelation && key)
      ? [{id: reverseRelation, value: isMultiReverseRelation ? [key] : key}]
      : []
    )
  ]

  const handleEntityCreated = ({id}) => {
    setTouched(false)
    history.push(match.url.replace(/create$/, id))
  }

  const msg = id => intl.formatMessage({id})
  const handleToucheChanged = ({touched}) => setTouched(touched)

  return <EntityDetailAppWrapper>
    <Prompt<commit_msg>fix(admin): set relation default value for create view<commit_after>import React, {useState} from 'react'
import PropTypes from 'prop-types'
import _get from 'lodash/get'
import {intlShape} from 'react-intl'
import EntityDetailApp from 'tocco-entity-detail/src/main'
import {Prompt} from 'react-router'
import styled from 'styled-components'
import {theme, StyledScrollbar, scale} from 'tocco-ui'

import {currentViewPropType} from '../../utils/propTypes'

const EntityDetailAppWrapper = styled.div`
  margin: 0;
  background-color: ${theme.color('paper')};
  padding: 0 0 0 1.5rem;
  overflow-y: auto;
  height: 100%;
  ${StyledScrollbar}

  .StyledRelationsViewWrapper {
    background-color: ${theme.color('paper')};
    position: sticky;
    top: 0;
    z-index: 1;
    padding-bottom: ${scale.space(-0.5)};
    display: flex;
    flex-wrap: wrap;

    & > * {
      margin-top: ${scale.space(-0.5)};
    }
  }
`

const CreateView = props => {
  const {
    currentViewInfo,
    history,
    match,
    intl,
    dispatchEmittedAction
  } = props

  const [touched, setTouched] = useState(false)

  const mode = 'create'

  if (!currentViewInfo) return null
  const {model, reverseRelation, parentKey} = currentViewInfo
  const entityName = model.name

  const isMultiReverseRelation = _get(model, `paths.${reverseRelation}.multi`, false)

  const defaultValues = [
    ...((reverseRelation && parentKey)
      ? [{id: reverseRelation, value: isMultiReverseRelation ? [parentKey] : parentKey}]
      : []
    )
  ]

  const handleEntityCreated = ({id}) => {
    setTouched(false)
    history.push(match.url.replace(/create$/, id))
  }

  const msg = id => intl.formatMessage({id})
  const handleToucheChanged = ({touched}) => setTouched(touched)

  return <EntityDetailAppWrapper>
    <Prompt
{'fraction_non_alphanumeric': 0.13917233560090703, 'fraction_numerical': 0.008503401360544218, 'mean_word_length': 3.6990679094540613, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '4045850', 'n_tokens_mistral': 1224, 'n_tokens_neox': 1160, 'n_words': 274}