Merge pull request #429 from webzard-io/fix/windlike

Fix/windlike
This commit is contained in:
tanbowensg 2022-06-01 18:11:24 +08:00 committed by GitHub
commit 83c3f7a374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 15 deletions

View File

@ -2,7 +2,11 @@ import { RuntimeFunctions } from '@sunmao-ui/runtime';
import { useState, useEffect } from 'react';
import { SlotSpec } from '@sunmao-ui/core';
export const useStateValue = <T, TMethods, TSlots extends Record<string, SlotSpec>>(
export const useStateValue = <
T,
TMethods = any,
TSlots extends Record<string, SlotSpec> = Record<string, SlotSpec>
>(
defaultValue: T,
mergeState?: RuntimeFunctions<Record<string, T>, TMethods, TSlots>['mergeState'],
updateWhenDefaultValueChanges?: boolean,

View File

@ -1,6 +1,6 @@
import React, { useCallback, useEffect, useState, useMemo } from 'react';
import { FormControl, FormLabel, Input, Select } from '@chakra-ui/react';
import { Type, Static } from '@sinclair/typebox';
import { Type, Static, TSchema } from '@sinclair/typebox';
import { useFormik } from 'formik';
import { GLOBAL_UTIL_METHOD_ID } from '@sunmao-ui/runtime';
import { ComponentSchema } from '@sunmao-ui/core';
@ -9,7 +9,7 @@ import { implementWidget, mergeWidgetOptionsIntoSpec } from '../../utils/widget'
import { RecordWidget } from './RecordField';
import { SpecWidget } from './SpecWidget';
import { observer } from 'mobx-react-lite';
import { CORE_VERSION, CoreWidgetName } from '@sunmao-ui/shared';
import { CORE_VERSION, CoreWidgetName, parseTypeBox } from '@sunmao-ui/shared';
const EventWidgetOptions = Type.Object({});
@ -90,17 +90,16 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
]);
const params = useMemo(() => {
const params: Record<string, string> = {};
const parameters = formik.values.method.parameters;
for (const key in paramsSpec?.properties ?? {}) {
const defaultValue = (paramsSpec?.properties?.[key] as WidgetProps['spec'])
.defaultValue;
const spec = paramsSpec!.properties![key] as TSchema;
const defaultValue = spec.defaultValue;
params[key] = parameters?.[key] ?? defaultValue ?? '';
params[key] = defaultValue ?? parseTypeBox(spec);
}
return params;
}, [formik.values.method.parameters, paramsSpec?.properties]);
}, [paramsSpec]);
const parametersPath = useMemo(() => path.concat('method', 'parameters'), [path]);
const parametersSpec = useMemo(
() => mergeWidgetOptionsIntoSpec(paramsSpec, { onlySetValue: true }),
@ -177,7 +176,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
const typeField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Event Type</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Event Type
</FormLabel>
<Select
name="type"
onBlur={onSubmit}
@ -195,7 +196,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
);
const targetField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Target Component</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Target Component
</FormLabel>
<Select
name="componentId"
onBlur={onSubmit}
@ -213,7 +216,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
);
const methodField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Method</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Method
</FormLabel>
<Select
name="method.name"
onBlur={onSubmit}
@ -232,7 +237,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
const parametersField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Parameters</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Parameters
</FormLabel>
<RecordWidget
component={component}
path={parametersPath}
@ -247,7 +254,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
const waitTypeField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Wait Type</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Wait Type
</FormLabel>
<Select
name="wait.type"
onBlur={onSubmit}
@ -263,7 +272,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
const waitTimeField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Wait Time</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Wait Time
</FormLabel>
<Input
name="wait.time"
onBlur={onSubmit}
@ -275,7 +286,9 @@ export const EventWidget: React.FC<WidgetProps<EventWidgetOptionsType>> = observ
const disabledField = (
<FormControl>
<FormLabel fontSize='14px' fontWeight='normal'>Disabled</FormLabel>
<FormLabel fontSize="14px" fontWeight="normal">
Disabled
</FormLabel>
<SpecWidget
{...props}
spec={disabledSpec}