Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
saarikabhasi committed Dec 9, 2024
1 parent 1dbfa4e commit 400334b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface Props {
isMultiField?: boolean | null;
showDocLink?: boolean;
isSemanticTextEnabled?: boolean;
fieldTypeInputRef: React.MutableRefObject<HTMLInputElement | null>;
fieldTypeInputRef?: React.MutableRefObject<HTMLInputElement | null>;
}

export const TypeParameter = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@ const FormWrapper: React.FC<{ children?: React.ReactNode }> = ({ children }) =>

export const EditField = React.memo(
({ form, field, allFields, exitEdit, updateField, kibanaVersion }: Props) => {
const fieldTypeInputRef = useRef<HTMLInputElement>(null);

const submitForm = async () => {
const { isValid, data } = await form.submit();

if (isValid) {
updateField({ ...field, source: data });
}
if (fieldTypeInputRef.current) {
fieldTypeInputRef.current.focus();
}
};

const { isMultiField } = field;
Expand Down Expand Up @@ -154,7 +149,6 @@ export const EditField = React.memo(
defaultValue={field.source}
isRootLevelField={field.parentId === undefined}
isMultiField={isMultiField}
fieldTypeInputRef={fieldTypeInputRef}
/>

<FormDataProvider pathsToWatch={['type', 'subType']}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface Props {
defaultValue: Field;
isRootLevelField: boolean;
isMultiField: boolean;
fieldTypeInputRef: React.MutableRefObject<HTMLInputElement | null>;
}

const getTypeDefinition = (type: MainType, subType: SubType): DataTypeDefinition | undefined => {
Expand All @@ -42,7 +41,7 @@ const getTypeDefinition = (type: MainType, subType: SubType): DataTypeDefinition
};

export const EditFieldHeaderForm = React.memo(
({ defaultValue, isRootLevelField, isMultiField, fieldTypeInputRef }: Props) => {
({ defaultValue, isRootLevelField, isMultiField }: Props) => {
return (
<>
<EuiFlexGroup gutterSize="s">
Expand All @@ -53,11 +52,7 @@ export const EditFieldHeaderForm = React.memo(

{/* Field type */}
<EuiFlexItem>
<TypeParameter
isRootLevelField={isRootLevelField}
isMultiField={isMultiField}
fieldTypeInputRef={fieldTypeInputRef}
/>
<TypeParameter isRootLevelField={isRootLevelField} isMultiField={isMultiField} />
</EuiFlexItem>

{/* Field subType (if any) */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ export const DocumentFieldsTreeEditor = ({

const addField = useCallback(() => {
dispatch({ type: 'documentField.createField' });
if (createFieldFormRef.current) {
createFieldFormRef.current.focus();
}
}, [dispatch, createFieldFormRef.current]);
}, [dispatch]);

const renderCreateField = () => {
// The "fieldToAddFieldTo" is undefined when adding to the top level "properties" object.
Expand Down

0 comments on commit 400334b

Please sign in to comment.