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 }) { ...@@ -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: '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) }, { key: 'delete', label: '删除', icon: Delete, tone: 'danger', onClick: ({ record }) => setDeleteField(record.raw) },
]} ]}
collapseRowActions={false}
states={{ loading, error, success, emptyTitle: '暂无字段', emptyDescription: '使用“新建字段”配置表单结构。' }} states={{ loading, error, success, emptyTitle: '暂无字段', emptyDescription: '使用“新建字段”配置表单结构。' }}
/> />
......
...@@ -92,9 +92,9 @@ function sortTableActions(actions) { ...@@ -92,9 +92,9 @@ function sortTableActions(actions) {
.map(({ action }) => action); .map(({ action }) => action);
} }
export function TableActionGroup({ className, children, ...props }) { export function TableActionGroup({ className, children, collapseOverflow = true, ...props }) {
const actions = sortTableActions(flattenActions(children)); 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 visibleActions = shouldCollapseOverflow ? actions.slice(0, 2) : actions;
const overflowActions = shouldCollapseOverflow ? actions.slice(2) : []; const overflowActions = shouldCollapseOverflow ? actions.slice(2) : [];
......
...@@ -54,12 +54,12 @@ const DEFAULT_ROW_ACTION_ICONS = { ...@@ -54,12 +54,12 @@ const DEFAULT_ROW_ACTION_ICONS = {
'view-detail': Eye, 'view-detail': Eye,
}; };
function resolveActionColumnWidth(rowActions = [], explicitWidth) { function resolveActionColumnWidth(rowActions = [], explicitWidth, collapseRowActions = true) {
if (Number.isFinite(explicitWidth) && explicitWidth > 0) { if (Number.isFinite(explicitWidth) && explicitWidth > 0) {
return explicitWidth; return explicitWidth;
} }
const visibleActionCount = rowActions.length >= 4 const visibleActionCount = collapseRowActions && rowActions.length >= 4
? 3 ? 3
: Math.max(1, rowActions.length); : Math.max(1, rowActions.length);
...@@ -312,6 +312,13 @@ function defaultGetRecordLabel(record) { ...@@ -312,6 +312,13 @@ function defaultGetRecordLabel(record) {
return record?.title || record?.name || record?.id || '当前记录'; 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) { function getFilterPlaceholder(field) {
if (field?.placeholder) return field.placeholder; if (field?.placeholder) return field.placeholder;
if (field?.type === 'text' || field?.type === 'number') return '请输入'; if (field?.type === 'text' || field?.type === 'number') return '请输入';
...@@ -322,8 +329,7 @@ function getFilterPlaceholder(field) { ...@@ -322,8 +329,7 @@ function getFilterPlaceholder(field) {
} }
function defaultRenderCell(record, column) { function defaultRenderCell(record, column) {
const sourceRecord = record?.raw || record; const value = getRecordFieldValue(record, column.field);
const value = getFieldValue(sourceRecord, column.field);
const text = formatFieldValue(value, column.fieldDef) || '-'; const text = formatFieldValue(value, column.fieldDef) || '-';
if (column.fieldDef?.type === 'user') { if (column.fieldDef?.type === 'user') {
...@@ -555,6 +561,7 @@ export default function RecordWorkbench({ ...@@ -555,6 +561,7 @@ export default function RecordWorkbench({
pagination = null, pagination = null,
stickyTable = false, stickyTable = false,
showExpandColumn = true, showExpandColumn = true,
collapseRowActions = true,
}) { }) {
const tableScrollRef = useRef(null); const tableScrollRef = useRef(null);
const pendingTableScrollRef = useRef(null); const pendingTableScrollRef = useRef(null);
...@@ -605,8 +612,8 @@ export default function RecordWorkbench({ ...@@ -605,8 +612,8 @@ export default function RecordWorkbench({
[records, getRecordId], [records, getRecordId],
); );
const resolvedActionColumnWidth = useMemo( const resolvedActionColumnWidth = useMemo(
() => resolveActionColumnWidth(rowActions, actionColumnWidth), () => resolveActionColumnWidth(rowActions, actionColumnWidth, collapseRowActions),
[rowActions, actionColumnWidth], [rowActions, actionColumnWidth, collapseRowActions],
); );
const stickyColumns = useMemo( const stickyColumns = useMemo(
() => () =>
...@@ -914,7 +921,7 @@ export default function RecordWorkbench({ ...@@ -914,7 +921,7 @@ export default function RecordWorkbench({
} }
if (columnIndex === 0 && detailPanel) { 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) || '-'; const text = formatFieldValue(value, column.fieldDef) || '-';
return ( return (
<DataTablePrimaryAction <DataTablePrimaryAction
...@@ -946,7 +953,7 @@ export default function RecordWorkbench({ ...@@ -946,7 +953,7 @@ export default function RecordWorkbench({
(action) => !isActionHidden(action, row.rowContext), (action) => !isActionHidden(action, row.rowContext),
); );
return ( return (
<TableActionGroup className="justify-start"> <TableActionGroup className="justify-start" collapseOverflow={collapseRowActions}>
{visibleRowActions.map((action) => {visibleRowActions.map((action) =>
renderRowActionButton({ renderRowActionButton({
action, 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