Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(form): fix render UI can't be inherit #1661

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 56 additions & 38 deletions packages/form/spec/schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,44 +54,6 @@ describe('form: schema', () => {
})
.checkUI('/name', 'widget', 'textarea');
});
it('should be inherit all properties with * for ui schema', () => {
const schema: SFSchema = {
properties: {
name1: { type: 'string' },
name2: {
type: 'array',
items: {
type: 'object',
properties: {
a: {
type: 'string',
ui: {
grid: { span: 12 }
}
},
b: { type: 'string' }
},
ui: { spanLabelFixed: 10 }
}
}
}
};
const label = 10;
const ui: SFUISchema = {
'*': { spanLabel: label },
$name2: {
$items: {
$a: { spanLabel: 9 }
}
}
};
page
.newSchema(schema, ui)
.checkUI('/name1', 'spanLabel', label)
.add()
.checkUI('/name2/0/a', 'spanLabel', null) // 当指定标签为固定宽度时无须指定 `spanLabel`,`spanControl` 会强制清理
.checkUI('/name2/0/b', 'spanLabelFixed', 10);
});
it('should be fixed label width', () => {
const schema: SFSchema = {
properties: {
Expand Down Expand Up @@ -227,6 +189,62 @@ describe('form: schema', () => {
discardPeriodicTasks();
}));
});
describe('#inherit', () => {
it('should be inherit all properties with * for ui schema', () => {
const schema: SFSchema = {
properties: {
name1: { type: 'string' },
name2: {
type: 'array',
items: {
type: 'object',
properties: {
a: {
type: 'string',
ui: {
grid: { span: 12 }
}
},
b: { type: 'string' }
},
ui: { spanLabelFixed: 10 }
}
}
}
};
const label = 10;
const ui: SFUISchema = {
'*': { spanLabel: label },
$name2: {
$items: {
$a: { spanLabel: 9 }
}
}
};
page
.newSchema(schema, ui)
.checkUI('/name1', 'spanLabel', label)
.add()
.checkUI('/name2/0/a', 'spanLabel', null) // 当指定标签为固定宽度时无须指定 `spanLabel`,`spanControl` 会强制清理
.checkUI('/name2/0/b', 'spanLabelFixed', 10);
});
it('should be ignore inherit render ui', () => {
const schema: SFSchema = {
properties: {
a: { type: 'string' },
adr: {
type: 'object',
title: 'adr',
properties: {
a: { type: 'string', ui: { optional: 'Help a' } }
},
ui: { optional: 'Help Adr' }
}
}
};
page.newSchema(schema).checkUI('/adr', 'optional', 'Help Adr').checkUI('/adr/a', 'optional', 'Help a');
});
});
});

describe('[definitions]', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/form/src/sf.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ export class SFComponent implements OnInit, OnChanges, OnDestroy {
// 忽略部分会引起呈现的属性
visibleIf: undefined,
hidden: undefined,
optional: undefined,
optionalHelp: undefined,
widget: property.type,
...(property.format && (this.options.formatMap as NzSafeAny)[property.format]),
...(typeof property.ui === 'string' ? { widget: property.ui } : null),
Expand Down
17 changes: 17 additions & 0 deletions packages/form/src/widgets/object/object.widget.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,23 @@
<div [class.point]="showExpand" (click)="changeExpand()">
<i *ngIf="showExpand" nz-icon [nzType]="expand ? 'down' : 'up'" class="mr-xs text-xs"></i>
{{ title }}
<span *ngIf="ui.optional || oh" class="sf__optional">
{{ ui.optional }}
<i
*ngIf="oh"
nz-tooltip
[nzTooltipTitle]="oh.text"
[nzTooltipPlacement]="oh.placement"
[nzTooltipTrigger]="oh.trigger"
[nzTooltipColor]="oh.bgColor"
[nzTooltipOverlayClassName]="oh.overlayClassName"
[nzTooltipOverlayStyle]="oh.overlayStyle"
[nzTooltipMouseEnterDelay]="oh.mouseEnterDelay"
[nzTooltipMouseLeaveDelay]="oh.mouseLeaveDelay"
nz-icon
[nzType]="oh.icon!"
></i>
</span>
</div>
</ng-template>
<ng-template [ngTemplateOutlet]="default" [ngTemplateOutletContext]="{ $implicit: true }" />
Expand Down