mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
Merge branch 'next' into develop
This commit is contained in:
commit
c3f99d7efb
@ -62,6 +62,7 @@ interface Props {
|
||||
children?: any;
|
||||
expandFlag?: boolean;
|
||||
dragSortBy?: string;
|
||||
enableIndexÏColumn?: boolean;
|
||||
}
|
||||
|
||||
const InternalTableBlockProvider = (props: Props) => {
|
||||
@ -74,6 +75,7 @@ const InternalTableBlockProvider = (props: Props) => {
|
||||
expandFlag: propsExpandFlag = false,
|
||||
fieldNames,
|
||||
collection,
|
||||
enableIndexÏColumn,
|
||||
} = props;
|
||||
const field: any = useField();
|
||||
const { resource, service } = useBlockRequestContext();
|
||||
@ -131,6 +133,7 @@ const InternalTableBlockProvider = (props: Props) => {
|
||||
allIncludesChildren,
|
||||
setExpandFlag: setExpandFlagValue,
|
||||
heightProps,
|
||||
enableIndexÏColumn,
|
||||
}),
|
||||
[
|
||||
allIncludesChildren,
|
||||
@ -146,6 +149,7 @@ const InternalTableBlockProvider = (props: Props) => {
|
||||
service,
|
||||
setExpandFlagValue,
|
||||
showIndex,
|
||||
enableIndexÏColumn,
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -1085,5 +1085,6 @@
|
||||
"Date scope":"日期范围",
|
||||
"Deprecated": "已弃用",
|
||||
"The following old template features have been deprecated and will be removed in next version.": "以下旧的模板功能已弃用,将在下个版本移除。",
|
||||
"Full permissions": "全部权限"
|
||||
"Full permissions": "全部权限",
|
||||
"Enable index column": "启用序号列"
|
||||
}
|
@ -25,6 +25,33 @@ import { setDefaultSortingRulesSchemaSettingsItem } from '../../../../schema-set
|
||||
import { setTheDataScopeSchemaSettingsItem } from '../../../../schema-settings/setTheDataScopeSchemaSettingsItem';
|
||||
import { useBlockTemplateContext } from '../../../../schema-templates/BlockTemplateProvider';
|
||||
import { setDataLoadingModeSettingsItem } from '../details-multi/setDataLoadingModeSettingsItem';
|
||||
import { SchemaSettingsItemType } from '../../../../application';
|
||||
|
||||
const enabledIndexColumn: SchemaSettingsItemType = {
|
||||
name: 'enableIndexColumn',
|
||||
type: 'switch',
|
||||
useComponentProps: () => {
|
||||
const field = useField();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { t } = useTranslation();
|
||||
const { dn } = useDesignable();
|
||||
return {
|
||||
title: t('Enable index column'),
|
||||
checked: field.decoratorProps.enableSelectColumn !== false,
|
||||
onChange: async (enableIndexÏColumn) => {
|
||||
field.decoratorProps = field.decoratorProps || {};
|
||||
field.decoratorProps.enableIndexÏColumn = enableIndexÏColumn;
|
||||
fieldSchema['x-decorator-props'].enableIndexÏColumn = enableIndexÏColumn;
|
||||
dn.emit('patch', {
|
||||
schema: {
|
||||
['x-uid']: fieldSchema['x-uid'],
|
||||
'x-decorator-props': fieldSchema['x-decorator-props'],
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
export const tableBlockSettings = new SchemaSettings({
|
||||
name: 'blockSettings:table',
|
||||
@ -139,6 +166,7 @@ export const tableBlockSettings = new SchemaSettings({
|
||||
};
|
||||
},
|
||||
},
|
||||
enabledIndexColumn,
|
||||
{
|
||||
name: 'SortField',
|
||||
Component: SchemaSettingsSortField,
|
||||
|
@ -28,7 +28,33 @@ import { isSubMode } from '../../../../schema-component/antd/association-field/u
|
||||
import { useIsAssociationField } from '../../../../schema-component/antd/form-item';
|
||||
import { FormLinkageRules } from '../../../../schema-settings/LinkageRules';
|
||||
import { SchemaSettingsLinkageRules } from '../../../../schema-settings/SchemaSettings';
|
||||
import { SchemaSettingsItemType } from '../../../../application';
|
||||
|
||||
const enabledIndexColumn: SchemaSettingsItemType = {
|
||||
name: 'enableIndexColumn',
|
||||
type: 'switch',
|
||||
useComponentProps: () => {
|
||||
const field = useField();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { t } = useTranslation();
|
||||
const { dn } = useDesignable();
|
||||
return {
|
||||
title: t('Enable index column'),
|
||||
checked: field.componentProps.enableIndexÏColumn !== false,
|
||||
onChange: async (enableIndexÏColumn) => {
|
||||
field.componentProps = field.componentProps || {};
|
||||
field.componentProps.enableIndexÏColumn = enableIndexÏColumn;
|
||||
fieldSchema['x-component-props'].enableIndexÏColumn = enableIndexÏColumn;
|
||||
dn.emit('patch', {
|
||||
schema: {
|
||||
['x-uid']: fieldSchema['x-uid'],
|
||||
'x-component-props': fieldSchema['x-component-props'],
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
const fieldComponent: any = {
|
||||
name: 'fieldComponent',
|
||||
type: 'select',
|
||||
@ -365,6 +391,7 @@ export const subTablePopoverComponentFieldSettings = new SchemaSettings({
|
||||
allowSelectExistingRecord,
|
||||
allowDisassociation,
|
||||
setDefaultSortingRules,
|
||||
enabledIndexColumn,
|
||||
linkageRules,
|
||||
recordPerPage,
|
||||
],
|
||||
|
@ -97,7 +97,7 @@ export const SubTable: any = observer(
|
||||
const labelUiSchema = useLabelUiSchema(collectionField, fieldNames?.label || 'label');
|
||||
const recordV2 = useCollectionRecord();
|
||||
const collection = useCollection();
|
||||
const { allowSelectExistingRecord, allowAddnew, allowDisassociation } = field.componentProps;
|
||||
const { allowSelectExistingRecord, allowAddnew, allowDisassociation, enableIndexÏColumn } = field.componentProps;
|
||||
|
||||
useSubTableSpecialCase({ rootField: field, rootSchema: schema });
|
||||
|
||||
@ -218,7 +218,7 @@ export const SubTable: any = observer(
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
console.log(props);
|
||||
return (
|
||||
<div className={subTableContainer}>
|
||||
<FlagProvider isInSubTable>
|
||||
@ -252,6 +252,7 @@ export const SubTable: any = observer(
|
||||
locale={{
|
||||
emptyText: <span> {field.editable ? t('Please add or select record') : t('No data')}</span>,
|
||||
}}
|
||||
enableIndexÏColumn={enableIndexÏColumn !== false}
|
||||
/>
|
||||
{field.editable && (
|
||||
<Space
|
||||
|
@ -679,6 +679,7 @@ export const Table: any = withDynamicSchemaProps(
|
||||
onExpand,
|
||||
loading,
|
||||
onClickRow,
|
||||
enableIndexÏColumn,
|
||||
...others
|
||||
} = { ...others1, ...others2 } as any;
|
||||
const field = useArrayField(others);
|
||||
@ -831,65 +832,67 @@ export const Table: any = withDynamicSchemaProps(
|
||||
|
||||
const restProps = useMemo(
|
||||
() => ({
|
||||
rowSelection: memoizedRowSelection
|
||||
? {
|
||||
type: 'checkbox',
|
||||
selectedRowKeys: selectedRowKeys,
|
||||
onChange(selectedRowKeys: any[], selectedRows: any[]) {
|
||||
field.data = field.data || {};
|
||||
field.data.selectedRowKeys = selectedRowKeys;
|
||||
field.data.selectedRowData = selectedRows;
|
||||
setSelectedRowKeys(selectedRowKeys);
|
||||
onRowSelectionChange?.(selectedRowKeys, selectedRows);
|
||||
},
|
||||
getCheckboxProps(record) {
|
||||
return {
|
||||
'aria-label': `checkbox`,
|
||||
};
|
||||
},
|
||||
renderCell: (checked, record, index, originNode) => {
|
||||
if (!dragSort && !showIndex) {
|
||||
return originNode;
|
||||
}
|
||||
const current = paginationProps?.current;
|
||||
rowSelection: enableIndexÏColumn
|
||||
? memoizedRowSelection
|
||||
? {
|
||||
type: 'checkbox',
|
||||
selectedRowKeys: selectedRowKeys,
|
||||
onChange(selectedRowKeys: any[], selectedRows: any[]) {
|
||||
field.data = field.data || {};
|
||||
field.data.selectedRowKeys = selectedRowKeys;
|
||||
field.data.selectedRowData = selectedRows;
|
||||
setSelectedRowKeys(selectedRowKeys);
|
||||
onRowSelectionChange?.(selectedRowKeys, selectedRows);
|
||||
},
|
||||
getCheckboxProps(record) {
|
||||
return {
|
||||
'aria-label': `checkbox`,
|
||||
};
|
||||
},
|
||||
renderCell: (checked, record, index, originNode) => {
|
||||
if (!dragSort && !showIndex) {
|
||||
return originNode;
|
||||
}
|
||||
const current = paginationProps?.current;
|
||||
|
||||
const pageSize = paginationProps?.pageSize || 20;
|
||||
if (current) {
|
||||
index = index + (current - 1) * pageSize + 1;
|
||||
} else {
|
||||
index = index + 1;
|
||||
}
|
||||
if (record.__index) {
|
||||
index = extractIndex(record.__index);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
aria-label={`table-index-${index}`}
|
||||
className={classNames(checked ? 'checked' : null, rowSelectCheckboxWrapperClass, {
|
||||
[rowSelectCheckboxWrapperClassHover]: isRowSelect,
|
||||
})}
|
||||
>
|
||||
<div className={classNames(checked ? 'checked' : null, rowSelectCheckboxContentClass)}>
|
||||
{dragSort && <SortHandle id={getRowKey(record)} />}
|
||||
{showIndex && <TableIndex index={index} />}
|
||||
</div>
|
||||
{isRowSelect && (
|
||||
<div
|
||||
className={classNames(
|
||||
'nb-origin-node',
|
||||
checked ? 'checked' : null,
|
||||
rowSelectCheckboxCheckedClassHover,
|
||||
)}
|
||||
>
|
||||
{originNode}
|
||||
const pageSize = paginationProps?.pageSize || 20;
|
||||
if (current) {
|
||||
index = index + (current - 1) * pageSize + 1;
|
||||
} else {
|
||||
index = index + 1;
|
||||
}
|
||||
if (record.__index) {
|
||||
index = extractIndex(record.__index);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
aria-label={`table-index-${index}`}
|
||||
className={classNames(checked ? 'checked' : null, rowSelectCheckboxWrapperClass, {
|
||||
[rowSelectCheckboxWrapperClassHover]: isRowSelect,
|
||||
})}
|
||||
>
|
||||
<div className={classNames(checked ? 'checked' : null, rowSelectCheckboxContentClass)}>
|
||||
{dragSort && <SortHandle id={getRowKey(record)} />}
|
||||
{showIndex && <TableIndex index={index} />}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
...memoizedRowSelection,
|
||||
}
|
||||
{isRowSelect && (
|
||||
<div
|
||||
className={classNames(
|
||||
'nb-origin-node',
|
||||
checked ? 'checked' : null,
|
||||
rowSelectCheckboxCheckedClassHover,
|
||||
)}
|
||||
>
|
||||
{originNode}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
...memoizedRowSelection,
|
||||
}
|
||||
: undefined
|
||||
: undefined,
|
||||
}),
|
||||
[
|
||||
@ -903,6 +906,7 @@ export const Table: any = withDynamicSchemaProps(
|
||||
isRowSelect,
|
||||
memoizedRowSelection,
|
||||
paginationProps,
|
||||
enableIndexÏColumn,
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -851,7 +851,7 @@ export const Table: any = withDynamicSchemaProps(
|
||||
const collection = useCollection();
|
||||
const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';
|
||||
const ctx = isTableSelector ? useTableSelectorContext() : useTableBlockContext();
|
||||
const { expandFlag, allIncludesChildren } = ctx;
|
||||
const { expandFlag, allIncludesChildren, enableIndexÏColumn } = ctx;
|
||||
const onRowDragEnd = useMemoizedFn(others.onRowDragEnd || (() => {}));
|
||||
const paginationProps = usePaginationProps(pagination1, pagination2, props);
|
||||
const columns = useTableColumns(others, paginationProps);
|
||||
@ -1016,73 +1016,76 @@ export const Table: any = withDynamicSchemaProps(
|
||||
|
||||
const restProps = useMemo(
|
||||
() => ({
|
||||
rowSelection: memoizedRowSelection
|
||||
? {
|
||||
type: 'checkbox',
|
||||
selectedRowKeys: selectedRowKeys,
|
||||
onChange(selectedRowKeys: any[], selectedRows: any[]) {
|
||||
field.data = field.data || {};
|
||||
field.data.selectedRowKeys = selectedRowKeys;
|
||||
field.data.selectedRowData = selectedRows;
|
||||
setSelectedRowKeys(selectedRowKeys);
|
||||
onRowSelectionChange?.(selectedRowKeys, selectedRows, setSelectedRowKeys);
|
||||
},
|
||||
onSelect: (record, selected: boolean, selectedRows, nativeEvent) => {
|
||||
if (tableBlockContextBasicValue) {
|
||||
tableBlockContextBasicValue.field.data = tableBlockContextBasicValue.field?.data || {};
|
||||
tableBlockContextBasicValue.field.data.selectedRecord = record;
|
||||
tableBlockContextBasicValue.field.data.selected = selected;
|
||||
}
|
||||
},
|
||||
getCheckboxProps(record) {
|
||||
return {
|
||||
'aria-label': `checkbox`,
|
||||
};
|
||||
},
|
||||
renderCell: (checked, record, index, originNode) => {
|
||||
if (!dragSort && !showIndex) {
|
||||
return originNode;
|
||||
}
|
||||
const current = paginationProps?.current;
|
||||
rowSelection:
|
||||
enableIndexÏColumn !== false
|
||||
? memoizedRowSelection
|
||||
? {
|
||||
type: 'checkbox',
|
||||
selectedRowKeys: selectedRowKeys,
|
||||
onChange(selectedRowKeys: any[], selectedRows: any[]) {
|
||||
field.data = field.data || {};
|
||||
field.data.selectedRowKeys = selectedRowKeys;
|
||||
field.data.selectedRowData = selectedRows;
|
||||
setSelectedRowKeys(selectedRowKeys);
|
||||
onRowSelectionChange?.(selectedRowKeys, selectedRows, setSelectedRowKeys);
|
||||
},
|
||||
onSelect: (record, selected: boolean, selectedRows, nativeEvent) => {
|
||||
if (tableBlockContextBasicValue) {
|
||||
tableBlockContextBasicValue.field.data = tableBlockContextBasicValue.field?.data || {};
|
||||
tableBlockContextBasicValue.field.data.selectedRecord = record;
|
||||
tableBlockContextBasicValue.field.data.selected = selected;
|
||||
}
|
||||
},
|
||||
getCheckboxProps(record) {
|
||||
return {
|
||||
'aria-label': `checkbox`,
|
||||
};
|
||||
},
|
||||
renderCell: (checked, record, index, originNode) => {
|
||||
if (!dragSort && !showIndex) {
|
||||
return originNode;
|
||||
}
|
||||
const current = paginationProps?.current;
|
||||
|
||||
const pageSize = paginationProps?.pageSize || 20;
|
||||
if (current) {
|
||||
index = index + (current - 1) * pageSize + 1;
|
||||
} else {
|
||||
index = index + 1;
|
||||
}
|
||||
if (record.__index) {
|
||||
index = extractIndex(record.__index);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
role="button"
|
||||
aria-label={`table-index-${index}`}
|
||||
className={classNames(checked ? 'checked' : null, rowSelectCheckboxWrapperClass, {
|
||||
[rowSelectCheckboxWrapperClassHover]: isRowSelect,
|
||||
})}
|
||||
>
|
||||
<div className={classNames(checked ? 'checked' : null, rowSelectCheckboxContentClass)}>
|
||||
{dragSort && <SortHandle id={getRowKey(record)} />}
|
||||
{showIndex && <TableIndex index={index} />}
|
||||
</div>
|
||||
{isRowSelect && (
|
||||
const pageSize = paginationProps?.pageSize || 20;
|
||||
if (current) {
|
||||
index = index + (current - 1) * pageSize + 1;
|
||||
} else {
|
||||
index = index + 1;
|
||||
}
|
||||
if (record.__index) {
|
||||
index = extractIndex(record.__index);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'nb-origin-node',
|
||||
checked ? 'checked' : null,
|
||||
rowSelectCheckboxCheckedClassHover,
|
||||
)}
|
||||
role="button"
|
||||
aria-label={`table-index-${index}`}
|
||||
className={classNames(checked ? 'checked' : null, rowSelectCheckboxWrapperClass, {
|
||||
[rowSelectCheckboxWrapperClassHover]: isRowSelect,
|
||||
})}
|
||||
>
|
||||
{originNode}
|
||||
<div className={classNames(checked ? 'checked' : null, rowSelectCheckboxContentClass)}>
|
||||
{dragSort && <SortHandle id={getRowKey(record)} />}
|
||||
{showIndex && <TableIndex index={index} />}
|
||||
</div>
|
||||
{isRowSelect && (
|
||||
<div
|
||||
className={classNames(
|
||||
'nb-origin-node',
|
||||
checked ? 'checked' : null,
|
||||
rowSelectCheckboxCheckedClassHover,
|
||||
)}
|
||||
>
|
||||
{originNode}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
...memoizedRowSelection,
|
||||
}
|
||||
: undefined,
|
||||
);
|
||||
},
|
||||
...memoizedRowSelection,
|
||||
}
|
||||
: undefined
|
||||
: undefined,
|
||||
}),
|
||||
[
|
||||
memoizedRowSelection,
|
||||
@ -1096,6 +1099,7 @@ export const Table: any = withDynamicSchemaProps(
|
||||
memoizedRowSelection,
|
||||
paginationProps,
|
||||
tableBlockContextBasicValue,
|
||||
enableIndexÏColumn,
|
||||
],
|
||||
);
|
||||
|
||||
|
@ -176,6 +176,21 @@ export const TableBlockDesigner = () => {
|
||||
});
|
||||
}}
|
||||
/>
|
||||
<SchemaSettingsSwitchItem
|
||||
title={t('Enable index column')}
|
||||
checked={field.decoratorProps?.enableSelectColumn !== false}
|
||||
onChange={async (enableIndexÏColumn) => {
|
||||
field.decoratorProps = field.decoratorProps || {};
|
||||
field.decoratorProps.enableIndexÏColumn = enableIndexÏColumn;
|
||||
fieldSchema['x-decorator-props'].enableIndexÏColumn = enableIndexÏColumn;
|
||||
dn.emit('patch', {
|
||||
schema: {
|
||||
['x-uid']: fieldSchema['x-uid'],
|
||||
'x-decorator-props': fieldSchema['x-decorator-props'],
|
||||
},
|
||||
});
|
||||
}}
|
||||
/>
|
||||
{field.decoratorProps.dragSort && <EditSortField />}
|
||||
<SchemaSettingsDataScope
|
||||
collectionName={name}
|
||||
|
@ -72,6 +72,10 @@ describe('Table.settings', () => {
|
||||
expect(screen.queryByText('Drag and drop sorting field')).not.toBeInTheDocument();
|
||||
},
|
||||
},
|
||||
{
|
||||
title: 'Enable index column',
|
||||
type: 'switch',
|
||||
},
|
||||
// {
|
||||
// title: 'Fix block',
|
||||
// type: 'switch',
|
||||
|
Loading…
x
Reference in New Issue
Block a user