fix: supportVariable SHOULD take precedence over supportVariableGlobally (#1997)

* fix: supportVariable should take precedence over supportVariableGlobally
This commit is contained in:
LeoYuan 袁力皓 2023-05-29 10:12:42 +08:00 committed by GitHub
parent ecca076d50
commit 503793fdfc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 16 deletions

View File

@ -1,6 +1,6 @@
import { Component, MouseEvent, Fragment, ReactNode } from 'react';
import { shallowIntl, observer, obx, engineConfig, runInAction } from '@alilc/lowcode-editor-core';
import { createContent, isJSSlot, isSetterConfig } from '@alilc/lowcode-utils';
import { createContent, isJSSlot, isSetterConfig, shouldUseVariableSetter } from '@alilc/lowcode-utils';
import { Skeleton, Stage } from '@alilc/lowcode-editor-skeleton';
import { IPublicApiSetters, IPublicTypeCustomView, IPublicTypeDynamicProps } from '@alilc/lowcode-types';
import { ISettingEntry, IComponentMeta, ISettingField, isSettingField, ISettingTopEntry } from '@alilc/lowcode-designer';
@ -155,23 +155,29 @@ class SettingFieldView extends Component<SettingFieldViewProps, SettingFieldView
const supportVariable = this.field.extraProps?.supportVariable;
// supportVariableGlobally 只对标准组件生效vc 需要单独配置
const supportVariableGlobally = engineConfig.get('supportVariableGlobally', false) && isStandardComponent(componentMeta);
if (supportVariable || supportVariableGlobally) {
if (setterType === 'MixedSetter') {
// VariableSetter 不单独使用
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
setterProps.setters.push('VariableSetter');
}
} else {
setterType = 'MixedSetter';
setterProps = {
setters: [
setter,
'VariableSetter',
],
};
}
const isUseVariableSetter = shouldUseVariableSetter(supportVariable, supportVariableGlobally);
if (isUseVariableSetter === false) {
return {
setterProps,
initialValue,
setterType,
};
}
if (setterType === 'MixedSetter') {
// VariableSetter 不单独使用
if (Array.isArray(setterProps.setters) && !setterProps.setters.includes('VariableSetter')) {
setterProps.setters.push('VariableSetter');
}
} else {
setterType = 'MixedSetter';
setterProps = {
setters: [
setter,
'VariableSetter',
],
};
}
return {
setterProps,
initialValue,

View File

@ -81,6 +81,7 @@ const stageList = [
'init',
'upgrade',
];
/**
*
* @param stage
@ -108,4 +109,18 @@ export function deprecate(fail: any, message: string, alterative?: string) {
export function isRegExp(obj: any): obj is RegExp {
return obj && obj.test && obj.exec && obj.compile;
}
/**
* The prop supportVariable SHOULD take precedence over default global supportVariable.
* @param propSupportVariable prop supportVariable
* @param globalSupportVariable global supportVariable
* @returns
*/
export function shouldUseVariableSetter(
propSupportVariable: boolean | undefined,
globalSupportVariable: boolean,
) {
if (propSupportVariable === false) return false;
return propSupportVariable || globalSupportVariable;
}

View File

@ -0,0 +1,9 @@
import { shouldUseVariableSetter } from '../../src/misc';
it('shouldUseVariableSetter', () => {
expect(shouldUseVariableSetter(false, true)).toBeFalsy();
expect(shouldUseVariableSetter(true, true)).toBeTruthy();
expect(shouldUseVariableSetter(true, false)).toBeTruthy();
expect(shouldUseVariableSetter(undefined, false)).toBeFalsy();
expect(shouldUseVariableSetter(undefined, true)).toBeTruthy();
});