Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const renderActions = () => {
const { canEdit } = use('model.permission')
const { onEdit } = use('model.event')
return (<>
{ canEdit ?
(<button type="primary">onEdit(params && params.id)}> {_t('Edit')}</button>) : null
}
)
}
const ItemEditForm = props => {
const { item, field, schema, model, onClose, saveItem } = use('model.save', props)
const formField = _.find(model.form || [], obj => obj && obj.key == field ) || { key: field }
const required = (model.required || []).indexOf(field) >= 0 ? { required: [ field ] } : {}
return (
const ColsDropdown = props => {
const { selected, fields, changeFieldDisplay } = use('model.fields', props)
let items = []
const showFields = Object.keys(fields).filter(name => fields[name].showInList !== false)
const menuShow = showFields.length <= 10
for (let name of showFields) {
let field = fields[name]
, fieldName = name
, title = field.title || name
, fieldSelected = _.indexOf(selected, name) !== -1
, onClick = (e) => {
changeFieldDisplay([ fieldName, e.target.checked ])
}, onClickBtn = () => {
changeFieldDisplay([ fieldName, !fieldSelected ])
}
if(menuShow) {
const useList = render => props => {
const state = use('model.list', use('model', props))
const { loading, items, model } = state
const list = render(state)
if(loading) {
return {items.length > 0 ? list : null}
} else {
if(items.length > 0) {
return list
} else {
const EmptyComponent = model.components && model.components.DataEmpty
if(EmptyComponent) {
return
} else {
return
}
}
const AddChildrenModelBtn = props => {
const [ show, setShow ] = React.useState(false)
const { model, getItems } = use('model.getItems')
const { canAdd } = use('model.permission')
const { refData, refreshTimeout } = props
const onSuccess = () => {
if(refreshTimeout) {
setTimeout(getItems, refreshTimeout)
} else {
getItems()
}
}
return canAdd ? [
<button style="{{"> setShow(true)}>{_t('Add {{object}}', { object: model.title })}</button>,
setShow(false)} />
] : null
}
const Checkboxes = props => {
const { input: { value, onChange }, field, loading, options } = use('model.relate.select', props)
const onCheckChange = React.useCallback((checked, option) => {
if(checked) {
onChange([ ...value, option ])
} else {
onChange(value.filter(item => item.id != option.id))
}
}, [ value, onChange ])
const renderOptions = () => {
const checkedIds = value ? value.map(item => item.id) : []
return options.map(({ value, label, item })=>{
const checked = checkedIds.indexOf(value) >= 0
return {onCheckChange(!checked, item)}} checked={checked} {...field.attrs} >{label}
})
'model.item': props => {
return {
...props,
...use('model.get', props),
...use('model.save', props),
...use('model.delete', props)
}
},
'model.query': props => {
export default (props) =>
const AddModelBtn = () => {
const { model } = use('model')
const { canAdd } = use('model.permission')
const { saveItem } = use('model.save')
const { show, dispatch } = use('redux', state => ({ show: state.showModalAddForm[model.name] || false }))
const hideModal = () => {
dispatch({ model, type: '@@xadmin-modalform/CLOSE' })
}
const onSubmitSuccess = (item) => {
hideModal()
dispatch({ model, type: 'GET_ITEMS' })
}
return (canAdd && show) ? (
export default props => {
const { model } = use('model', props)
const { count } = use('model.select', props)
const { renderActions } = use('model.batchActions', props)
const actions = renderActions({ ...props, model })
return actions && actions.length > 0 ? (
{ React.Children.toArray(actions) }
)}>
<button>
{ count > 0 ? _t('{{count}} record selected', { count }) : _t('No data selected')}
</button>
) : null
}