UNPKG

@alauda-fe/common

Version:

Alauda frontend team common codes.

41 lines (40 loc) 1.54 kB
import { FormGroup } from '@angular/forms'; import { Observable } from 'rxjs'; interface Rule<T> { source: T; deps: string[]; isEnable: (...deps: unknown[]) => boolean; } /** * @description * 创建集群中存在大量的 control 依赖的情形,同时,由于业务特殊性,在 ipv4,ipv6 时要对表单控件进行不同外观的展示,因此控件的 disabled 变得很复杂 * 如果是在 ts 里通过 valueChanges 写:每个影响源都要写自己的 subscription,且某个 control 可能会收到多个其他 control 影响,届时逻辑组织会复杂很多, * 如果是在模板里通过 aluControlDisabled 去写,可能会存在多个 control 要重复同一套逻辑,这点在创建集群中很常见,因此提供了如下方案,可以以声明式写法去描述依赖关系 * * @usageNotes * For example, for the following `FormGroup`: * ``` * [ { source: 'joinCIDR', deps: ['networkType'], isEnable: networkType => networkType === 'kube-ovn', }, { source: 'gatewayIPv6', deps: ['networkType', 'transmitType', 'ipv6DualStack'], isEnable: (networkType, transmitType, ipv6DualStack: boolean) => networkType === 'kube-ovn' && transmitType === 'underlay' && ipv6DualStack, }, { source: ['clusterCIDRIPv6', 'serviceCIDRIPv6'], deps: ['ipv6DualStack'], isEnable: (ipv6DualStack: boolean) => ipv6DualStack, }, ] * ``` */ export declare function genControlDepsMap(context: FormGroup, rules: Array<Rule<string | string[]>>, destroy$: Observable<unknown>): void; export {};