mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 11:12:20 +08:00
fix: issues with deletion action , text ellipsis, and new data display in sub-table (#5523)
* fix: subtable issue * fix: bug * fix: bug * fix: bug * fix: bug * fix: bug * fix: bug
This commit is contained in:
parent
055b64ba0e
commit
45810d0658
@ -297,7 +297,7 @@ export const useTableSelectorProps = () => {
|
|||||||
field.value = data;
|
field.value = data;
|
||||||
field?.setInitialValue?.(data);
|
field?.setInitialValue?.(data);
|
||||||
field.data = field.data || {};
|
field.data = field.data || {};
|
||||||
field.data.selectedRowKeys = ctx?.field?.data?.selectedRowKeys;
|
field.data.selectedRowKeys = [];
|
||||||
field.componentProps.pagination = field.componentProps.pagination || {};
|
field.componentProps.pagination = field.componentProps.pagination || {};
|
||||||
field.componentProps.pagination.pageSize = ctx?.service?.data?.meta?.pageSize;
|
field.componentProps.pagination.pageSize = ctx?.service?.data?.meta?.pageSize;
|
||||||
field.componentProps.pagination.total = ctx?.service?.data?.meta?.count;
|
field.componentProps.pagination.total = ctx?.service?.data?.meta?.count;
|
||||||
|
@ -54,6 +54,11 @@ export const ellipsisSettingsItem: SchemaSettingsItemType = {
|
|||||||
tableFieldInstanceList.forEach((fieldInstance) => {
|
tableFieldInstanceList.forEach((fieldInstance) => {
|
||||||
fieldInstance.componentProps.ellipsis = checked;
|
fieldInstance.componentProps.ellipsis = checked;
|
||||||
});
|
});
|
||||||
|
schema['x-component-props']['ellipsis'] = checked;
|
||||||
|
const path = formField.path?.splice(formField.path?.length - 1, 1);
|
||||||
|
formField.form.query(`${path.concat(`*.` + fieldSchema.name)}`).forEach((f) => {
|
||||||
|
f.componentProps.ellipsis = checked;
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
formField.componentProps.ellipsis = checked;
|
formField.componentProps.ellipsis = checked;
|
||||||
}
|
}
|
||||||
|
@ -15,55 +15,9 @@ import { useFieldComponentName } from '../../../../common/useFieldComponentName'
|
|||||||
import { useCollectionField } from '../../../../data-source';
|
import { useCollectionField } from '../../../../data-source';
|
||||||
import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../../schema-component';
|
import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../../schema-component';
|
||||||
import { isSubMode } from '../../../../schema-component/antd/association-field/util';
|
import { isSubMode } from '../../../../schema-component/antd/association-field/util';
|
||||||
import {
|
import { allowAddNew, useIsFieldReadPretty } from '../../../../schema-component/antd/form-item/FormItem.Settings';
|
||||||
allowAddNew,
|
|
||||||
useIsFieldReadPretty,
|
|
||||||
useTitleFieldOptions,
|
|
||||||
} from '../../../../schema-component/antd/form-item/FormItem.Settings';
|
|
||||||
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
|
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
|
||||||
|
import { titleField } from '../Select/selectComponentFieldSettings';
|
||||||
export const titleField: any = {
|
|
||||||
name: 'titleField',
|
|
||||||
type: 'select',
|
|
||||||
useComponentProps() {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const field = useField<Field>();
|
|
||||||
const { uiSchema, fieldSchema: tableColumnSchema, collectionField: tableColumnField } = useColumnSchema();
|
|
||||||
const options = useTitleFieldOptions();
|
|
||||||
const schema = useFieldSchema();
|
|
||||||
const fieldSchema = tableColumnSchema || schema;
|
|
||||||
const targetCollectionField = useCollectionField();
|
|
||||||
const collectionField = tableColumnField || targetCollectionField;
|
|
||||||
const { dn } = useDesignable();
|
|
||||||
const fieldNames =
|
|
||||||
field?.componentProps?.fieldNames ||
|
|
||||||
fieldSchema?.['x-component-props']?.['fieldNames'] ||
|
|
||||||
uiSchema?.['x-component-props']?.['fieldNames'];
|
|
||||||
return {
|
|
||||||
title: t('Title field'),
|
|
||||||
options,
|
|
||||||
value: fieldNames?.label,
|
|
||||||
onChange(label) {
|
|
||||||
const schema = {
|
|
||||||
['x-uid']: fieldSchema['x-uid'],
|
|
||||||
};
|
|
||||||
const fieldNames = {
|
|
||||||
...collectionField?.uiSchema?.['x-component-props']?.['fieldNames'],
|
|
||||||
...field.componentProps.fieldNames,
|
|
||||||
label,
|
|
||||||
};
|
|
||||||
fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
|
|
||||||
fieldSchema['x-component-props']['fieldNames'] = fieldNames;
|
|
||||||
schema['x-component-props'] = fieldSchema['x-component-props'];
|
|
||||||
field.componentProps.fieldNames = fieldSchema['x-component-props'].fieldNames;
|
|
||||||
dn.emit('patch', {
|
|
||||||
schema,
|
|
||||||
});
|
|
||||||
dn.refresh();
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const allowMultiple: any = {
|
const allowMultiple: any = {
|
||||||
name: 'allowMultiple',
|
name: 'allowMultiple',
|
||||||
|
@ -17,7 +17,8 @@ import { useDesignable, useFieldModeOptions, useIsAddNewForm } from '../../../..
|
|||||||
import { isSubMode } from '../../../../schema-component/antd/association-field/util';
|
import { isSubMode } from '../../../../schema-component/antd/association-field/util';
|
||||||
import { useIsFieldReadPretty } from '../../../../schema-component/antd/form-item/FormItem.Settings';
|
import { useIsFieldReadPretty } from '../../../../schema-component/antd/form-item/FormItem.Settings';
|
||||||
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
|
import { useColumnSchema } from '../../../../schema-component/antd/table-v2/Table.Column.Decorator';
|
||||||
import { titleField } from '../Picker/recordPickerComponentFieldSettings';
|
import { titleField } from '../Select/selectComponentFieldSettings';
|
||||||
|
|
||||||
import { linkageRules } from '../SubTable/subTablePopoverComponentFieldSettings';
|
import { linkageRules } from '../SubTable/subTablePopoverComponentFieldSettings';
|
||||||
import { schemaSettingsLabelLayout } from '../../../../schema-settings';
|
import { schemaSettingsLabelLayout } from '../../../../schema-settings';
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ const enableLink = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const titleField: any = {
|
export const titleField: any = {
|
||||||
name: 'titleField',
|
name: 'titleField',
|
||||||
type: 'select',
|
type: 'select',
|
||||||
useComponentProps() {
|
useComponentProps() {
|
||||||
|
@ -147,6 +147,7 @@ export const SubTable: any = observer(
|
|||||||
setSelectedRows,
|
setSelectedRows,
|
||||||
collectionField,
|
collectionField,
|
||||||
};
|
};
|
||||||
|
|
||||||
const usePickActionProps = () => {
|
const usePickActionProps = () => {
|
||||||
const { setVisible } = useActionContext();
|
const { setVisible } = useActionContext();
|
||||||
const { selectedRows, setSelectedRows } = useContext(RecordPickerContext);
|
const { selectedRows, setSelectedRows } = useContext(RecordPickerContext);
|
||||||
@ -176,8 +177,9 @@ export const SubTable: any = observer(
|
|||||||
}, [field.componentProps?.pageSize]);
|
}, [field.componentProps?.pageSize]);
|
||||||
|
|
||||||
const paginationConfig = useMemo(() => {
|
const paginationConfig = useMemo(() => {
|
||||||
|
const page = Math.ceil(field.value?.length / 10);
|
||||||
return {
|
return {
|
||||||
current: currentPage,
|
current: currentPage > page ? page : currentPage,
|
||||||
pageSize: pageSize || 10,
|
pageSize: pageSize || 10,
|
||||||
total: field?.value?.length,
|
total: field?.value?.length,
|
||||||
onChange: (page, pageSize) => {
|
onChange: (page, pageSize) => {
|
||||||
|
@ -84,7 +84,7 @@ export const useColumnsDeepMemoized = (columns: any[]) => {
|
|||||||
return oldObj.value;
|
return oldObj.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
const useTableColumns = (props: { showDel?: any; isSubTable?: boolean }) => {
|
const useTableColumns = (props: { showDel?: any; isSubTable?: boolean }, paginationProps) => {
|
||||||
const { token } = useToken();
|
const { token } = useToken();
|
||||||
const field = useArrayField(props);
|
const field = useArrayField(props);
|
||||||
const schema = useFieldSchema();
|
const schema = useFieldSchema();
|
||||||
@ -98,7 +98,7 @@ const useTableColumns = (props: { showDel?: any; isSubTable?: boolean }) => {
|
|||||||
}
|
}
|
||||||
return buf;
|
return buf;
|
||||||
}, []);
|
}, []);
|
||||||
|
const { current, pageSize } = paginationProps;
|
||||||
const hasChangedColumns = useColumnsDeepMemoized(columnsSchema);
|
const hasChangedColumns = useColumnsDeepMemoized(columnsSchema);
|
||||||
|
|
||||||
const schemaToolbarBigger = useMemo(() => {
|
const schemaToolbarBigger = useMemo(() => {
|
||||||
@ -189,13 +189,13 @@ const useTableColumns = (props: { showDel?: any; isSubTable?: boolean }) => {
|
|||||||
<CloseOutlined
|
<CloseOutlined
|
||||||
style={{ cursor: 'pointer', color: 'gray' }}
|
style={{ cursor: 'pointer', color: 'gray' }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
action(() => {
|
return action(() => {
|
||||||
spliceArrayState(field as any, {
|
const fieldIndex = (current - 1) * pageSize + index;
|
||||||
startIndex: index,
|
spliceArrayState(field, {
|
||||||
|
startIndex: fieldIndex,
|
||||||
deleteCount: 1,
|
deleteCount: 1,
|
||||||
});
|
});
|
||||||
field.value.splice(index, 1);
|
field.value.splice(fieldIndex, 1);
|
||||||
field.initialValue?.splice(index, 1);
|
|
||||||
return field.onInput(field.value);
|
return field.onInput(field.value);
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@ -361,7 +361,7 @@ const usePaginationProps = (pagination1, pagination2) => {
|
|||||||
if (!pagination2 && pagination1 === false) {
|
if (!pagination2 && pagination1 === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return field.value?.length > 0 ? result : false;
|
return field.value?.length > 0 || result.total ? result : false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const headerClass = css`
|
const headerClass = css`
|
||||||
@ -616,7 +616,6 @@ export const Table: any = withDynamicSchemaProps(
|
|||||||
...others
|
...others
|
||||||
} = { ...others1, ...others2 } as any;
|
} = { ...others1, ...others2 } as any;
|
||||||
const field = useArrayField(others);
|
const field = useArrayField(others);
|
||||||
const columns = useTableColumns(others);
|
|
||||||
const schema = useFieldSchema();
|
const schema = useFieldSchema();
|
||||||
const collection = useCollection();
|
const collection = useCollection();
|
||||||
const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';
|
const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';
|
||||||
@ -624,12 +623,12 @@ export const Table: any = withDynamicSchemaProps(
|
|||||||
const { expandFlag, allIncludesChildren } = ctx;
|
const { expandFlag, allIncludesChildren } = ctx;
|
||||||
const onRowDragEnd = useMemoizedFn(others.onRowDragEnd || (() => {}));
|
const onRowDragEnd = useMemoizedFn(others.onRowDragEnd || (() => {}));
|
||||||
const paginationProps = usePaginationProps(pagination1, pagination2);
|
const paginationProps = usePaginationProps(pagination1, pagination2);
|
||||||
|
const columns = useTableColumns(others, paginationProps);
|
||||||
const [expandedKeys, setExpandesKeys] = useState(() => (expandFlag ? allIncludesChildren : []));
|
const [expandedKeys, setExpandesKeys] = useState(() => (expandFlag ? allIncludesChildren : []));
|
||||||
const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>(field?.data?.selectedRowKeys || []);
|
const [selectedRowKeys, setSelectedRowKeys] = useState<any[]>(field?.data?.selectedRowKeys || []);
|
||||||
const [selectedRow, setSelectedRow] = useState([]);
|
const [selectedRow, setSelectedRow] = useState([]);
|
||||||
const isRowSelect = rowSelection?.type !== 'none';
|
const isRowSelect = rowSelection?.type !== 'none';
|
||||||
const defaultRowKeyMap = useRef(new Map());
|
const defaultRowKeyMap = useRef(new Map());
|
||||||
|
|
||||||
const highlightRowCss = useMemo(() => {
|
const highlightRowCss = useMemo(() => {
|
||||||
return css`
|
return css`
|
||||||
& > td {
|
& > td {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user