import { ISchema, useField, useFieldSchema } from '@formily/react'; import React from 'react'; import { useDesignable } from '../..'; import { GeneralSchemaDesigner, SchemaSettings } from '../../../schema-settings'; export const ActionDesigner = (props) => { const field = useField(); const fieldSchema = useFieldSchema(); const { dn } = useDesignable(); const isPopupAction = ['create', 'update', 'view'].includes(fieldSchema['x-action'] || ''); return ( { if (title) { fieldSchema.title = title; field.title = title; field.componentProps.icon = icon; fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {}; fieldSchema['x-component-props'].icon = icon; dn.emit('patch', { schema: { ['x-uid']: fieldSchema['x-uid'], title, 'x-component-props': { ...fieldSchema['x-component-props'], }, }, }); dn.refresh(); } }} /> {isPopupAction && ( { field.componentProps.openMode = value; fieldSchema['x-component-props']['openMode'] = value; dn.emit('patch', { schema: { 'x-uid': fieldSchema['x-uid'], 'x-component-props': fieldSchema['x-component-props'], }, }); dn.refresh(); }} /> )} {fieldSchema['x-action-params'] && ( { try { const values = JSON.parse(initialValues); fieldSchema['x-action-params']['initialValues'] = values; dn.emit('patch', { schema: { ['x-uid']: fieldSchema['x-uid'], 'x-action-params': { initialValues: values, }, }, }); dn.refresh(); } catch (e) {} }} /> )} { return s['x-component'] === 'Space' || s['x-component'] === 'ActionBar'; }} /> ); };