Skip to content

Commit

Permalink
fix(amis): cards嵌套在crud下面,setValue时通过crud进行操作,解决crud的setValue动作失效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ranwawa committed Jan 11, 2025
1 parent 3b0391e commit d5b7330
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 15 additions & 1 deletion packages/amis/__tests__/renderers/CRUD.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1898,11 +1898,12 @@ test('25. CRUD Table Cell sync data to store', async () => {
});

describe.only('26. setValue 动作', () => {
it('table模式下,设置值后,页面能够自动更新', async () => {
const renderCrud = (mode: string) =>
render(
amisRender({
type: 'crud',
id: 'crud',
mode,
data: {
label: '点击前'
},
Expand All @@ -1928,6 +1929,9 @@ describe.only('26. setValue 动作', () => {
})
);

it('table模式下,设置值后,页面能够自动更新', async () => {
renderCrud('table');

await waitFor(() => {
expect(screen.getByText('点击前')).toBeInTheDocument();
});
Expand All @@ -1938,4 +1942,14 @@ describe.only('26. setValue 动作', () => {
expect(screen.getByText('点击后')).toBeInTheDocument();
});
});

it('cards模式下,设置值后,页面能够自动更新', () => {
renderCrud('cards');

expect(screen.getByText('点击前')).toBeInTheDocument();

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

expect(screen.getByText('点击后')).toBeInTheDocument();
});
});
11 changes: 8 additions & 3 deletions packages/amis/src/renderers/Cards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ export class CardsRenderer extends Cards {
index?: number | string,
condition?: any
) {
const {store} = this.props;
const {store, host} = this.props;

if (index !== undefined || condition !== undefined) {
const targets = await getMatchedEventTargets<IItem>(
Expand All @@ -1232,9 +1232,14 @@ export class CardsRenderer extends Cards {
targets.forEach(target => {
target.updateData(values);
});
} else {
return store.updateData(values, undefined, replace);
return;
}

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

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

getData() {
Expand Down

0 comments on commit d5b7330

Please sign in to comment.