refactor(web): remove typescript
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import * as React from 'react';
|
||||
import MuiTextField from '@mui/material/TextField';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
import type { IField, IFieldDropdownOption } from 'types';
|
||||
|
||||
import useDynamicFields from 'hooks/useDynamicFields';
|
||||
import useDynamicData from 'hooks/useDynamicData';
|
||||
import PowerInput from 'components/PowerInput';
|
||||
@@ -10,29 +8,9 @@ import TextField from 'components/TextField';
|
||||
import ControlledAutocomplete from 'components/ControlledAutocomplete';
|
||||
import ControlledCustomAutocomplete from 'components/ControlledCustomAutocomplete';
|
||||
import DynamicField from 'components/DynamicField';
|
||||
|
||||
type InputCreatorProps = {
|
||||
onChange?: React.ChangeEventHandler;
|
||||
onBlur?: React.FocusEventHandler;
|
||||
schema: IField;
|
||||
namePrefix?: string;
|
||||
stepId?: string;
|
||||
disabled?: boolean;
|
||||
showOptionValue?: boolean;
|
||||
shouldUnregister?: boolean;
|
||||
};
|
||||
|
||||
type RawOption = {
|
||||
name: string;
|
||||
value: string;
|
||||
};
|
||||
|
||||
const optionGenerator = (options: RawOption[]): IFieldDropdownOption[] =>
|
||||
options?.map(({ name, value }) => ({ label: name as string, value: value }));
|
||||
|
||||
export default function InputCreator(
|
||||
props: InputCreatorProps
|
||||
): React.ReactElement {
|
||||
const optionGenerator = (options) =>
|
||||
options?.map(({ name, value }) => ({ label: name, value: value }));
|
||||
export default function InputCreator(props) {
|
||||
const {
|
||||
onChange,
|
||||
onBlur,
|
||||
@@ -43,7 +21,6 @@ export default function InputCreator(
|
||||
showOptionValue,
|
||||
shouldUnregister,
|
||||
} = props;
|
||||
|
||||
const {
|
||||
key: name,
|
||||
label,
|
||||
@@ -53,13 +30,10 @@ export default function InputCreator(
|
||||
description,
|
||||
type,
|
||||
} = schema;
|
||||
|
||||
const { data, loading } = useDynamicData(stepId, schema);
|
||||
|
||||
const { data: additionalFields, loading: additionalFieldsLoading } =
|
||||
useDynamicFields(stepId, schema);
|
||||
const computedName = namePrefix ? `${namePrefix}.${name}` : name;
|
||||
|
||||
if (type === 'dynamic') {
|
||||
return (
|
||||
<DynamicField
|
||||
@@ -76,10 +50,8 @@ export default function InputCreator(
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (type === 'dropdown') {
|
||||
const preparedOptions = schema.options || optionGenerator(data);
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
{!schema.variables && (
|
||||
@@ -92,7 +64,7 @@ export default function InputCreator(
|
||||
disableClearable={required}
|
||||
options={preparedOptions}
|
||||
renderInput={(params) => <MuiTextField {...params} label={label} />}
|
||||
defaultValue={value as string}
|
||||
defaultValue={value}
|
||||
description={description}
|
||||
loading={loading}
|
||||
disabled={disabled}
|
||||
@@ -112,7 +84,7 @@ export default function InputCreator(
|
||||
disableClearable={required}
|
||||
options={preparedOptions}
|
||||
renderInput={(params) => <MuiTextField {...params} label={label} />}
|
||||
defaultValue={value as string}
|
||||
defaultValue={value}
|
||||
description={description}
|
||||
loading={loading}
|
||||
disabled={disabled}
|
||||
@@ -141,7 +113,6 @@ export default function InputCreator(
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
if (type === 'string') {
|
||||
if (schema.variables) {
|
||||
return (
|
||||
@@ -178,7 +149,6 @@ export default function InputCreator(
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<TextField
|
||||
@@ -218,6 +188,5 @@ export default function InputCreator(
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
return <React.Fragment />;
|
||||
}
|
Reference in New Issue
Block a user