Skip to content

Commit

Permalink
🐛 fix: SortableList 默认空数据处理
Browse files Browse the repository at this point in the history
  • Loading branch information
rdmclin2 committed Jun 12, 2023
1 parent 3fdb7e0 commit 07bda12
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export default defineConfig({
{
image:
'https://mdn.alipayobjects.com/yuyan_qk0oxh/afts/img/UKqDTIp55HYAAAAAAAAAAAAAFl94AQBr',
title: '国际化',
description: '提供完备的国际化,与 Ant Design 体系打通,无需多余配置',
title: '通用编辑器组件',
description: '提供完备的编辑器组件,方便使用者定制自己的编辑器',
},

{
Expand Down
53 changes: 53 additions & 0 deletions src/ColumnList/demos/empty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { EditFilled } from '@ant-design/icons';
import type { ColumnItemList } from '@ant-design/pro-editor';
import { ActionIcon, ColumnList } from '@ant-design/pro-editor';
import { message } from 'antd';
import { useState } from 'react';
import { tableColumnValueOptions } from './mock_data/options';

type SchemaItem = {
title: string;
valueType: string;
dataIndex: string;
};

const columns: ColumnItemList<SchemaItem> = [
{
title: '列标题',
dataIndex: 'title',
type: 'input',
},
{
title: '值类型',
dataIndex: 'valueType',
type: 'select',
options: tableColumnValueOptions,
},
{
title: '字段',
dataIndex: 'dataIndex',
type: 'select',
},
];

export default () => {
const [value, setValue] = useState(null);
return (
<ColumnList<SchemaItem>
columns={columns}
value={value}
actions={(field) => [
<ActionIcon
icon={<EditFilled />}
key={'edit'}
tabIndex={-1}
onClick={() => message.info(field.dataIndex)}
/>,
]}
onChange={(values) => {
console.log('onChange', values);
setValue(values);
}}
/>
);
};
4 changes: 4 additions & 0 deletions src/ColumnList/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ order: 3

<code src="./demos/custom.tsx" ></code>

### 空数据

<code src="./demos/empty.tsx" ></code>

## API

<API id="ColumnList"></API>
6 changes: 4 additions & 2 deletions src/SortableList/container/StoreUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ const StoreUpdater = forwardRef(
// KeyManager 和 value & initialValues 同步。
const KeyManagerUpdater = (state, key) => {
const { keyManager } = storeApi.getState();
// value 为空处理
const value = state[key] || [];
const manager = produce(keyManager, (draft) => {
state[key].forEach((__, index) => {
value.forEach((__, index) => {
const key = draft.keys[index];
if (key === undefined) {
draft.keys[index] = draft.id;
Expand All @@ -96,7 +98,7 @@ const StoreUpdater = forwardRef(
return draft;
});

storeApi.setState({ keyManager: manager, [key]: state[key] });
storeApi.setState({ keyManager: manager, [key]: value });
};

useStoreUpdater('value', initialValues, []);
Expand Down

0 comments on commit 07bda12

Please sign in to comment.