Skip to content

Commit

Permalink
fix: 修复 static-xxx 在列中始终是能获取上层数据的问题 Close: baidu#9556 (baidu#9581)
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Feb 24, 2024
1 parent cb7a0f6 commit e2db651
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 4 deletions.
20 changes: 16 additions & 4 deletions packages/amis-core/src/renderers/wrapControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ export function wrapControl<

setInitialValue(value: any) {
const model = this.model!;
const {formStore: form, data} = this.props;
const {formStore: form, canAccessSuperData, data} = this.props;
const isExp = isExpression(value);

if (isExp) {
Expand All @@ -479,10 +479,22 @@ export function wrapControl<
} else {
let initialValue = model.extraName
? [
getVariable(data, model.name, form?.canAccessSuperData),
getVariable(data, model.extraName, form?.canAccessSuperData)
getVariable(
data,
model.name,
canAccessSuperData ?? form?.canAccessSuperData
),
getVariable(
data,
model.extraName,
canAccessSuperData ?? form?.canAccessSuperData
)
]
: getVariable(data, model.name, form?.canAccessSuperData);
: getVariable(
data,
model.name,
canAccessSuperData ?? form?.canAccessSuperData
);

if (
model.extraName &&
Expand Down
103 changes: 103 additions & 0 deletions packages/amis/__tests__/renderers/Table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,109 @@ test('Renderer:table-accessSuperData4', () => {
expect(td2?.textContent).toBe('-');
});

// https://github.com/baidu/amis/issues/9556
test('Renderer:table-accessSuperData5', async () => {
const {container, getByText} = render(
amisRender(
{
type: 'page',
data: {
engine: 'xxx',
items: [
{
id: 1
},
{
id: 2,
engine: 'Trident'
}
]
},
body: {
type: 'table',
name: 'crud',
source: '${items}',
columns: [
{
name: 'id',
label: 'ID'
},
{
type: 'static-text',
name: 'engine',
label: 'Rendering engine'
},
{
type: 'text',
name: 'engine',
label: 'Rendering engine'
}
]
}
},
{},
makeEnv({})
)
);

await wait(200);
const tds = [].slice
.call(container.querySelectorAll('td'))
.map((td: any) => td.textContent);
expect(tds).toEqual(['1', '-', '-', '2', 'Trident', 'Trident']);
});
test('Renderer:table-accessSuperData6', async () => {
const {container, getByText} = render(
amisRender(
{
type: 'page',
data: {
engine: 'xxx',
items: [
{
id: 1
},
{
id: 2,
engine: 'Trident'
}
]
},
body: {
type: 'table',
name: 'crud',
source: '${items}',
columns: [
{
name: 'id',
label: 'ID'
},
{
type: 'static-text',
name: 'engine',
label: 'Rendering engine',
canAccessSuperData: true
},
{
type: 'text',
name: 'engine',
label: 'Rendering engine'
}
]
}
},
{},
makeEnv({})
)
);

await wait(200);
const tds = [].slice
.call(container.querySelectorAll('td'))
.map((td: any) => td.textContent);
expect(tds).toEqual(['1', 'xxx', '-', '2', 'Trident', 'Trident']);
});

test('Renderer:table-each', () => {
const {container, getByText} = render(
amisRender(
Expand Down

0 comments on commit e2db651

Please sign in to comment.