fix: use the isHidden to hide a property instead of shouldRender

This commit is contained in:
MrWindlike 2022-06-13 16:33:52 +08:00
parent ab13ad629f
commit ec0797bc12
2 changed files with 5 additions and 4 deletions

View File

@ -21,7 +21,6 @@ import {
shouldDisplayLabel,
getCodeMode,
} from '../../utils/widget';
import { shouldRender } from '../../utils/condition';
import { ExpressionWidget, ExpressionWidgetOptionsSpec } from './ExpressionWidget';
import { StringField } from './StringField';
import { ObjectField } from './ObjectField';
@ -131,6 +130,7 @@ export const SchemaFieldWidgetOptions = Type.Object({
isDisplayLabel: Type.Optional(Type.Boolean()),
isShowAsideExpressionButton: Type.Optional(Type.Boolean()),
expressionOptions: Type.Optional(ExpressionWidgetOptionsSpec),
isHidden: Type.Optional(Type.Boolean()),
});
type SchemaFieldWidgetOptionsType = Static<typeof SchemaFieldWidgetOptions>;
@ -145,7 +145,8 @@ type Props = WidgetProps<SchemaFieldWidgetOptionsType> & {
export const SpecWidget: React.FC<Props> = props => {
const { component, spec, level, path, value, services, children, onChange } = props;
const { title, widgetOptions } = spec;
const { isShowAsideExpressionButton, expressionOptions } = widgetOptions || {};
const { isShowAsideExpressionButton, expressionOptions, isHidden } =
widgetOptions || {};
const label = title ?? '';
const { widgetManager } = services;
const [isExpression, setIsExpression] = useState(() => _isExpression(value));
@ -153,7 +154,7 @@ export const SpecWidget: React.FC<Props> = props => {
widgetOptions?.isDisplayLabel !== false && shouldDisplayLabel(spec, label);
const codeMode = getCodeMode(spec);
if (isEmpty(spec) || !shouldRender(spec.conditions || [], value)) {
if (isEmpty(spec) || isHidden) {
return null;
}

View File

@ -8,7 +8,7 @@ const ContainerPropertySpec = Type.Object(
slot: Type.String(),
},
// don't show this property in the editor
{ conditions: [{ key: '', value: '' }] }
{ widgetOptions: { isHidden: true } }
);
export const PropsSpec = Type.Object({