feat: table block support size settings (#5563)

* feat: table block support size settings

* fix: bug

* fix: bug

* fix: test
This commit is contained in:
Katherine 2024-11-06 09:11:45 +08:00 committed by GitHub
parent aad8fd7bab
commit ee1dd2375f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 79 additions and 6 deletions

View File

@ -2,9 +2,7 @@
"version": "1.4.0-alpha", "version": "1.4.0-alpha",
"npmClient": "yarn", "npmClient": "yarn",
"useWorkspaces": true, "useWorkspaces": true,
"npmClientArgs": [ "npmClientArgs": ["--ignore-engines"],
"--ignore-engines"
],
"command": { "command": {
"version": { "version": {
"forcePublish": true, "forcePublish": true,

View File

@ -1024,5 +1024,6 @@
"Line break": "换行", "Line break": "换行",
"Ellipsis": "省略", "Ellipsis": "省略",
"Set block layout": "设置区块布局", "Set block layout": "设置区块布局",
"Add & Update": "添加 & 更新" "Add & Update": "添加 & 更新",
"Table size":"表格大小"
} }

View File

@ -187,6 +187,40 @@ export const tableBlockSettings = new SchemaSettings({
}; };
}, },
}, },
{
name: 'tableSize',
type: 'select',
useComponentProps() {
const field = useField();
const fieldSchema = useFieldSchema();
const { t } = useTranslation();
const { dn } = useDesignable();
return {
title: t('Table size'),
value: field.componentProps?.size || 'middle',
options: [
{ label: t('Large'), value: 'large' },
{ label: t('Middle'), value: 'middle' },
{ label: t('Small'), value: 'small' },
],
onChange: (size) => {
const schema = fieldSchema.reduceProperties((_, s) => {
if (s['x-component'] === 'TableV2') {
return s;
}
}, null);
schema['x-component-props'] = schema['x-component-props'] || {};
schema['x-component-props']['size'] = size;
dn.emit('patch', {
schema: {
['x-uid']: schema['x-uid'],
'x-decorator-props': schema['x-component-props'],
},
});
},
};
},
},
{ {
name: 'ConnectDataBlocks', name: 'ConnectDataBlocks',
Component: SchemaSettingsConnectDataBlocks, Component: SchemaSettingsConnectDataBlocks,

View File

@ -500,7 +500,7 @@ Grid.Col = observer(
width = `calc(${w}% - ${token.marginBlock}px * ${(showDivider ? cols.length + 1 : 0) / cols.length})`; width = `calc(${w}% - ${token.marginBlock}px * ${(showDivider ? cols.length + 1 : 0) / cols.length})`;
} }
return { width }; return { width };
}, [cols?.length, schema?.['x-component-props']?.['width']]); }, [cols?.length, schema?.['x-component-props']?.['width'], token.marginBlock]);
const { isOver, setNodeRef } = useDroppable({ const { isOver, setNodeRef } = useDroppable({
id: field.address.toString(), id: field.address.toString(),
data: { data: {

View File

@ -620,6 +620,7 @@ export const Table: any = withDynamicSchemaProps(
} = { ...others1, ...others2 } as any; } = { ...others1, ...others2 } as any;
const field = useArrayField(others); const field = useArrayField(others);
const schema = useFieldSchema(); const schema = useFieldSchema();
const { size = 'middle' } = schema?.['x-component-props'] || {};
const collection = useCollection(); const collection = useCollection();
const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider'; const isTableSelector = schema?.parent?.['x-decorator'] === 'TableSelectorProvider';
const ctx = isTableSelector ? useTableSelectorContext() : useTableBlockContext(); const ctx = isTableSelector ? useTableSelectorContext() : useTableBlockContext();
@ -892,7 +893,6 @@ export const Table: any = withDynamicSchemaProps(
expandedRowKeys: expandedKeys, expandedRowKeys: expandedKeys,
}; };
}, [expandedKeys, onExpandValue]); }, [expandedKeys, onExpandValue]);
return ( return (
// If spinning is set to undefined, it will cause the subtable to always display loading, so we need to convert it here // If spinning is set to undefined, it will cause the subtable to always display loading, so we need to convert it here
<Spin spinning={!!loading}> <Spin spinning={!!loading}>
@ -913,6 +913,7 @@ export const Table: any = withDynamicSchemaProps(
columns={columns} columns={columns}
expandable={expandable} expandable={expandable}
field={field} field={field}
size={size}
/> />
</Spin> </Spin>
); );

View File

@ -303,6 +303,30 @@ export const TableBlockDesigner = () => {
}); });
}} }}
/> />
<SchemaSettingsSelectItem
title={t('Table size')}
value={field.componentProps?.size || 'middle'}
options={[
{ label: t('Large'), value: 'large' },
{ label: t('Middle'), value: 'middle' },
{ label: t('Small'), value: 'small' },
]}
onChange={(size) => {
const schema = fieldSchema.reduceProperties((_, s) => {
if (s['x-component'] === 'TableV2') {
return s;
}
}, null);
schema['x-component-props'] = schema['x-component-props'] || {};
schema['x-component-props']['size'] = size;
dn.emit('patch', {
schema: {
['x-uid']: schema['x-uid'],
'x-decorator-props': schema['x-component-props'],
},
});
}}
/>
<SchemaSettingsConnectDataBlocks type={FilterBlockType.TABLE} emptyDescription={t('No blocks to connect')} /> <SchemaSettingsConnectDataBlocks type={FilterBlockType.TABLE} emptyDescription={t('No blocks to connect')} />
{supportTemplate && <SchemaSettingsDivider />} {supportTemplate && <SchemaSettingsDivider />}
{supportTemplate && ( {supportTemplate && (

View File

@ -219,6 +219,21 @@ describe('Table.settings', () => {
}, },
], ],
}, },
{
title: 'Table size',
type: 'select',
options: [
{
label: 'Large',
},
{
label: 'Middle',
},
{
label: 'Small',
},
],
},
{ {
title: 'Save as template', title: 'Save as template',
type: 'modal', type: 'modal',