import { ArrayField } from '@formily/core'; import { connect, useField } from '@formily/react'; import { Checkbox, Select, Table, Tag } from 'antd'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { useCompile } from '../..'; import { useAvailableActions } from './RoleTable'; const toScopes = (value) => { if (!value) { return {}; } const scopes = {}; value?.forEach?.((item) => { const [name, scope] = item.split(':'); scopes[name] = scope || 'all'; }); return scopes; }; const toFieldValue = (scopes) => { const values = []; for (const name in scopes) { if (Object.prototype.hasOwnProperty.call(scopes, name)) { const scope = scopes[name]; if (scope === 'all') { values.push(name); } else { values.push(`${name}:${scope}`); } } } return values; }; export const StrategyActions = connect((props) => { const { onChange } = props; const availableActions = useAvailableActions(); const compile = useCompile(); const { t } = useTranslation(); const field = useField(); const scopes = toScopes(field.value); return (
compile(value), }, { dataIndex: 'onNewRecord', title: t('Action type'), render: (onNewRecord) => onNewRecord ? ( {t('Action on new records')} ) : ( {t('Action on existing records')} ), }, { dataIndex: 'enabled', title: t('Allow'), render: (enabled, action) => ( { if (enabled) { delete scopes[action.name]; } else { scopes[action.name] = 'all'; } onChange(toFieldValue(scopes)); }} /> ), }, { dataIndex: 'scope', title: t('Data scope'), render: (scope, action) => !action.onNewRecord && (