Skip to content

Commit

Permalink
fix(amis): table嵌套在crud下面,setValue时通过crud进行操作,解决crud的setValue动作失效的问题
Browse files Browse the repository at this point in the history
closes:11453
  • Loading branch information
ranwawa committed Jan 11, 2025
1 parent 4032263 commit 3b0391e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
43 changes: 43 additions & 0 deletions packages/amis/__tests__/renderers/CRUD.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1896,3 +1896,46 @@ test('25. CRUD Table Cell sync data to store', async () => {
const listDoms2 = container.querySelectorAll('.cxd-ListItem-title');
expect(listDoms2.length).toEqual(0);
});

describe.only('26. setValue 动作', () => {
it('table模式下,设置值后,页面能够自动更新', async () => {
render(
amisRender({
type: 'crud',
id: 'crud',
data: {
label: '点击前'
},
headerToolbar: [
{
type: 'button',
label: '${label}',
onEvent: {
click: {
actions: [
{
actionType: 'setValue',
componentId: 'crud',
args: {
value: {label: '点击后'}
}
}
]
}
}
}
]
})
);

await waitFor(() => {
expect(screen.getByText('点击前')).toBeInTheDocument();
});

fireEvent.click(screen.getByText('点击前'));

await waitFor(() => {
expect(screen.getByText('点击后')).toBeInTheDocument();
});
});
});
20 changes: 13 additions & 7 deletions packages/amis/src/renderers/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3049,7 +3049,7 @@ export class TableRendererBase<
index?: number | string,
condition?: any
) {
const {store} = this.props;
const {store, host} = this.props;

if (index !== undefined || condition !== undefined) {
const targets = await this.getEventTargets(
Expand All @@ -3060,13 +3060,19 @@ export class TableRendererBase<
targets.forEach(target => {
target.updateData(values);
});
} else {
const data = {
...values,
rows: values.rows ?? values.items // 做个兼容
};
return store.updateData(data, undefined, replace);
return;
}

if (host) {
host.setData?.(values, replace);
}

const data = {
...values,
rows: values.rows ?? values.items // 做个兼容
};

return store.updateData(data, undefined, replace);
}

getData() {
Expand Down

0 comments on commit 3b0391e

Please sign in to comment.