Commit 918096b2 authored by drigle's avatar drigle

fix: restore dynamic form field actions

parent 01cf462f
......@@ -402,6 +402,7 @@ function FieldsDialog({ form, open, onClose }) {
{ key: 'move-down', label: '下移', icon: ArrowDownIcon, disabled: ({ record }) => fields.findIndex((item) => item.name === record.name) === fields.length - 1, onClick: ({ record }) => reorder(record.raw, 1) },
{ key: 'delete', label: '删除', icon: Delete, tone: 'danger', onClick: ({ record }) => setDeleteField(record.raw) },
]}
collapseRowActions={false}
states={{ loading, error, success, emptyTitle: '暂无字段', emptyDescription: '使用“新建字段”配置表单结构。' }}
/>
......
......@@ -92,9 +92,9 @@ function sortTableActions(actions) {
.map(({ action }) => action);
}
export function TableActionGroup({ className, children, ...props }) {
export function TableActionGroup({ className, children, collapseOverflow = true, ...props }) {
const actions = sortTableActions(flattenActions(children));
const shouldCollapseOverflow = actions.length >= 4;
const shouldCollapseOverflow = collapseOverflow && actions.length >= 4;
const visibleActions = shouldCollapseOverflow ? actions.slice(0, 2) : actions;
const overflowActions = shouldCollapseOverflow ? actions.slice(2) : [];
......
......@@ -54,12 +54,12 @@ const DEFAULT_ROW_ACTION_ICONS = {
'view-detail': Eye,
};
function resolveActionColumnWidth(rowActions = [], explicitWidth) {
function resolveActionColumnWidth(rowActions = [], explicitWidth, collapseRowActions = true) {
if (Number.isFinite(explicitWidth) && explicitWidth > 0) {
return explicitWidth;
}
const visibleActionCount = rowActions.length >= 4
const visibleActionCount = collapseRowActions && rowActions.length >= 4
? 3
: Math.max(1, rowActions.length);
......@@ -312,6 +312,13 @@ function defaultGetRecordLabel(record) {
return record?.title || record?.name || record?.id || '当前记录';
}
function getRecordFieldValue(record, field) {
const mappedValue = getFieldValue(record, field);
return mappedValue === undefined
? getFieldValue(record?.raw, field)
: mappedValue;
}
function getFilterPlaceholder(field) {
if (field?.placeholder) return field.placeholder;
if (field?.type === 'text' || field?.type === 'number') return '请输入';
......@@ -322,8 +329,7 @@ function getFilterPlaceholder(field) {
}
function defaultRenderCell(record, column) {
const sourceRecord = record?.raw || record;
const value = getFieldValue(sourceRecord, column.field);
const value = getRecordFieldValue(record, column.field);
const text = formatFieldValue(value, column.fieldDef) || '-';
if (column.fieldDef?.type === 'user') {
......@@ -555,6 +561,7 @@ export default function RecordWorkbench({
pagination = null,
stickyTable = false,
showExpandColumn = true,
collapseRowActions = true,
}) {
const tableScrollRef = useRef(null);
const pendingTableScrollRef = useRef(null);
......@@ -605,8 +612,8 @@ export default function RecordWorkbench({
[records, getRecordId],
);
const resolvedActionColumnWidth = useMemo(
() => resolveActionColumnWidth(rowActions, actionColumnWidth),
[rowActions, actionColumnWidth],
() => resolveActionColumnWidth(rowActions, actionColumnWidth, collapseRowActions),
[rowActions, actionColumnWidth, collapseRowActions],
);
const stickyColumns = useMemo(
() =>
......@@ -914,7 +921,7 @@ export default function RecordWorkbench({
}
if (columnIndex === 0 && detailPanel) {
const value = getFieldValue(row.record?.raw || row.record, column.field);
const value = getRecordFieldValue(row.record, column.field);
const text = formatFieldValue(value, column.fieldDef) || '-';
return (
<DataTablePrimaryAction
......@@ -946,7 +953,7 @@ export default function RecordWorkbench({
(action) => !isActionHidden(action, row.rowContext),
);
return (
<TableActionGroup className="justify-start">
<TableActionGroup className="justify-start" collapseOverflow={collapseRowActions}>
{visibleRowActions.map((action) =>
renderRowActionButton({
action,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment