How to use the xadmin.use function in xadmin

To help you get started, we’ve selected a few xadmin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sshwsfc / xadmin / packages / xadmin-antd / src / model / components / Pages.js View on Github external
const renderActions = () => {
    const { canEdit } = use('model.permission')
    const { onEdit } = use('model.event')

    return (<>
      
      { canEdit ?
        (<button type="primary">onEdit(params &amp;&amp; params.id)}&gt; {_t('Edit')}</button>) : null
      }
    )
  }
github sshwsfc / xadmin / packages / xadmin-antd / src / model / components / Items.js View on Github external
const ItemEditForm = props =&gt; {
  const { item, field, schema, model, onClose, saveItem } = use('model.save', props)

  const formField = _.find(model.form || [], obj =&gt; obj &amp;&amp; obj.key == field ) || { key: field }
  const required = (model.required || []).indexOf(field) &gt;= 0 ? { required: [ field ] } : {}

  return (
github sshwsfc / xadmin / packages / xadmin-antd / src / model / components / SubMenu.js View on Github external
const ColsDropdown = props =&gt; {
  const { selected, fields, changeFieldDisplay } = use('model.fields', props)

  let items = []
  const showFields = Object.keys(fields).filter(name =&gt; fields[name].showInList !== false)
  const menuShow = showFields.length &lt;= 10

  for (let name of showFields) {
    let field = fields[name]
      , fieldName = name
      , title = field.title || name
      , fieldSelected = _.indexOf(selected, name) !== -1
      , onClick = (e) =&gt; {
        changeFieldDisplay([ fieldName, e.target.checked ])
      }, onClickBtn = () =&gt; {
        changeFieldDisplay([ fieldName, !fieldSelected ])
      }
    if(menuShow) {
github sshwsfc / xadmin / packages / xadmin-antd / src / model / components / Items.js View on Github external
const useList = render =&gt; props =&gt; {
  const state = use('model.list', use('model', props))
  const { loading, items, model } = state
  const list = render(state)

  if(loading) {
    return {items.length &gt; 0 ? list : null}
  } else {
    if(items.length &gt; 0) {
      return list
    } else {
      const EmptyComponent = model.components &amp;&amp; model.components.DataEmpty
      if(EmptyComponent) {
        return 
      } else {
        return 
      }
    }
github sshwsfc / xadmin / packages / xadmin-antd / src / model / components / ChildrenModel.js View on Github external
const AddChildrenModelBtn = props =&gt; {
  const [ show, setShow ] = React.useState(false)
  const { model, getItems } = use('model.getItems')
  const { canAdd } = use('model.permission')
  const { refData, refreshTimeout } = props

  const onSuccess = () =&gt; {
    if(refreshTimeout) {
      setTimeout(getItems, refreshTimeout)
    } else {
      getItems()
    }
  }

  return canAdd ? [
    <button style="{{"> setShow(true)}&gt;{_t('Add {{object}}', { object: model.title })}</button>,
     setShow(false)} /&gt;
  ] : null
}
github sshwsfc / xadmin / packages / xadmin-model / src / relate.js View on Github external
const Checkboxes = props =&gt; {
  const { input: { value, onChange }, field, loading, options } = use('model.relate.select', props)

  const onCheckChange = React.useCallback((checked, option) =&gt; {
    if(checked) {
      onChange([ ...value, option ])
    } else {
      onChange(value.filter(item =&gt; item.id != option.id))
    }
  }, [ value, onChange ])

  const renderOptions = () =&gt; {
    const checkedIds = value ? value.map(item =&gt; item.id) : []

    return options.map(({ value, label, item })=&gt;{
      const checked = checkedIds.indexOf(value) &gt;= 0
      return {onCheckChange(!checked, item)}} checked={checked} {...field.attrs} &gt;{label}
    })
github sshwsfc / xadmin / packages / xadmin-model / src / hooks.js View on Github external
'model.item': props => {
    return {
      ...props,
      ...use('model.get', props),
      ...use('model.save', props),
      ...use('model.delete', props)
    }
  },
  'model.query': props => {
github sshwsfc / xadmin / packages / xadmin-model / src / modalform.js View on Github external
const AddModelBtn = () =&gt; {
  const { model } = use('model')
  const { canAdd } = use('model.permission')
  const { saveItem } = use('model.save')

  const { show, dispatch } = use('redux', state =&gt; ({ show: state.showModalAddForm[model.name] || false }))
  const hideModal = () =&gt; {
    dispatch({ model, type: '@@xadmin-modalform/CLOSE' })
  }

  const onSubmitSuccess = (item) =&gt; {
    hideModal()
    dispatch({ model, type: 'GET_ITEMS' })
  }

  return (canAdd &amp;&amp; show) ? (
github sshwsfc / xadmin / packages / xadmin-antd / src / model / components / ActionBar.js View on Github external
export default props =&gt; {
  const { model } = use('model', props)
  const { count } = use('model.select', props)
  const { renderActions } = use('model.batchActions', props)
  const actions = renderActions({ ...props, model })
  return actions &amp;&amp; actions.length &gt; 0 ? (
    
        { React.Children.toArray(actions) }
      
    )}&gt;
      <button>
        { count &gt; 0 ? _t('{{count}} record selected', { count }) : _t('No data selected')} 
      </button>
    
  ) : null
}